Memory search ranks unrelated entities above exact-identifier matches; narrow lookups return oversized aggregate overviews
Summary
Semantic memory search (openviking_search / openviking_find via the opencode plugin) repeatedly returns unrelated entities at high confidence (82–88%) ahead of exact-identifier matches, and narrow lookups can return oversized aggregate overview documents that blow the caller's context budget.
Observed across many real agent sessions on self-hosted desktops (consolidated from open-bot reports shpaw415/open-bot#20, #21, #32, #71, #83 — same defect family, filed independently by different agent sessions over several days).
Repro patterns
- Exact identifiers lose to unrelated entities. A query containing precise current-task identifiers (round/contract/counter names, e.g.
R42 R43 Capstone distribution module version preflight STATIC PE, orfilons_pme_quebec filons-pme-quebec-quotidien reports coverage discord-bridge prompt-shield) returns an unrelated entity ("Tripo API V2") first at 82–88%, with the exact-matching task reports/skills absent or far below. Expected: exact technical-token overlap (or a lexical fallback boost) should keep unrelated entities from presenting as high-confidence guidance. - Oversized aggregate overviews. A narrow lookup with
limit=5, read_content=falsereturns aggregate events-overview documents containing many unrelated historical entries — 50 KB to 122 KB responses that truncate. Expected: token-bounded abstracts and per-hit excerpt limits;read_content=falseshould not inject full aggregate overviews, and leaf memories should be preferred over aggregate ones for narrow queries.
Impact
Agents either follow unrelated "high-confidence" guidance or burn their context budget on one search call. The client-side workaround (find with small limits, exact-identifier filtering, direct URI reads) helps but cannot fix ranking or server-side response sizing.
Happy to provide anonymized query/result pairs if useful — please tell us what shape helps (no user content or credentials are involved in the reports above).
Before touching the ranker, one structural cause is worth testing: in our deployment embedding.text_source is content_only, so the document prefix is literally title: none | text: ... and the card name never enters the embedding. A query carrying exact identifiers then has nothing to match except body prose, while a semantically adjacent but unrelated card can win on similarity alone. That is the 82-88% false-positive pattern you describe.
Cheap experiment that separates indexing from ranking: take 20 of your failing queries, re-embed one namespace with the title prepended to the embedded text, and compare recall@1 on the same 20 queries. If it moves, the defect is in the embedding input and weight tuning will not fix it.
The oversized-overview half is a different bug. A directory .overview.md is a legitimate semantic hit for a broad query, which is why narrow lookups keep returning it. We filter results whose URI ends in .overview.md when the query contains an exact-identifier token, which removed the context blowups in our runs without hurting broad queries.
Worth splitting the issue in two: the ranking defect has a measurable fixture, the overview one has a filter.
We run several self-hosted instances with multiple agent sessions reading/writing daily, and we independently hit the same defect family (exact identifiers losing to unrelated entities at high confidence). Two additions to @godxxs's analysis, based on mitigations we have verified in our own deployments:
1. The embedding-input fix and the .overview.md filter are necessary but not sufficient — a third layer at assembly/serving time catches what the other two miss.
Even with a better embedding input, we still saw cases where the consuming agent followed a high-confidence unrelated result as guidance (and separately, stale records presented as current). What reliably reduced both was injecting each hit's card-header metadata (title, record type, validity, time range) into the assembled context block, so the agent can verify the hit against its own query tokens before trusting it. With that metadata visible at assembly time, agents self-correct or discard mismatches instead of following them. This layer is independent of embedding.text_source, so it also helps deployments that stay on content_only.
Two observations that shaped this:
- Query-side interventions (rewriting/expanding the query) were ruled out in our tests — the ceiling is per-card, so re-ranking or rewriting over the same candidate set cannot fix identity mismatches.
- The same metadata injection also fixed time-related misuse in our runs, which suggests one mechanism covers both the "unrelated entity wins" and "stale record hijacks" failure families.
2. On the split-in-two suggestion — agreed, and the ranking half likely needs a lexical fallback, not just weight tuning.
Exact-identifier queries are a known weak spot of pure dense retrieval; a lexical/exact-token fallback boost (BM25-style hybrid) is the standard remedy in the retrieval literature. Concretely, the three layers compose as: (a) fix the embedding input (title in), (b) filter aggregate overviews for narrow identifier queries, (c) expose per-hit metadata to callers so trust decisions happen at consumption time with visible evidence.
Happy to share anonymized query/result pairs from our side as well, in whatever shape helps build the fixture for the ranking half.