Skip to content

perf(core): read only the projects in scope from the vector indexes - #1574

Merged
phernandez merged 1 commit into
mainfrom
feat/1558-scoped-search-4a-ann-prefilter
Sep 16, 2026
Merged

phernandez merged 1 commit into
mainfrom
feat/1558-scoped-search-4a-ann-prefilter

Conversation

@phernandez

Copy link
Copy Markdown
Member

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.

  • sqlite-vec: project_id becomes 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.
  • pgvector: the statement now runs on the HNSW index (its tie-break sort keys had kept the planner on an exact scan), with hnsw.ef_search sized to the candidate window and hnsw.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

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@phernandez
phernandez merged commit 6c7bbea into main Sep 16, 2026
33 checks passed
@phernandez
phernandez deleted the feat/1558-scoped-search-4a-ann-prefilter branch September 16, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant