fix(core): fill a filtered vector window instead of stopping at rejected neighbours - #1570
Closed
phernandez wants to merge 2 commits into
Closed
phernandez wants to merge 2 commits into
phernandez wants to merge 2 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
phernandez
added this pull request to stack #1572
September 15, 2026 23:56
phernandez
force-pushed
the
feat/1558-scoped-search-4b-filtered-window
branch
from
September 16, 2026 00:00
17587fd to
f4604ab
Compare
Both built-in vector adapters took the k nearest vectors across the whole database and applied the scope afterwards. In a shared database a small project could get an under-filled or empty page for a query its own notes answered, because a larger neighbour's vectors filled the window first. On a 20k-chunk corpus where one project holds 2% of the vectors, a limit-100 query for that project returned 1 row from sqlite-vec. sqlite-vec: `project_id` becomes a vec0 partition key, so the KNN ranks each partition in scope and the outer ORDER BY merges them (100 of 100 rows, 0.2 ms against 3.1 ms). Existing local storage is carried into the partitioned table through a temporary table inside one transaction; vectors and ready manifests survive, nothing is re-embedded. Dimension and source_hash mismatches still rebuild as before. pgvector: the statement's tie-break sort keys had kept the planner off the HNSW index entirely, so every vector query was an exact scan of the table. The window is now taken by distance alone inside a materialized CTE and re-sorted with the tie-breaks outside it. `hnsw.ef_search` is set per transaction to the window the query must fill (the default 40 capped every larger candidate pool), and `hnsw.iterative_scan = relaxed_order` lets the scan continue until the scope and manifest filters have admitted enough rows. That scan needs pgvector 0.8; an older extension now raises SemanticDependenciesMissingError at first use rather than returning short windows. Neon tenants run 0.8.0. Refs #1558 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019YW9ysxugGGBCNEGzsxtFV Signed-off-by: phernandez <[email protected]>
…ted neighbours The vector index ranks by similarity alone and cannot evaluate structured filters (note types, dates, categories, metadata, path prefixes, valid time). Vector and hybrid retrieval took one window of `candidate_limit` chunks from that ranking and asked the full-text pass which of them the filters admitted. When the nearest chunks belonged to rows the filter rejects, the window held few admitted rows while more sat just past it, and the page came back short although matches existed. `vector_only` now resolves its window through `_candidate_window`, which re-reads the ranking with a bounded geometric overfetch until the window holds `candidate_limit` admitted rows, the ranking is exhausted (a short read, no growth, or the scan cap), or its tail has fallen below the similarity threshold, past which nothing further can qualify. A query without filters resolves its window once, as before. The chunk-to-row resolution (keys, threshold, row fetch, filter) moves into `_resolve_rows`, returning a frozen `CandidateWindow`; `_run_vector_query` and the trace stage are unchanged, and each round replaces the previous round's rejection lists so the trace reads the final window. Refs #1558 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019YW9ysxugGGBCNEGzsxtFV Signed-off-by: phernandez <[email protected]>
phernandez
force-pushed
the
feat/1558-scoped-search-4b-filtered-window
branch
from
September 16, 2026 00:00
f4604ab to
7016dae
Compare
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.
Summary
Seventh PR in the #1558 stack, on top of #1569. Second half of the "vector order" item: a vector or hybrid search that carries structured filters now fills its candidate window.
What was wrong. The vector index ranks by similarity alone and cannot evaluate note types, dates, categories, metadata, path prefixes, or valid time. Retrieval took one window of
candidate_limitchunks from that ranking and asked the full-text pass which of them the filters admitted. When the nearest chunks belonged to rows the filter rejects, the window held few admitted rows while more sat just past it, and the page came back short although matches existed. Twelve archive notes nearer the query than three matching notes were enough to turn afile_path_prefix="notes"search into an empty answer.What changes.
vector_onlyresolves its window through a small loop: read the window, resolve chunks to rows (keys, threshold, row fetch, filter), and if the query has filters and the window is not full, read it again twice as wide. The loop stops when the window holdscandidate_limitadmitted rows, when the ranking is exhausted (a short read, no growth between reads, or the existing 50k scan cap), or when the tail of the ranking has fallen below the similarity threshold, past which nothing further can qualify. A query without filters reads its window once, exactly as before.This is the same rule for both routes and every adapter, and it adapts to filter selectivity without estimating it: a broad filter finishes in one read, a narrow one pays a few more reads of the same ranking. It replaces neither the scope pre-filter from #1569 nor the candidate-key restriction from #1431; it sits on top of both.
Shape. The chunk-to-row resolution that used to sit inline in
vector_onlymoves into_resolve_rows, returning a frozenCandidateWindow._run_vector_query, hydration, and the trace stage are unchanged; each round replaces the previous round's rejection lists, so a trace reads the final window.Test plan
just fast-checktests/repository/test_vector_filter_window.py: the window widens 20 then 40 and returns the admitted rows; an unfiltered query reads once and never asks the filter; an exhausted ranking returns what it admitted; a ranking that stops growing ends the loop; a sub-threshold tail ends it; the widening is bounded by the scan cap; each round asks the filter only about the candidates it holds. Five of the seven fail on the previous reader.tests/repository tests/services tests/apiplus the search tool tests on SQLite (2193 passed)test-intsemantic coverage, search diagnostics, vec0 status (13 passed)Refs #1558
🤖 Generated with Claude Code
https://claude.ai/code/session_019YW9ysxugGGBCNEGzsxtFV