feat(search): Cosmos full-text search as composable index mode#180
Merged
Conversation
Adds 'mode: vector|fts' to IndexSpec so callers can declare an index as full-text only and merge it with vector indexes via the existing RRF strategy. Cosmos-only in v1 (pgvector follows separately). Schema changes: - IndexSpec.mode (default 'vector', preserves backward compat) - IndexSpec.embedding now Optional; validator requires it iff mode='vector' - IndexSpec.fts_field (defaults to content_fields[0] at search time) - fts_field validated against strict path regex (SQL-injection guard) - mode='fts' rejected for pgvector stores (clear error, not silent) Searcher changes: - search_cosmos_fts() uses Cosmos 'ORDER BY RANK FullTextScore(field, @t0, @t1, ...)' with bound term params; native score is not projectable so hits get score=None and rank via RRF - _tokenize_fts_query(): lowercase, dedupe, cap to SEARCH_FTS_MAX_TERMS=16 - _search_one_index branches on idx.mode, skipping embed_query entirely for FTS - run_search emits warning when merge.strategy='score' is used with FTS indexes - explain_search renders FTS plan without touching idx.embedding Tests: 17 new (schema validation, tokenization, SQL shape, per-index branching, explain). OpenAPI snapshot refreshed. Full unit suite: 217 passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Adds full-text search as a composable index mode alongside vector search. Callers can now mix FTS-only and vector indexes in a single /search request and let the existing RRF merge fuse the results.
What
Schema ( + "search/schemas.py" + )
Searcher ( + "search/searcher.py" + )
SELECT TOP @top_k c FROM c [WHERE ...]
ORDER BY RANK FullTextScore(c., @Term0, @Term1, ...)
Cosmos forbids + "FullTextScore" + in projection, so hits return + "score=None" + and rank via RRF (use + "merge.strategy="rrf"" + — a warning fires for + ""score"" + with mixed FTS+vector).
un_search()" + modality classification treats FTS as text
Why
User wanted full-text search next to vector search. Option B (FTS as a separate index mode merged via RRF) was chosen over native Cosmos hybrid because it composes: an FTS-only index over Cosmos can merge with vector indexes over Cosmos or pgvector or CLIP image indexes — all via the existing per-index RRF.
Cosmos container requirement
The target container must have a full-text indexing policy on + "ts_field" + before this works. The existing demo container ( + "
ationwide-delta-1536" + ) will need an ALTER. Follow-up deployment task.
Tests
Follow-ups