Add provenance & review-status metadata convention with read filtering#63
Merged
Conversation
Formalize a lightweight metadata convention for governed agent memory and let REST reads filter on it. Stores as ordinary metadata in the existing Qdrant payload — no tables, no schema change (verified: mem0 get_all/search pass arbitrary metadata keys through to the payload filter). Reserved keys: source, confidence, review_status, reviewed_by/reviewed_at, expires_at. confidence and review_status are kept independent (orthogonal states), and expires_at addresses the "stale memory stays trusted" failure mode raised in the issue discussion. Adopts that feedback; keeps `source` a flat string (consistent with the importers/capture bot and the existing top-level agent_id writer tag) rather than a nested object. - app/rest.py: _provenance_filters(); GET /api/v1/memories gains source/ confidence/review_status/exclude_expired query params; search gains the same fields (semantic + keyword). MCP reads stay unfiltered (architecture invariant). - app/memory.py: drop_expired() post-filter (handles top-level and nested metadata expires_at); keyword_search() gains extra_filters passthrough. - tests: drop_expired, keyword extra_filters, and REST list/search provenance filtering + exclude_expired. - docs: USER_GUIDE convention table + filter examples; DEVELOPER_GUIDE notes. Closes #52. https://claude.ai/code/session_017835DVrvURaYnbQiPQwzue
There was a problem hiding this comment.
Pull request overview
Adds a provenance + review-status metadata convention for governed memories and exposes it via REST read/search filtering (including optional expiry exclusion), without changing storage schema (still ordinary Qdrant payload metadata).
Changes:
- Add REST query/body filters for
source,confidence,review_statusplusexclude_expiredon list/search. - Extend keyword search to accept additional exact-match payload filters, and add a shared
drop_expired()post-filter for REST reads. - Add tests and update user/developer documentation to describe the convention and new filter parameters.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/rest.py | Adds provenance filter construction for list/search and optional expiry exclusion via drop_expired(). |
| app/memory.py | Adds extra_filters support to keyword search and implements drop_expired() with expires_at parsing. |
| tests/test_rest.py | Verifies REST list/search provenance filters and exclude_expired behavior. |
| tests/test_memory.py | Adds unit tests for keyword extra_filters passthrough and drop_expired() behavior. |
| docs/USER_GUIDE.md | Documents the metadata convention and the new REST read/search filter parameters. |
| docs/DEVELOPER_GUIDE.md | Notes the new helpers (_provenance_filters, drop_expired) in the codebase overview. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Adds a lightweight provenance & review-status metadata convention for governed agent memory, and lets the REST read endpoints filter on it (backlog issue #52 — the last active OB1-review item). It stores as ordinary metadata in the existing Qdrant payload: no tables, no schema change, no migration.
Verified against mem0 2.0.2 source: both
get_allandsearchpass arbitrary metadata keys straight through to the (already-validated)vector_store.listpayload-filter path, and return custom fields under each result'smetadata. So filtering is real, not aspirational.The convention
sourceuser,agent,import:chatgpt,capture:telegram,tool:n8n…confidencehigh,medium,low,unknownreview_statusunreviewed,approved,rejected,stalereviewed_by/reviewed_atexpires_atOn the issue comment (re-checked, as asked)
An external commenter (
norika1207-lab) suggested keepingconfidenceandreview_statusorthogonal and adding expiry/staleness. It's sound and I adopted it:confidenceandreview_statusare documented as independent states.expires_at+ anexclude_expiredread filter directly address their key point — "old memory stayed trusted after the world changed."I declined the nested
source.kind/source.ref/source.agent_idshape: memserv already has a top-levelagent_idwriter tag, and the importers/capture bot already write a flatmetadata.sourcestring — nesting would duplicate/conflict. Sosourcestays a flat string. (Rationale captured in the docs.)Changes
app/rest.py:_provenance_filters();GET /api/v1/memoriesgainssource/confidence/review_status(exact-match) +exclude_expiredquery params;POST /memories/searchgains the same fields (works in both semantic and keyword modes). MCP reads stay unfiltered per the shared-store invariant.app/memory.py:drop_expired()post-filter (handlesexpires_atboth top-level and nested undermetadata);keyword_search()gains anextra_filterspassthrough.metadatafield (REST) /metadataarg (MCP) — no write-path change needed.Tests
tests/test_memory.py:drop_expired(past removed / future + missing kept / top-level + nested / non-results passthrough), keywordextra_filterspassthrough.tests/test_rest.py: list filters bysource/confidence/review_status, listexclude_expired, search provenance filter, searchexclude_expired.ruffclean.Docs
rest.py/memory.pynotes.Optional post-deploy check
GET /api/v1/memories?review_status=approved&exclude_expired=trueshould return only approved, non-expired memories.Closes #52.
https://claude.ai/code/session_017835DVrvURaYnbQiPQwzue
Generated by Claude Code