Repository navigation
Description
Thanks for basic-memory — it backs a small bilingual (Turkish/English) engineering vault for our team, and the local-first design is why we can keep it on a shared repo of plain markdown at all.
Following CONTRIBUTING's "create an issue first to discuss the approach": while tuning multilingual retrieval I measured something in the chunk-building path that looks unintended, and the fix appears well contained.
Environment
- basic-memory v0.22.1, sqlite backend, FastEmbed provider
- Embedding model
intfloat/multilingual-e5-large - Corpus: 8 shared team notes, Turkish queries against English notes
- Code below re-checked against current
main, where the logic moved tosrc/basic_memory/repository/semantic_chunking.pybut is otherwise identical
What happens
compose_row_source_text() prepends the note's title and permalink to the row's source text. split_text_into_chunks() then splits that text on markdown headings and on every bullet. Title and permalink are ordinary non-bullet lines, so they merge into the first chunk and only the first: every later chunk — which for an observations-style note means every single - [fact] … bullet — is embedded with no indication of which note it belongs to.
For a vault whose notes are mostly bullet lists of discrete facts, that means most vectors carry no note identity at all.
Why
Two pointers in semantic_chunking.py (search_repository_base.py up to v0.22.x):
compose_row_source_text()joinstitle,permalink,content_snippetinto one blob. The title is contributed once, positionally.split_text_into_chunks()starts a new section whenever_BULLET_PATTERNmatches, so the first bullet closes the title's section. Everything after inherits nothing.
Measurements
Read back from search_vector_chunks on a real vault, not estimated:
| chunks | 134 (8 notes) |
| median chunk | 178 chars |
| p25 / p75 | 89 / 441 chars |
| longest | 888 chars |
| under 60 chars | 23 chunks (17%) |
The short tail is structural rather than sloppy writing:
## Relationsis embedded as a standalone 12-character chunk, once per note that has one- each
- relates_to [[Some Note]]line becomes its own chunk - [name] abcws-monorepo(23 chars) is its own chunk
Direct probe of the cost, multilingual-e5-large, Turkish query against English bullets: naming the subject inside the bullet raised gold-chunk cosine from 0.769 to 0.807 (and top score 0.854 → 0.898) versus the bare bullet the chunker actually stores.
Being honest about that probe's limits: 6 candidate chunks, and it did not change ranking — both variants retrieved at rank 1. It measures the margin the missing context costs, not a recall win. On a larger vault where many notes share vocabulary, that margin is what has to separate the right note from a plausible wrong one.
Suggested shapes
Both are localized to semantic_chunking.py:
- Carry note identity into every chunk — prefix each chunk with the title (and optionally the permalink) rather than relying on positional inheritance in chunk 0.
- Don't emit content-free chunks — a chunk that is only a heading, or only a
relates_towikilink, spends an embedding and can never match a real query. Merging a bare heading into the following section would also make heading text useful to the chunks under it.
Either changes chunk text, so build_entity_fingerprint() invalidates and existing vaults re-embed on next sync — worth calling out in release notes.
Related but distinct
- Entity-aware ranking boost: cross-conversation entity confusion dominates hard retrieval misses in LoCoMo benchmark #951 (entity-aware ranking boost) improves ranking within a candidate set; this is about what goes into the vector in the first place.
- Document query/passage prefixes for asymmetric FastEmbed models #1264 covered the FastEmbed query/passage prefix gap.
embed_query()on currentmainstill delegates straight toembed_documents(), so if that issue was closed as documentation-only, this one is independent of it either way. Measured on our vault, applying the e5 prefixes by hand made no difference to ranking, so we are not blocked on it.
Offer
Happy to test a branch against this Turkish/English vault and report before/after chunk stats and retrieval scores — just point me at it. Not opening a PR directly since CONTRIBUTING asks for an issue first, and the CLA is a call for the repo owner on our side rather than mine.
Activity
gkhnelbstn commentedon Aug 26, 2026
Correction to my own "Related but distinct" note, before it misleads anyone reading this later.
I wrote that
embed_query()onmainstill delegates straight toembed_documents(), implying the prefix gap from #1264 was still open. That reading was wrong. #1044 landed in v0.23.0 and addedsemantic_embedding_document_prefix/semantic_embedding_query_prefix, applied byPrefixingEmbeddingProvideras a wrapper around any provider — soembed_query()is untouched by design, and the prefixes are very much applied. Including them in vector identity so a prefix change forces a re-embed is a nice touch.We are on v0.22.1, which predates that, which is why we saw no prefix support locally. Our own docs now say v0.23.0+ rather than "never applied".
Nothing in the issue above depends on that — the chunk context loss and the content-free chunks reproduce on current
main, which I re-checked insemantic_chunking.pyafter the 0.23 refactor moved it out ofsearch_repository_base.py. Sorry for the noise.phernandez commentedon Aug 28, 2026
Confirmed by reading
src/basic_memory/repository/semantic_chunking.pyonmain:compose_row_source_text()contributes title and permalink once, positionally, andsplit_text_into_chunks()opens a new section at every header and every bullet (_BULLET_PATTERN), so only the first chunk carries the note's identity and a bare## Relationsheading becomes its own 12-character vector. For bullet-heavy vaults that's most of the index with no note context. The measurements make the case well; thanks for doing them.Happy to take a PR. Two things to design in:
--fullreindex.- relates_to [[X]]lines are short but are how graph-adjacent retrieval currently surfaces; dropping the## Relationsheading chunk is clearly right, dropping the relation lines needs numbers.Same landing notes as for other contributors: DCO sign-off, CLA via the bot link on the PR, semantic title (
fix(core): …orperf(core): …), and fork PRs don't get the test matrix so I'll cherry-pick onto an in-repo branch for CI and rebase-merge with your authorship. Include your before/after retrieval numbers in the PR; we'll run the internal retrieval eval on it too.phernandez commentedon Aug 29, 2026
Fix is up in #1371.
I went a different way than either suggested shape, because both treat the symptom. The root cause is that the entity body was being split into one chunk per bullet — and observations and relations are already embedded as their own search rows (
observation:*,relation:*), each carrying the note title, permalink, and category/relation-type. So the per-bullet body chunks were duplicating those facts in a degraded, identity-stripped form.So instead of re-attaching the title to every bullet, or deciding which short chunks are "content-free" and dropping them:
## Relationsheading is never stranded, because it chunks together with the list under it.- relates_to [[X]]line still has its own vector via the relation row, so I didn't have to measure whether dropping relation bullets hurts graph-adjacent retrieval. That question goes away.On your two design points:
entity_fingerprintis built from each chunk'ssource_hash(a hash of the chunk text), and the chunk text changes for any note with bullets. No chunker-version marker needed — the chunk text is the version signal. A plainbm reindex(no--force) re-evaluates every entity and re-embeds exactly the affected notes while prose-only notes skip; individual notes also re-embed on their next edit.Your measurements are what made the shape obvious — thank you for reading them back out of
search_vector_chunksrather than estimating. The offer to run your Turkish/English vault against a branch is very welcome: #1371 is the branch. Before/after chunk stats (I'd expect the sub-60-char tail to mostly disappear) and retrieval scores would be great to have on the PR, and we'll run the internal retrieval eval on it too.fix(core): stop splitting entity body into per-bullet vector chunks