Skip to content

Conversation

muzzlol
Copy link
Contributor

@muzzlol muzzlol commented Jul 23, 2025

Description

Summary: This PR fixes an AttributeError that occurred in both chat() and chat_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 .id and .model_dump() on the outer dictionary instead of on the TextualMemoryItem objects contained within the "memories" key.

Solution

A nested loop has been added to correctly iterate through the TextualMemoryItem objects. This ensures we are operating on the actual Pydantic models and can access their attributes without error.

Checklist:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

- 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.
@tangg555 tangg555 requested a review from fridayL July 24, 2025 03:21
Copy link
Collaborator

@fridayL fridayL left a comment

Choose a reason for hiding this comment

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

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.

@CaralHsi
Copy link
Collaborator

CaralHsi commented Aug 3, 2025

Please resolve the conflicts. Thanks for your contribution:)

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.

3 participants