From 1dcf842635a3a4dfedf04c6ecf4ad3cadd08b54b Mon Sep 17 00:00:00 2001 From: Mgeeeek Date: Wed, 6 May 2026 19:13:10 +0530 Subject: [PATCH] fix(plugin): correct v2 filter syntax in mem0-mcp rubric MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rubric introduced in this PR taught the agent to use `{"metadata.type": "decision"}` filters, but the v2 search contract (docs/platform/features/v2-memory-filters.mdx) requires: 1. The root must be a logical operator (`AND`/`OR`/`NOT`) with an array. A bare `{"user_id": "..."}` is rejected. 2. Metadata uses a nested object — `{"metadata": {"type": "..."}}` — not a dotted key. Only top-level metadata keys are filterable. Without this fix, agents following the rubric produce filter calls the platform either ignores or rejects. Also replaces the literal `"alice"` in the worked example with a clearly-marked `` placeholder so agents don't copy verbatim, and adds a one-line "substitute the active user_id" instruction. Co-Authored-By: Claude Opus 4.7 (1M context) --- mem0-plugin/scripts/on_user_prompt.sh | 14 ++++++----- mem0-plugin/skills/mem0-mcp/SKILL.md | 34 +++++++++++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/mem0-plugin/scripts/on_user_prompt.sh b/mem0-plugin/scripts/on_user_prompt.sh index e8cff7357..70f8eaa44 100755 --- a/mem0-plugin/scripts/on_user_prompt.sh +++ b/mem0-plugin/scripts/on_user_prompt.sh @@ -51,12 +51,14 @@ improve your answer. The agent -- not this hook -- owns this decision. - Run **2-4 parallel** \`search_memories\` calls with different angles, not one query that echoes the user's prompt. - Phrase queries as **nouns** ("auth module decisions"), not full sentences. -- Use \`metadata.type\` filters where they fit: - - \`{"metadata.type": "decision"}\` -- design / architecture questions - - \`{"metadata.type": "anti_pattern"}\` -- debugging, error handling - - \`{"metadata.type": "user_preference"}\` -- tooling, stack, style - - \`{"metadata.type": "convention"}\` -- established patterns in this project -- Scope every query with \`{"user_id": "$USER_ID"}\`. +- Filter shape: the root must be a logical operator (\`AND\` / \`OR\` / \`NOT\`) + with an array, and metadata uses a **nested** object (not dotted keys). + Combine \`user_id\` with one \`metadata.type\` clause per call: + - \`{"AND": [{"user_id": "$USER_ID"}, {"metadata": {"type": "decision"}}]}\` -- design / architecture + - \`{"AND": [{"user_id": "$USER_ID"}, {"metadata": {"type": "anti_pattern"}}]}\` -- debugging, error handling + - \`{"AND": [{"user_id": "$USER_ID"}, {"metadata": {"type": "user_preference"}}]}\` -- tooling, stack, style + - \`{"AND": [{"user_id": "$USER_ID"}, {"metadata": {"type": "convention"}}]}\` -- established patterns +- Or scope with just \`{"AND": [{"user_id": "$USER_ID"}]}\` when no metadata filter fits. - Empty results are normal -- proceed without context. EOF diff --git a/mem0-plugin/skills/mem0-mcp/SKILL.md b/mem0-plugin/skills/mem0-mcp/SKILL.md index f89bef133..11331f19a 100644 --- a/mem0-plugin/skills/mem0-mcp/SKILL.md +++ b/mem0-plugin/skills/mem0-mcp/SKILL.md @@ -43,18 +43,25 @@ When you do search, run **2–4 parallel** `search_memories` calls at different - Use entity names, not pronouns. Resolve "that thing" from recent context first. - Don't search on meta-questions ("what was that?") — use recent context or `get_memories` ordered by `created_at`. -**Metadata filters** match the same `metadata.type` values written under "After completing significant work" below: +**Metadata filters** match the same `type` values written under "After completing significant work" below. -| Filter | Use for | +Two rules from the v2 filter spec: + +1. The root **must** be a logical operator (`AND` / `OR` / `NOT`) with an array. A bare `{"user_id": "..."}` won't work. +2. Metadata uses a **nested** object, not a dotted key. `{"metadata": {"type": "decision"}}`, never `{"metadata.type": "decision"}`. Only top-level metadata keys are filterable. + +Combine `user_id` with one metadata clause per call: + +| `metadata.type` clause | Use for | |--------|---------| -| `{"metadata.type": "decision"}` | design / architecture / "how should we" questions | -| `{"metadata.type": "anti_pattern"}` | debugging, error handling, things that failed before | -| `{"metadata.type": "user_preference"}` | tooling, stack, style — always include for code work | -| `{"metadata.type": "convention"}` | established patterns in this project | +| `{"metadata": {"type": "decision"}}` | design / architecture / "how should we" questions | +| `{"metadata": {"type": "anti_pattern"}}` | debugging, error handling, things that failed before | +| `{"metadata": {"type": "user_preference"}}` | tooling, stack, style — always include for code work | +| `{"metadata": {"type": "convention"}}` | established patterns in this project | -Combine with `user_id` using AND: +Full filter (replace `` with the active user_id from your runtime): ```python -filters={"AND": [{"user_id": "alice"}, {"metadata.type": "decision"}]} +filters={"AND": [{"user_id": ""}, {"metadata": {"type": "decision"}}]} ``` ### Worked example @@ -67,15 +74,16 @@ search_memories(query="Refactor the auth module to use JWT") # Hits whatever shares words. Misses prior decisions and preferences. ``` -Do (parallel): +Do (parallel — substitute the active `user_id` for ``): ```python search_memories(query="auth module decisions", - filters={"AND": [{"user_id": "alice"}, {"metadata.type": "decision"}]}) -search_memories(query="JWT", filters={"user_id": "alice"}) + filters={"AND": [{"user_id": ""}, {"metadata": {"type": "decision"}}]}) +search_memories(query="JWT", + filters={"AND": [{"user_id": ""}]}) search_memories(query="auth refactor failures", - filters={"AND": [{"user_id": "alice"}, {"metadata.type": "anti_pattern"}]}) + filters={"AND": [{"user_id": ""}, {"metadata": {"type": "anti_pattern"}}]}) search_memories(query="auth", - filters={"AND": [{"user_id": "alice"}, {"metadata.type": "user_preference"}]}) + filters={"AND": [{"user_id": ""}, {"metadata": {"type": "user_preference"}}]}) ``` ## After completing significant work