Skip to content

feat(api): filter listed memories by scope#1015

Merged
lightzt99 merged 7 commits into
oceanbase:mainfrom
wayyoungboy:fix/issue-1014-list-memory-scope-filter
Jun 11, 2026
Merged

feat(api): filter listed memories by scope#1015
lightzt99 merged 7 commits into
oceanbase:mainfrom
wayyoungboy:fix/issue-1014-list-memory-scope-filter

Conversation

@wayyoungboy

Copy link
Copy Markdown
Member

Summary

Closes #1014.

  • Add scope query parameter to GET /api/v1/memories for metadata scope filtering.
  • Pass metadata filters through API, service, core memory, and storage count/list paths.
  • Keep pagination stable by applying metadata filters before limit/offset.
  • Document the new REST query parameter and add regression tests for personal/group-style scope pagination.

Validation

  • pytest tests/unit/test_list_memory_filters.py tests/unit/test_memory.py -q
  • PYTHONPATH=src pytest tests/unit -q
  • python3 -m flake8 src/server/api/v1/memories.py src/server/services/memory_service.py src/powermem/core/memory.py src/powermem/storage/adapter.py tests/unit/test_list_memory_filters.py --select=F601,F821,E999
  • git diff --check

@lightzt99

lightzt99 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

A small suggestion:

it might be worth pushing the scope filter down to the DB layer rather than relying on in-memory filtering. The SQLite backend already supports json_extract-based filtering on nested payload paths via _json_path_for_key (sqlite_vector_store.py:20) — it just needs the adapter to translate the logical key to the backend-specific path:

  • SQLite: scopemetadata.scopejson_extract(payload, '$.metadata.scope') = 'personal'
  • OceanBase: scope → filter on the metadata JSON column directly

Both list() and count() on the vector stores already accept arbitrary filter keys with dotted nesting. If the adapter does this translation, the has_extra_filters / fetch-all / in-memory paginate branch could be dropped, keeping pagination and counting at the DB level and avoiding the large-fetch risk on bigger datasets.

@wayyoungboy

Copy link
Copy Markdown
Member Author

Thanks for the suggestion. I pushed an update that translates logical metadata filters before calling the vector store, so list/count no longer fetch all rows for scope filtering. SQLite and PGVector now use nested payload paths such as metadata.scope, while OceanBase keeps scope so its metadata JSON column filter is used directly.\n\nValidation done:\n- targeted scope/list tests passed\n- full unit suite passed: 421 passed\n- started the API server locally and verified the real GET /api/v1/memories flow: created 4 memories with personal/group scopes, confirmed scope=personal returned total 3 with correct paginated results, confirmed scope=group returned total 1, then cleaned up the 4 test memories

@lightzt99

Copy link
Copy Markdown
Collaborator

LGTM

@lightzt99 lightzt99 merged commit a9fd696 into oceanbase:main Jun 11, 2026
17 checks passed
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.

feat(api): support metadata filters on list memories

2 participants