perf(core): read only the projects in scope from the vector indexes - #1574
Merged
Merged
Conversation
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]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Sep 16, 2026
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
Same branch and commit as #1569, opened against
main. #1569 was stacked on the 3b branch, which was merged before it, and GitHub refuses to retarget a PR that is part of a stack. See #1569 for the full description and measurements.project_idbecomes a vec0 partition key, so a scoped nearest-neighbour query ranks each project's own vectors instead of taking the k nearest across the whole database and discarding the out-of-scope ones. Existing local storage is carried into the partitioned table without re-embedding.hnsw.ef_searchsized to the candidate window andhnsw.iterative_scan = relaxed_order. pgvector 0.8 is required; an older extension raises a dependency error at first use.Refs #1558, #1569
🤖 Generated with Claude Code
https://claude.ai/code/session_019YW9ysxugGGBCNEGzsxtFV