Skip to content

docs(client): fix search result example usage#1345

Open
haosenwang1018 wants to merge 5 commits intoMemMachine:mainfrom
haosenwang1018:docs/python-search-result-object
Open

docs(client): fix search result example usage#1345
haosenwang1018 wants to merge 5 commits intoMemMachine:mainfrom
haosenwang1018:docs/python-search-result-object

Conversation

@haosenwang1018
Copy link
Copy Markdown

@haosenwang1018 haosenwang1018 commented Apr 17, 2026

Purpose of the change

Fix the Python client docs/demo so they use the actual SearchResult object API instead of treating search results like a dict.

Description

Fixes #973

The current Python SDK example and demo access search results like:

  • results.get('episodic_memory', [])
  • item['content']

But the Python client returns typed objects (SearchResult, EpisodicMemory), which causes runtime failures like:

  • AttributeError: 'SearchResult' object has no attribute 'get'

This change updates:

  • docs/api_reference/python/client.mdx
  • examples/memmachine_client_demo.py

to use object-style access instead:

  • results.episodic_memory or []
  • item.content
  • item.producer_role
  • memory.timestamp
  • memory.user_metadata

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Manual verification:

  1. Verified the docs example now iterates with results.episodic_memory or []
  2. Verified the docs example uses object attributes like item.content
  3. Verified the official demo no longer uses results.get(...) or dict indexing for search results

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

@sscargal sscargal requested a review from Copilot April 17, 2026 17:21
@sscargal
Copy link
Copy Markdown
Contributor

@haosenwang1018 thank you for the pull request submission. Please sign your commits, resolve the unit test failures, and review the CoPilot feedback. You only need to resolve the relevant items. Thanks.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes Python SDK docs/demo to use typed result objects for memory search output, and extends the client/tooling to accept raw filter strings (plus episode type support in LangGraph).

Changes:

  • Update docs and demo to use attribute-style access for search results (e.g., item.content).
  • Add filter: str | None passthrough to Memory.search() / Memory.list() and LangGraph search_memory().
  • Add optional episode_type handling + normalization in LangGraph tools, with expanded tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/client/src/memmachine_client/memory.py Adds raw filter string parameter and combines it with built-in / dict filters
packages/client/src/memmachine_client/langgraph.py Adds episode_type support, normalizes enum values, and passes raw filter through
packages/client/client_tests/test_memory.py Adds unit tests for raw filter strings and updates filter_dict expectations
packages/client/client_tests/test_langgraph.py Updates tool tests for new filter/episode_type behavior
packages/client/client_tests/test_integration_complete.py Aligns integration test filter_dict keys with metadata. prefix
examples/memmachine_client_demo.py Switches demo to attribute access for episodic memory items
docs/api_reference/python/client.mdx Updates docs example to attribute access for search results

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 459 to 468
def list(
self,
memory_type: MemoryType = MemoryType.Episodic,
page_size: int = 100,
page_num: int = 0,
filter_dict: dict[str, str] | None = None,
filter: str | None = None,
set_metadata: dict[str, JsonValue] | None = None,
timeout: int | None = None,
) -> ListResult:
Comment on lines 362 to +370
self,
query: str,
limit: int | None = None,
expand_context: int = 0,
score_threshold: float | None = None,
filter_dict: dict[str, str] | None = None,
timeout: int | None = None,
*,
filter: str | None = None,
print("Results found:")
for idx, item in enumerate(results.get('episodic_memory', [])):
print(f"[{idx+1}] {item['content']} (Role: {item['producer_role']})")
for idx, item in enumerate(results.episodic_memory or []):
Comment on lines +39 to +49
episodic_memories = results.episodic_memory or []
if not episodic_memories:
print(" No memories found.")
return

episodic_memories = results["episodic_memory"]
if episodic_memories and len(episodic_memories) > 0:
print(f" Found {len(episodic_memories[0])} relevant memories:")
for i, memory in enumerate(episodic_memories[0][:3], 1): # Show top 3
print(f" Time: {memory['timestamp']}")
print(f" {i}. {memory['content']}")
if memory.get("user_metadata"):
print(f" Metadata: {memory['user_metadata']}")
print()
print(f" Found {len(episodic_memories)} relevant memories:")
for i, memory in enumerate(episodic_memories[:3], 1): # Show top 3
print(f" Time: {memory.timestamp}")
print(f" {i}. {memory.content}")
if memory.user_metadata:
print(f" Metadata: {memory.user_metadata}")
Comment on lines 392 to +394
timeout: Request timeout in seconds (uses client default if not provided)
filter: Optional raw filter string. If provided together with built-in or
`filter_dict` filters, all filters are combined with AND.
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.

[Docs]: Python SDK example does not work

3 participants