Repository navigation
Description
Problem
In benchmark evaluation (LoCoMo), BM finds the correct document 74.3% of the time (R@5) but the retrieved text only contains the exact answer 15.5% of the time (content hit rate). Mem0 gets 34.3% content hit with lower recall.
The gap is because search results return minimal text context:
matched_chunk: the single best-matching chunk (max 900 chars) — may not contain the answer even when the right note was foundcontent: the entity'scontent_snippet— often just the note header/title area
Root cause
-
Single chunk returned:
_search_vector_only()keeps only the best chunk per search_index row (best_chunk_by_si_id). If the answer is in chunk 3 but chunk 1 matched the query better, the answer text is lost. -
content_snippettruncation: Thecontentfield in search results comes fromcontent_snippeton the search index, which for entities is a truncated version of the note. Long session notes get their content cut off. -
Observation-level hits: For person/topic entities with few observations, the matched chunk is just a single observation line like
- [role] Conversation participant. The actual conversation content lives in session notes.
Proposed improvements
Option A: Return top-N chunks per result (preferred)
Instead of just the best matching chunk, return the top 2-3 chunks from the same entity. This preserves more context without returning the entire note.
# Instead of just best_chunk_by_si_id[si_id] = chunk_text
# Keep top 3 chunks per entity
top_chunks_by_si_id[si_id].append((similarity, chunk_text))
# Then join them: matched_chunk = '\n'.join(top 3 by similarity)Option B: Return full content for small notes
If a note is under some threshold (e.g., 2000 chars), return the full content instead of just the snippet. Most LoCoMo notes are conversation sessions that fit in this range.
Option C: Add matched_chunks (plural) field
Return an array of all chunks that exceeded the similarity threshold, preserving the current matched_chunk for backward compat.
Benchmark evidence
Full LoCoMo run (locomo-full-20260226T055634Z):
| Provider | R@5 | Content Hit |
|---|---|---|
| bm-local | 74.3% | 15.5% |
| mem0-local | 64.6% | 34.3% |
BM finds the right doc 10 points more often but surfaces the answer text 19 points less often.
Impact
This affects real users too — when an LLM gets search results, having more context per hit means better answers even when retrieval is correct. This is the gap between 'found the right note' and 'gave the right answer.'
Activity
claude commentedon Feb 26, 2026
Claude finished @bm-clawd's task in 2m 56s —— View job
Triage Analysis
Issue Classification
No duplicates found. Issue #603 (time-decay scoring) is related but distinct.
Code Analysis
I explored the search implementation and confirmed the root causes described in the issue:
1. Single best-chunk selection (
search_repository_base.py:877-891):The loop over vector results keeps only the highest-similarity chunk per
si_id. If the answer is in chunk 3 but chunk 1 has a better embedding match, the answer text is discarded.2. Severe content truncation (
search_index_row.py+utils.py):CONTENT_DISPLAY_LIMIT = 250chars — thecontentfield shown inSearchResultis truncated at 250 characterscontent_snippetin the database stores the full markdown, but only the first 250 chars are surfaced via thecontentproperty3. MAX_VECTOR_CHUNK_CHARS = 900 — individual chunks max out at 900 chars, so even the
matched_chunkfield is capped at 900 charsFeasibility Assessment
Option A — Top-N chunks per result (recommended)
_search_vector_only(): accumulate top-3 chunks instead of replacing with best\n---\nseparator into existingmatched_chunkfieldsearch_repository_base.py+ test updatesOption B — Full content for small notes
content_snippet(or full entity text) alongside each resultsearch_index.content_snippet— just needs to be surfaced whenlen(content_snippet) < thresholdOption C —
matched_chunksarray fieldmatched_chunkRecommended Approach
Combining Option A + Option B gives the largest benefit with minimal risk:
content_snippetis under a threshold (e.g., 2000 chars), return it ascontentinstead of the 250-char truncationmatched_chunkandcontentfieldsThe fix is localized to:
src/basic_memory/repository/search_repository_base.py(~30 lines)src/basic_memory/schemas/search.py(possibly raise content display limit)src/basic_memory/api/v2/utils.py(adjust truncation logic)Labels Applied
enhancement✓feat: return richer content context in search results (#609)
feat: improve content hit rate in search results (#609)
docs: update v0.19.0 release notes with post-draft changes