refactor(core): extract SearchReader and SemanticSearch from the search repository - #1565
Merged
phernandez merged 1 commit intoSep 15, 2026
Conversation
…ch repository Retrieval leaves SearchRepositoryBase. SearchReader runs one prepared query over one ProjectScope in whichever mode it asks for; SemanticSearch owns vector and hybrid retrieval (adapter lookup, manifest hydration, the structured filter pass, score fusion, reranking, pagination) over a VectorRetrieval that is present or absent instead of probed with hasattr. The repository keeps what only it knows, whether semantic search is enabled and its vector tables exist, and builds a reader per call from its current state. Hydrated chunks are a typed HydratedChunk, which retires the best_distance compatibility branch and the per-backend _distance_to_similarity hooks the adapters had already replaced. PreparedSearchQuery gains has_filters, the predicate the vector path uses to decide whether to run the filter pass. Test doubles construct the pipeline directly (a FakeFts backend and a VectorRetrieval over a stubbed adapter) instead of subclassing the repository and patching its private hooks. No query behavior changes. Part of #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. |
phernandez
added this pull request to stack #1564
September 15, 2026 19:12
This was referenced Sep 15, 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.
Part of #1558. Third PR in the stack, on top of #1563 (which is on #1562).
What changes
Retrieval leaves
SearchRepositoryBase.SearchReader(scope, fts, semantic=None)runs onePreparedSearchQueryover oneProjectScopein whichever mode it asks for: the engine'sFtsBackendfor FTS,SemanticSearchfor vector and hybrid. It raisesSemanticSearchDisabledErrorwhen a semantic mode is asked of a reader built without the semantic stack, and the sameValueErroras before when a semantic mode has nothing to embed.SemanticSearch(session_maker, scope, fts, vector, rerank=None)owns the vector and hybrid pipeline: adapter nearest-neighbour lookup, manifest hydration, the structured filter pass throughcandidate_keys, score fusion, reranking, and pagination. It is constructed only when aVectorRetrievalis present, so no stage re-checks availability.VectorRetrievalandRerankingare frozen bundles of the live semantic stack. Hydrated chunks are a typedHydratedChunk, which retires thebest_distancecompatibility branch and thehasattr(self, "_semantic_vector_index")and_prepare_vector_sessionbranches on the read path.search()runs that gate, then builds a reader from its current attributes for each call, because the semantic flag can flip at runtime ([BUG] Fatal crash on startup when python.org Python 3.12 is present alongside Homebrew on macOS #711) and tests retune thresholds between searches.PreparedSearchQuery.has_filtersnames the predicate the vector path uses to decide whether to run the filter pass._distance_to_similarityis removed from the base and both repositories; the adapters already return calibrated similarity.parse_chunk_key,vector_eligible,rerank_document_text,demote_tail, andcurrent_vector_manifest_predicateare module functions insearch_reader.No query behavior changes.
search_repository_base.pygoes from 3002 to 1819 lines.Tests
Test doubles construct the pipeline directly instead of subclassing the repository and patching its private hooks.
FakeFtsis a typedFtsBackenddouble that records the queries it was asked, andfake_vector_retrieval()is aVectorRetrievalover a stubbed adapter. Six repository subclasses and the_run_vector_query/_ensure_vector_tables/_prepare_vector_sessionpatches across about fourteen files go away. The tests that still drive a real repository patchSemanticSearch._run_vector_queryat class level.tests/repository/test_search_reader.pyis new and pins reader dispatch plus the pipeline edges the migrated tests do not reach.search_reader.pyis at 100% line coverage in the unit suites.just fast-checktests/repository, SQLitetests/repository, Postgres (testcontainers)tests/services,tests/api,tests/mcp,tests/cli, SQLitejust doctorNext in the stack
PR 3 adds
QUERY /v2/search/and a scoped service method that builds aSearchReaderover a multi-projectProjectScopewithout a repository.🤖 Generated with Claude Code
https://claude.ai/code/session_019YW9ysxugGGBCNEGzsxtFV