Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumpyNormEvaluation numpy error fix #502

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

keenborder786
Copy link
Contributor

When I ran the following code:

## Embedding Function
embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
encoder = LangChain(embeddings=embeddings)


## Data Manager
redis_cache_storage = CacheBase(name="redis", redis_host="localhost", redis_port=6379)
redis_vector_storage = VectorBase(
    name="redis", host="localhost", port=6379, dimension=1536
)
data_manager = get_data_manager(redis_cache_storage, redis_vector_storage)

init_similar_cache(
    embedding=encoder,
    data_manager=data_manager,
    evaluation=NumpyNormEvaluation(),
    data_dir=f"similar_cache",
    config=Config(similarity_threshold=0.2),
)

put("apple", "boy")
print(get("appl"))

I was getting the following error:

Traceback (most recent call last):
  File "/home/mohtashimkhan/GPTCache/test.py", line 36, in <module>
    print(get("appl"))
  File "/home/mohtashimkhan/GPTCache/gptcache/adapter/api.py", line 124, in get
    res = adapt(
  File "/home/mohtashimkhan/GPTCache/gptcache/adapter/adapter.py", line 158, in adapt
    rank = time_cal(
  File "/home/mohtashimkhan/GPTCache/gptcache/utils/time.py", line 9, in inner
    res = func(*args, **kwargs)
  File "/home/mohtashimkhan/GPTCache/gptcache/similarity_evaluation/np.py", line 71, in evaluation
    if 'embedding' not in src_dict or 'embedding' not in cache_dict or not src_dict['embedding'] or not cache_dict['embedding']:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Numpy was raising a ValueError because the not operator with a numpy array was not reducing to a single boolean value. Therefore, I decided to explicitly check if the array is None, which resolved the issue.

… than using 'not' which gives numpy ambiguity error
@sre-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: keenborder786
To complete the pull request process, please assign xiaofan-luan after the PR has been reviewed.
You can assign the PR to them by writing /assign @xiaofan-luan in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot
Copy link
Collaborator

Welcome @keenborder786! It looks like this is your first PR to zilliztech/GPTCache 🎉

@keenborder786
Copy link
Contributor Author

/assign @xiaofan-luan

@SimFG
Copy link
Collaborator

SimFG commented Aug 4, 2023

@keenborder786 thanks for your pr. please make the dev branch as the target branch

@SimFG SimFG assigned SimFG and unassigned xiaofan-luan Aug 4, 2023
@keenborder786
Copy link
Contributor Author

@SimFG ok

@SimFG SimFG changed the base branch from main to dev August 4, 2023 07:36
@SimFG SimFG merged commit 03dda8f into zilliztech:dev Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants