fix(core): reuse retrieval for stable rerank pagination - #1560
Open
phernandez wants to merge 2 commits into
Open
phernandez wants to merge 2 commits into
phernandez wants to merge 2 commits into
Conversation
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
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 #1561
September 15, 2026 14:55
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.
Why
Fixes #1557. Expanded hybrid/vector pages currently repeat retrieval to reconstruct the fixed reranker prefix. This adds a second query embedding and vector query (and a second FTS pass for hybrid) before the one reranker call.
Stacked on #1559, with base
feat/1558-multi-project-searchat0159119c7328729b7ac69be342031e072c073a6d. Neither PR is to be merged as part of this task.What Changed
stable_pool_refetched=false.Implementation Details
The request-local vector window carries prefix rows and original chunk ranks; it is not cached or stored on the repository. Hydration and filter evaluation are shared by prefix and tail.
SQLite vec0's equal-distance top-k membership changes with k, so simply slicing a larger retrieval is insufficient. Reranker-enabled SQLite requests use vec0's existing 4,096-candidate ceiling as a repeatable tie universe, then trim the requested chunk window in SQL before project/manifest filtering. Original positions survive dropped matches. The disabled path retains its existing k sizing. PostgreSQL retrieval SQL is unchanged.
Testing
[18, 8]and hybrid limits[90, 80]; the fixed path uses[18]and[90].just fast-check: passed (ruff, formatting, full ty check).just doctor: passed.just fast-checkpassed, the fixture-dependent SQLite selection passed 51 tests, and standalonetest-int/test_stable_rerank_pagination.pypassed 2 tests on each of SQLite and Postgres. ty uses pytest's existingtestsimport root.The real FastEmbed/Postgres test passed, including a 101-result request and deep pages. New regressions exercise real sqlite-vec/pgvector, API/MCP probes and later empty pages, tied similarities, mixed lexical/vector matches, multi-chunk collapse, fixed reranker document text, pending manifests, thresholds, filters, and reranking enabled/disabled. Stage-span assertions require exactly one embedding/vector span per request and one FTS span for hybrid. All 55 added executable production lines were covered by the selected SQLite run.
Risks / Follow-ups
SQLite reranker-enabled shallow requests do more bounded vec0 selection work to make ties repeatable. A local synthetic microbenchmark (384 dimensions, seed 1557, five warm iterations) compared the old two k queries (890 + 80) with one fixed-4096 query trimmed to 890: 10k vectors, 9.39 ms versus 9.98 ms; 50k vectors, 45.79 ms versus 45.48 ms. This isolates retrieval and is not a production latency or model-inference benchmark. A substantially slower scalar-distance scan was rejected.
Existing best-effort chunk headroom and backend candidate ceilings remain. No Cloud configuration, production reranker enablement, cache, locking, or admission system changes.