Repository navigation
Description
Problem
Three defects let the RAG index silently go wrong when the embedding model changes. Lines are at release/v0.2.25 (e3ff98c).
1. No collection records which model made its vectors. A point's payload holds the file, lines, content, language, category, project, symbols, metadata and content hash, but no model (src/devops_cli/ai/rag/indexer.py:212-228). The collection itself records only its vector size. The planned switch from bge-m3:latest to qwen3-embedding:0.6b (#481) keeps the size at 1024. After it, queries embedded by one model would be compared with vectors from the other, with no error, and the code would never notice. Today the only safeguard is to remember devops ai rag clear --force before re-indexing (commands/rag.py:510-552).
2. A search can delete the index.
- When a query's dimension does not match the collection,
search_pointscalls_handle_dim_mismatch(ai/rag/qdrant.py:462-468). - That handler deletes the collection and creates it again, empty, at the query's dimension (
:472-489). - It logs a warning and returns no results. Every later search finds nothing until someone re-indexes.
- So a read path wipes stored data. Any lookup whose model resolves to another dimension does this, from a review, verification, chat or
rag query. Examples are a misconfiguredai.tasks.embedding, or an engine that falls back to the dimension table because it could not probe the model (ai/rag/embeddings.py:471-475, whereqwen3-embeddingis wrongly 768). ensure_collectiondoes the same on the index path (qdrant.py:327-337): it deletes a collection whose size differs and creates it again.
3. Ranking throws away the cosine score.
- With hybrid search,
reciprocal_rank_fusionwrites the fused rank value over each result'sscore(ai/rag/retriever.py:232-235;k= 60). - The reranker then reads that value as its vector signal, weighted 0.5 (
ai/rag/reranker.py:193-195;DEFAULT_RERANKER_VECTOR_WEIGHT,config/defaults.py:354). - The fused value is at most 2/61 ≈ 0.033, so the whole dense-plus-lexical rank term adds at most about 0.016, and the dense rank's own share is at most about 0.008. The raw cosine acts only through Qdrant's
score_thresholdgate and the size of the candidate pool. devops ai rag queryshows the fused or reranked score, not the cosine, so it cannot be used to calibrate the threshold for a new model.
Source: .data/slow-tier-plan-20261003.md, section 4 ("RAG index integrity"), and its verification pass, which re-read each line. The lines above were checked again at e3ff98c.
Acceptance criteria
-
Every point the workspace indexer writes (
devops ai rag indexandindex-kb) carriesembedding_model, the model name as configured, in its payload. -
Before indexing into a collection that already holds points, the indexer reads one point's
embedding_model. If it names another model, or the collection's size differs from the model's, indexing fails with exit 1 and a message naming both models and the fix (devops ai rag clear --force, thendevops ai rag index --force).--forcedoes not recreate the collection by itself. Onlycleardeletes it. -
A search whose dimension does not match never deletes or recreates the collection.
_handle_dim_mismatchgoes. The search raises anEmbeddingsErrormarked permanent that names the collection, both dimensions and the same fix. RAG treats it like an unserved model: it stops for the run, with one warning (fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run, and each embedding model gets its own prompts, cache keys, dimension and bounded chunks #1065's permanent error). -
A search also checks the model a collection records, once per process. A query model that differs from it raises the same error before any search runs.
-
SearchResultkeeps the cosine from Qdrant in its own field (for examplevector_score), and fusion writes its value to a separate field. The reranker's vector signal reads the cosine.devops ai rag queryprints the cosine beside the final score. -
Tests with a fake Qdrant client:
- a collection holding
bge-m3:latestpoints refuses an index run withqwen3-embedding:0.6b, and the collection keeps its points; - a 768-dimension query against a 1024-dimension collection raises, and the fake client records no delete or create call;
- two results with the same fused rank but cosines of 0.9 and 0.4 come out of the reranker in cosine order.
The first two fail on the current code.
- a collection holding
-
The tests run offline, call no Qdrant, gateway, Ollama or model, and each runs in under 1 s.
-
changelog.d/1066.mdrecords the fix under### Fixed.CHANGELOG.mdis not edited. -
uv run devops cipasses. -
(person-run) After the next full index:
devops ai rag statusshows the point counts, and one point fetched from each collection carriesembedding_model. Then setai.tasks.embedding.modelto another model and rundevops ai rag query "<path> <symbol>". It fails with the message, and the counts are unchanged.
Key questions
- Where is the model recorded: in each point's payload or in collection metadata? (proposed) In each point's payload. It works with any Qdrant version, survives per-file upserts, and needs no second write path. Reading it costs one
scrollof one point, once per collection and process. - Should a mismatch re-index automatically instead of failing? (proposed) No. Re-indexing this repository is about 17,500 chunks, estimated at 15–30 minutes on the 48gib-slow tier. A search must not start that, or wipe the index, as a side effect. The fix is one command, and the message names it.
- What about collections written before this change, whose points carry no
embedding_model? (proposed) Treat them as unknown. Searching them still works, and indexing into one asks forrag clear --forceonce. Pre-1.0 needs no migration, and the collections are effectively empty today (76 of 76 searches returned nothing, per the plan). - Which score does
--min-score/score_thresholdgate on? (proposed) The cosine, as today, through Qdrant. This item only stops it from being overwritten afterwards, so a threshold set fromrag query's cosine means what it says. - Is this P1? Decided (review redesign, 2026-10-03): yes. It was proposed as P2 because it needs a model switch or a misconfiguration to bite, but fix(ai): the knowledge base is re-indexed whenever the installed knowledge base differs from what its collection holds, and rag status and drift read Qdrant instead of the local cache #1139 (the knowledge base is re-indexed on use) depends on it, and the RAG client fixes (fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run, and each embedding model gets its own prompts, cache keys, dimension and bounded chunks #1065, P1) still come first. It must land before feat(ai): embeddings through the llm gateway, with embedding model evaluation #481's switch, or the switch runs
rag clear --forceby hand as the plan says.
Strategic alignment
Depends on: none.
Order: before #481's switch to qwen3-embedding:0.6b, or that switch clears the collections by hand. The RAG client fixes (#1065) edit investigator.py, embeddings.py and the indexer's batch loop. This item edits qdrant.py, the indexer's point payload and retriever.py/reranker.py. Whichever lands second rebases.
Related:
- feat(ai): embeddings through the llm gateway, with embedding model evaluation #481: the embedding-model comparison and switch.
- fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run, and each embedding model gets its own prompts, cache keys, dimension and bounded chunks #1065: the RAG client fixes (breaker, prompts, cache keys, dimension table).
- fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945: no fallback vectors, and RAG stopping on an unserved model.
- feat(cli): qdrant vector engine async connection pooling, hybrid lexical-dense search & payload quantization research #313: hybrid lexical-dense search.
- refactor(ai): the agent, rag, benchmark and spend tables move out of config/ next to their owners #1028: the
ai/ragconstants move next to their owners.
Review redesign placement (2026-10-03)
- This item is a phase P0 child of the evidence-first review (feat(review): evidence-first code review — tools find, version-pinned facts ground, models explain and plan, fixes are re-checked #1137), raised from P2 to P1 (see the key question above). Any later review use of embeddings waits for it and feat(ai): embeddings through the llm gateway, with embedding model evaluation #481.
- The body above stands. fix(ai): the knowledge base is re-indexed whenever the installed knowledge base differs from what its collection holds, and rag status and drift read Qdrant instead of the local cache #1139 records the installed knowledge base's digest beside this item's
embedding_modelon every point.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty-bot commentedon Oct 10, 2026
Moved to v0.2.34: v0.2.34 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(ai): a rag collection records its embedding model, a mismatch fai…
dan-petty commentedon Oct 11, 2026
Merged
feat(release): v0.2.34 (#1566)