fix(product): Correctly handle nested memory structure in chat methods#148
Closed
muzzlol wants to merge 3 commits intoMemTensor:mainfrom
Closed
fix(product): Correctly handle nested memory structure in chat methods#148muzzlol wants to merge 3 commits intoMemTensor:mainfrom
muzzlol wants to merge 3 commits intoMemTensor:mainfrom
Conversation
- Fixes AttributeError when processing references in chat() and chat_with_references(). - The search result is a list of dictionaries . - The previous code incorrectly treated the outer dictionary as a TextualMemoryItem. - This change adds a nested loop to correctly iterate through the TextualMemoryItem objects inside the 'memories' key, resolving the crash.
fridayL
requested changes
Jul 28, 2025
Collaborator
fridayL
left a comment
There was a problem hiding this comment.
Sorry for the late code review.
first please change pr branch to dev
and for the code I want to clarify that at lines 757-762:
memories_list = []
memories_result = super().search(
query, user_id, install_cube_ids=[cube_id] if cube_id else None, top_k=10
)["text_mem"]
if memories_result:
memories_list = memories_result[0]["memories"]I have already handled this part maybe is not very good style.
If you want to change the structure later, you'll also need to update this code accordingly.
Collaborator
|
Please resolve the conflicts. Thanks for your contribution:) |
|
This PR has been automatically marked as stale due to inactivity. |
|
This PR has been automatically closed due to inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary: This PR fixes an
AttributeErrorthat occurred in bothchat()andchat_with_references()when processing memory references for streaming responses. The root cause was an incorrect assumption about the data structure returned from the search method.Fix: #(no existing issue - bug found during development)
Docs Issue/PR: (not applicable)
Reviewer: @(leave blank)
Root Cause
The
super().search()method returns a list of dictionaries, where each dictionary is structured as{"cube_id": "...", "memories": [TextualMemoryItem, ...]}.The code was incorrectly trying to access attributes like
.idand.model_dump()on the outer dictionary instead of on theTextualMemoryItemobjects contained within the"memories"key.Solution
A nested loop has been added to correctly iterate through the
TextualMemoryItemobjects. This ensures we are operating on the actual Pydantic models and can access their attributes without error.Checklist: