Repository navigation
Vector search stays an exact scan, with the measurements that rule out an HNSW index - #131
Merged
Merged
Conversation
On ClickHouse 26.9 a vector_similarity index is never searched by a read whose primary-key condition prunes granules, and every Loom vector read filters on the (org, namespace) sort-key prefix. Where the index does run, a selective filter drops recall@10 to 0.10-0.82, and under FINAL it serves superseded versions. docs/architecture/clickhouse.md records the numbers; bench/vector_index_vs_exact.py reproduces them on synthetic vectors against any ClickHouse. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…and drops its tables Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y-index Signed-off-by: zlareb1 <[email protected]>
Codes-first at the fact leg's LIMIT 60, the partition-per-tenant win at 50%, the FINAL reread arm, per-run query tags and the cache-miss count. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d the harness drops its tables on any exit Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y-index Signed-off-by: zlareb1 <[email protected]>
…he cache observation as measured Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…rt its ClickHouse, and what the health probe can still find Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…k and the health probe's table shape Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y-index Signed-off-by: zlareb1 <[email protected]>
… each Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e every part and probe output Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This was referenced Oct 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #17
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
...
Why
Semantic search is an exact
cosineDistancescan over a tenant's rows, so its cost grows with namespace size. This evaluated avector_similarity(HNSW) index onmemory_embeddingsand on the knowledge and chunk tables, which share the read shape: every vector table's sort key starts with(org, namespace), and every read filters on it. The index does not hold up, so no migration or setting ships.docs/architecture/clickhouse.mdgains "Why there is no vector index" with the numbers below, andbench/vector_index_vs_exact.pyreproduces them.Setup.
BFloat16vectors: 500 clusters around a 16-dimensional latent space.memory_embeddings(its sort key,ReplacingMergeTree,index_granularity = 256, one merged part per partition):Quantized-coded;'hnsw', 'cosineDistance', 1536, 'bf16', 16, 128: M 16, ef_construction 128,GRANULARITY 100000000);system.query_logProfileEvents (USearchSearchCount,VectorSimilarityIndexCacheMisses), with tags unique to the run.1. A tenant read never searches the index. ClickHouse searches the graph only when the primary-key condition keeps every granule of a part. In every vector table but
code_chunksa part holds many tenants, so a(org, namespace)filter prunes to the tenant's granules and the read sorts them exactly.code_chunksis partitioned by(org, namespace), so an index there would run: points 2 and 3 are what rule it out. Index searches were zero for every tenant, and rows and bytes read matched the plain table, under everyvector_search_filter_strategy, multiplier andeftried. MiB read and p50, every read underFINAL:The codes-first column uses the fact leg's shape: 60 rows, codes multiplier 1. recall@10 of those 60 rows against the exact top 10 was 0.95-1.00. The 10% tenant's exact read is slower than the 50% one in both runs, so compare bytes rather than milliseconds.
2. Where the index does run, a selective filter loses recall. With a predicate outside the sort key (
cityHash64(memory_key) % 1000 < n), the graph runs first and the predicate post-filters its candidates. recall@10 byvector_search_index_fetch_multiplier:ef = 256; it is 0.847 atef = 1024.FINAL, at recall 0.757;3. Under
FINALit serves superseded versions.bench/ann_final_staleness.py(30k keys x 3 versions, 18 parts, 128 dimensions) on 26.9:final: recall@10 0.38, with 6.2 of 10 rows stale;prefilter, which skips the index: 1.00 with no stale rows, 20 ms;reread, which re-reads the index's candidate keys underFINAL: 0.90-0.98 at 37-39 ms against 20 ms.4. Write, storage and memory cost.
vector_similarity_index_cache_size5 GiB,SLRU) and took 4.8 s instead of 9 ms. The harness now prints the cache settings.So an index would cost writes, storage and cache memory, would never serve a tenant read, and would serve stale rows wherever it did run. The codes-first read already cuts the bytes of a 100k-row-or-larger tenant's scan 6-11x.
The doc names when to look again: when ClickHouse searches the graph within the primary-key ranges a read selects, and resolves versions under
FINAL.Reproduce (a ClickHouse you started; no provider, no Loom server; about 40 minutes and about 15 GiB of disk, plus room to rewrite the largest table):
LOOM_CH_CONTAINER=ch-vbench LOOM_CH_HOST_PORT=18433 LOOM_CH_NATIVE_HOST_PORT=19433 bash dev/ci_start_clickhouse.sh PYTHONPATH=$PWD .venv/bin/python bench/vector_index_vs_exact.py \ --port 18433 --user loom --password loomdev --rows 1000000 --dim 1536 --build .venv/bin/python bench/ann_final_staleness.py --url http://localhost:18433 --user loom --password loomdev docker rm -f ch-vbenchScope and risk
This PR changes documentation and adds one offline harness. No server code, migration, setting, op or stored data changes. The harness writes only to its own database (
loom_vbenchby default) and drops its tables at the end unless given--keep.bench/vector_tenant_recall.pynow has a docstring that matches the table as it is.Left alone on purpose:
LOOM_VECTOR_SEARCH_EF_SEARCHandLOOM_VECTOR_SEARCH_INDEX_FETCH_MULTIPLIERonly tune an index that no table has. Whether to remove them is the open question from the related PR, and it needs its own decision.embedding_hnsw_idxentry inmemory_embeddings'exclude_materialize_skip_indexes_on_merge.server/memory/app/retrieval/fact_sql.py. The SQL comment there says the identity PREWHERE makes ClickHouse post-filter, but the measurement shows it keeps the read off the graph. Fixing it belongs with the settings decision, and this PR leaves the server untouched.Seen on the way, not changed here: at
LIMIT 10with multiplier 3, codes-first scored recall@10 0.73-0.88 on the 1M-row and 500k-row filters. The comment inserver/core/vectors/search_settings.pysays that "x3 held recall 1.000". The fact leg's own shape (LIMIT 60, x1) is in the table above.Compatibility, rollout and rollback
Tests
make format lint typecheck: pass. The codegen checks insidemake lintall report current.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (Claude Code): I checked every figure in the doc against the harness output. I checked the index-use column against
EXPLAIN indexes = 1and against the query_log counters.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (format, lint and typecheck ran locally; unit tests are left to CI)main; no merged migration is edited. (no migration)frontend/changed. (unchanged)docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s).🤖 Generated with Claude Code