Skip to content

fix(mcp): embed memory_query search text as a query - #861

Merged
akitaonrails merged 2 commits into
akitaonrails:mainfrom
kevin9327:fix/memory-query-embed-query-task
Sep 24, 2026
Merged

akitaonrails merged 2 commits into
akitaonrails:mainfrom
kevin9327:fix/memory-query-embed-query-task

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What changed

memory_query embedded search text with the generic Embedder::embed() method. Google's embedder implements that as embed_document (RETRIEVAL_DOCUMENT), the same task type used when indexing wiki pages, so hybrid search compared a document vector to document vectors.

The query-side helper now calls embed_query (RETRIEVAL_QUERY). Indexed writes still use embed_document. Symmetric embedders (OpenAI, Voyage, local) already return the same vector from embed() and embed_query(), so their results are unchanged.

Why

Hybrid retrieval is only useful when the query vector is in the same task space as the indexed pages expect for queries. With Google embeddings configured, the vector stream could not separate query from passage because both sides used RETRIEVAL_DOCUMENT.

Test plan

  • cargo fmt --all -- --check passes
  • git diff --check passes
  • cargo clippy -p ai-memory-mcp --all-targets -- -D warnings passes
  • cargo test -p ai-memory-mcp --lib memory_query — 23 passed, including memory_query_embeds_search_text_as_a_query_not_a_document
  • Before the fix the new test failed: embed_query was never called (query_calls == 0). After the fix it is called once and embed() / embed_document stay unused.

Commit attribution

Release impact

  • Patch — bug fix, no new surface
  • Minor — additive: new flag/subcommand/MCP tool/config key,
    new agent harness or provider
  • Major (breaking) — on-disk format, removed/renamed surface,
    breaking MCP schema change, called out in "What changed" above

CHANGELOG (merge gate)

  • I added a CHANGELOG.md [Unreleased] entry.
  • Any changed default (flag behaviour, config default, env var,
    response shape) is called out explicitly in "What changed" above.
    No default changed; only Google (and other query/document-asymmetric
    embedders) get the correct query task type.

Notes for reviewers

The one-line production change is in AiMemoryServer::embed_query. Wiki page writes already call embed_document; this only corrects the search-text helper that feeds hybrid memory_query.

AI-assisted (Grok)

Google's embedder implements embed() as embed_document
(RETRIEVAL_DOCUMENT), the same task type used when indexing wiki
pages. memory_query called that generic method for search text, so
hybrid retrieval compared a document vector to document vectors.

Call embed_query instead so the vector stream uses RETRIEVAL_QUERY.
Symmetric embedders are unchanged.
@akitaonrails
akitaonrails merged commit 21fc328 into akitaonrails:main Sep 24, 2026
20 checks passed
akitaonrails added a commit that referenced this pull request Sep 24, 2026
Forward-merge the 2.4.x fixes (#875, #824, #861, #873, #866, #871, #872) so main stays a subset of release/2.5.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDbhmszrjG9s5MrPrTuNtm

# Conflicts:
#	CHANGELOG.md
#	crates/ai-memory-cli/src/commands/serve.rs
#	crates/ai-memory-mcp/src/server.rs
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.

2 participants