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

fix: patch bug on TEI embedding lookup #724

Merged
merged 2 commits into from
Dec 28, 2023
Merged

Conversation

cpacker
Copy link
Collaborator

@cpacker cpacker commented Dec 27, 2023

Please describe the purpose of this pull request.

Same bug we patched before with having to unpack TEI embedding payload. However, I noticed that in LocalIndex the embeddings on a query get created again, so our previous patch doesn't apply, and thus we get a similar error. This patch uses QueryBundle to make sure we don't create another embedding on query, so that we don't have another unpacking problem.

How to test

Use memgpt quickstart

On main, ask "insert "banana" into archival memory", then "search archival memory for "banana"" and you'll get this error:

💭 Processing user request to search archival memory for a specific term.
⚡🧠 [function] updating memory with archival_memory_search
'page'
{'query': 'banana'}
Archival search error unsupported operand type(s) for /: 'dict' and 'int'
Error calling function archival_memory_search: unsupported operand type(s) for /: 'dict' and 'int'
Traceback (most recent call last):
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/memgpt/agent.py", line 521, in handle_ai_response
    function_response = function_to_call(**function_args)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/memgpt/functions/function_sets/base.py", line 178, in archival_memory_search
    results, total = self.persistence_manager.archival_memory.search(query, count=count, start=page * count)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/memgpt/memory.py", line 393, in search
    raise e
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/memgpt/memory.py", line 382, in search
    self.cache[query_string] = self.storage.query(query_string, query_vec, top_k=self.top_k)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/memgpt/connectors/local.py", line 120, in query
    nodes = retriever.retrieve(query)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/llama_index/core/base_retriever.py", line 54, in retrieve
    nodes = self._retrieve(query_bundle)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/llama_index/indices/vector_store/retrievers/retriever.py", line 84, in _retrieve
    self._service_context.embed_model.get_agg_embedding_from_queries(
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/llama_index/embeddings/base.py", line 144, in get_agg_embedding_from_queries
    return agg_fn(query_embeddings)
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/llama_index/embeddings/base.py", line 33, in mean_agg
    return list(np.array(embeddings).mean(axis=0))
  File "/home/cpacker/memgpt-test-2/venv/lib/python3.9/site-packages/numpy/core/_methods.py", line 131, in _mean
    ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'dict' and 'int'

⚡🔴 [function] Error: Error calling function archival_memory_search: unsupported operand type(s) for /: 'dict' and 'int'

With this PR, you won't get the error:
image

Have you tested this PR?

Yes, using memgpt quickstart.

Copy link
Collaborator

@sarahwooders sarahwooders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@cpacker cpacker merged commit 4fae3e9 into main Dec 28, 2023
3 checks passed
@cpacker cpacker deleted the patch-archival-memory-bug branch December 28, 2023 06:10
norton120 pushed a commit to norton120/MemGPT that referenced this pull request Feb 15, 2024
mattzh72 pushed a commit that referenced this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants