fix(api): map entity params to filters in GET /memories (#4955) - #4960
Conversation
|
hey @PratikRai0101 thank you for your contribution can you please add some test here to validate. |
xkonjin
left a comment
There was a problem hiding this comment.
Good catch on mapping entity params to filters. This accurately matches the get_all signature expected by the library.
Since PR #4959 contains the exact same fix, you might want to coordinate with the author or close one of them as a duplicate to avoid merge conflicts.
The fix itself looks correct.
|
hey @kartik-mem0 so I just pushed a commit adding the TestGetMemories class to test_server_params.py. It explicitly tests the GET /memories?user_id=... route to ensure it returns a 200 OK and correctly maps the query parameters to the filters dict instead of passing them as top-level kwargs. |
|
For the timestamp not being saved with memories: The issue is likely that the timestamp field exists in the model but is not passed to the storage layer. Check your memory creation code: # Wrong - timestamp ignored
memory = Memory(
content=content,
# timestamp=datetime.now() # Missing!
)
# Correct - timestamp passed through
memory = Memory(
content=content,
timestamp=datetime.now(),
)
# And in the storage layer, ensure timestamp is persisted:
def save(memory):
db.session.add(memory)
db.session.commit()Also check if your database schema has a timestamp column that's not being mapped. |
|
For the timestamp not being preserved: The issue is in the metadata pipeline. Here's the fix: def add_memory(messages, metadata):
# Ensure timestamp is in metadata
if 'timestamp' not in metadata:
metadata['timestamp'] = datetime.now(timezone.utc).isoformat()
# Pass timestamp through to vector store
memory_data = {
'content': message_content,
'metadata': metadata, # timestamp is preserved here
}
vector_store.add(memory_data)And in the vector store: def add(self, data):
# Extract timestamp from metadata and store it in the vector
timestamp = data['metadata'].get('timestamp')
point = PointStruct(
id=uuid4(),
vector=embedding,
payload={
'content': data['content'],
'timestamp': timestamp, # Stored as searchable field
}
) |
Linked Issue
Closes #4955
Description
This PR resolves a version mismatch between the OSS REST API server and the Core Memory backend (v3).
Following the v3 update, the
Memory.get_all()method now requires entity-level parameters (user_id,agent_id,run_id) to be encapsulated within afiltersdictionary. The API route was previously passing these as top-level keyword arguments, resulting in aRuntimeError.Key Changes:
get_all_memoriesroute inserver/main.pyto intercept query parameters.filtersobject.filters=filterskeyword argument.Type of Change
Breaking Changes
N/A - This restores expected functionality for the
/memoriesGET endpoint.Test Coverage
Manual Validation:
uvicorn.filtersdictionary before being dispatched to the core memory instance.Checklist