Skip to content

feat(ai): search RAG with Qdrant dense and BM25 fusion #4971

Open

Description

@dan-petty

Problem or Motivation

BM25 runs in Python only over the dense pool (hybrid_search_results, src/devops_cli/ai/rag/retriever.py:206-212), so it cannot find a chunk that dense search missed. Each query merges two collections, devops_code and devops_docs, in the client. Each point holds one unnamed dense vector, and no point carries visibility.

On the 62-query project eval set of #4961, BM25 over all chunks fused with dense search by RRF (B2f) gives:

  • nDCG@10 0.514 against 0.468 for dense only (B2f - D0 +0.046 [+0.004, +0.088], p 0.040);
  • on exact identifiers, 0.673 against 0.507 (+0.166, p 0.001);
  • on the 42 natural-language queries, no gain: -0.012 [-0.051, +0.026], p 0.57.

Thus the only measured gain of the hybrid step is on exact-identifier lookup. The relevance of an identifier query is an exact string match, so this gain is lexical by construction, and git grep also serves it. The hybrid pool also feeds the cross-encoder of child 7. B2 (hybrid pool, reranked) against B1d (dense pool, reranked) is +0.042 overall (p 0.10), +0.073 on identifiers (p 0.017), and -0.050 on issue_fix (p 0.004).

Qdrant 1.19.1 is live. It supports named sparse vectors with the IDF modifier, BM25 on the server (in core for self-hosted servers since 1.15.3), and prefetch with RRF and a set k (since 1.16).

Proposed Solution & Architectural Design

  • Make one collection behind the alias devops_rag (a dated collection name under it). It replaces devops_code and devops_docs.
  • Vectors: dense (1024, Cosine, int8 scalar quantization quantile 0.99 in RAM, HNSW m 16, ef_construct 100, as today) and the sparse vector bm25 with modifier idf. Qdrant fills bm25 on the server from the chunk text (Document with model qdrant/bm25). Check that qdrant-client sends the text to the server and does not load fastembed in the client process.
  • Payload: as today, plus commit and doc_class from feat(ai): RAG points carry the commit and the document class #4921 if it is merged. Keyword indexes for category, language and symbol_names. Write visibility on every point.
  • Query: one Query API call with two prefetches (dense top 100 and bm25 top 100, same filter) and RRF, limit 50, no cosine threshold. Set the RRF k explicitly: the study used 1/(60 + rank) with rank from 1, Qdrant counts positions from 0 and its default k is 2, so k 61 gives the study's fusion. Check the formula in the Qdrant source of the live version.
  • Delete the BM25 of src/devops_cli/ai/lexical.py from the retriever path, and the client RRF and merge.
  • Re-index once: ingest into the new collection. The model does not change, so cached dense vectors are reused. At the measured 45 texts/s with all cache misses, about 70,800 chunks after fix(ai): RAG chunks cover module code and use a token size #4967 take about 26 minutes. Check the point count and visibility, run the eval, then switch the alias. Keep the old collections for 7 days, then delete them. Open WebUI keeps the same embedding route.
  • If Qdrant 1.20 is live, also measure BM25 on a full-text index with the code tokenizer, and keep the better arm.
  • Do not claim a gain for natural-language queries until the code-behaviour queries of test(ai): a gold set measures retrieval of knowledge base facts #3902 measure it.

Target Subsystem

src/devops_cli/ai/rag/ (retriever, Qdrant store, indexer), src/devops_cli/ai/lexical.py, the Qdrant collection and alias, the RAG ingest.

Existing Tool Considered

Qdrant 1.19.1: named sparse vectors, server-side BM25 (qdrant/bm25, statistical, no model weights), the Query API with prefetch and RRF, and collection aliases. qdrant-client. No model server and no GPU. Rejected: a learned sparse model (the bge-m3 sparse output has no server among the candidates, and the SPLADE models are CC-BY-NC-SA-4.0). Estimated cost: about 0.40M tokens and 6 hours, plus the re-index.

Acceptance criteria

  • The collection has the named dense vector and the sparse vector bm25 with modifier idf. The point count equals the chunk count of the ingest. Every point has a visibility value.
  • The query sets the RRF k explicitly.
  • git grep finds no client BM25 or RRF code in the retriever path.
  • On the eval set of test(ai): a gold set measures retrieval of knowledge base facts #3902: nDCG@10 >= 0.50 and exact_identifier nDCG@10 >= 0.65 (measured B2f 0.514 and 0.673), above B0prod with p < 0.05, and natural-language nDCG@10 not lower than dense only by more than its bootstrap interval.
  • The full re-index takes less than 1 hour. The alias switches only after the eval passes.
  • RAG query p95 without rerank stays at or below 737 ms over 7 days.

Dependencies

#3902 (the eval set and the scorer), #4965 (the weighted reranker is gone) and #4967 (the chunker fix goes into the same re-index). Related: #4566 (the cluster ingest has never run; the re-index needs a working ingest path, in the cluster or from a workstation).

Source: #4961

Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: qdrant/qdrant (https://github.com/qdrant/qdrant), Apache-2.0, last activity 2026-11-27, maintained.
Reason: Searches and the fact reads confirm Qdrant, already the project's vector store, ships server-side BM25 (qdrant/bm25 with the idf modifier), named sparse vectors and one Query API call with prefetches and RRF k, which is the whole fusion need; only project-side work remains.

Covers:

  • Server-side BM25 from chunk text with the idf modifier
  • Named dense and sparse vectors in one collection
  • One query call with two prefetches and explicit RRF k
  • Collection aliases for a switchable dated collection
  • Keyword payload indexes and payload filtering

Lacks:

  • Eval-gated alias switch guard is project code
  • Visibility on every point is ingest-side enforcement
  • Re-index of about 70,800 chunks and p95 check are person steps
  • No client BM25 or merge removal; that is a code change

Proposed design

Problem statement

The RAG hybrid step scores BM25 in Python over the dense candidate pool. It cannot find a chunk that dense search missed. Each query merges the devops_code and devops_docs collections in the client, and no point carries visibility.

The change moves the lexical arm into Qdrant. The store uses one collection behind the devops_rag alias. It has the named dense vector dense and the sparse vector bm25 with the idf modifier. Qdrant computes BM25 on the server from the chunk text. One query call uses two prefetches and RRF at an explicit k. The measured gain is on exact-identifier queries only.

Acceptance criteria

Requirement: One collection behind the devops_rag alias

The RAG store SHALL read and write one collection through the devops_rag alias and SHALL not merge devops_code and devops_docs.

Scenario: Collection resolution

  • WHEN The retriever resolves the collection name.
  • THEN It returns devops_rag and the store sends no request to devops_code or devops_docs.

Requirement: Collection schema with dense and sparse vectors

The Qdrant store SHALL create the collection with the named dense vector dense and the named sparse vector bm25 with the idf modifier.

Scenario: Create-collection request

  • WHEN The store builds the create-collection request for a collection that does not exist.
  • THEN The request defines dense with size 1024, distance Cosine, int8 scalar quantization in RAM, HNSW m 16 and ef_construct 100. It defines bm25 as a sparse vector with modifier idf.

Requirement: Keyword payload indexes

The collection setup SHALL create keyword payload indexes for category, language and symbol_names.

Scenario: Payload index requests

  • WHEN The store creates the collection schema.
  • THEN It sends keyword index requests for category, language and symbol_names.

Requirement: Server-side BM25 from the chunk text

The indexer MUST send each chunk text as a Document with model qdrant/bm25 under bm25 and MUST NOT score BM25 in the client.

Scenario: Point for one chunk

  • WHEN The indexer builds the point for one chunk.
  • THEN The point holds the chunk text as a Document with model qdrant/bm25 under bm25, and the indexer module imports neither a BM25 scorer nor fastembed.

Requirement: Visibility on every point

The ingest SHALL write a non-empty visibility value on every point and SHALL fail when a chunk has no visibility value.

Scenario: Chunk with no visibility

  • WHEN The indexer builds a point for a chunk whose visibility is empty.
  • THEN The indexer raises an error and writes no point.

Requirement: One point for each chunk

The ingest SHALL write exactly one point for each chunk.

Scenario: Fixture ingest

  • WHEN The ingest completes over a fixture of N chunks.
  • THEN The collection holds N points and each point has a non-empty visibility value.

Requirement: One fused query with an explicit RRF k

The retriever MUST send one query call with dense and bm25 prefetches of 100, the same filter, RRF at an explicit k, limit 50 and no score threshold.

Scenario: Query request for one search

  • WHEN The retriever runs one search.
  • THEN The store sends one query call with two prefetches under the same filter, rrf fusion with an explicit k, limit 50 and no score threshold, and the first rank has weight 1/61.

Requirement: No client BM25, RRF or merge in the retriever path

The RAG retriever path SHALL contain no client BM25 ranking, no client RRF and no client merge of two collections.

Scenario: Retriever module import and search

  • WHEN The RAG retriever module is imported and one search runs.
  • THEN It imports no BM25 or RRF function from devops_cli.ai.lexical, runs one store call and reads one collection name.

Requirement: Alias switch waits for the eval

The alias switch MUST refuse to move the devops_rag alias when the eval result is below nDCG@10 0.50 or exact-identifier nDCG@10 0.65.

Scenario: Eval below the threshold

  • WHEN The switch reads an eval result that records nDCG@10 0.49.
  • THEN The switch returns an error, the alias keeps its target and the new collection stays.

Requirement: Pending a person after the merge

The migration MUST finish the re-index in less than 1 hour, switch the alias only after the eval of #3902 passes, and keep RAG query p95 without rerank at or below 737 ms for 7 days after the switch.

Scenario: Live re-index, eval and latency window

  • WHEN A person runs the re-index into the dated collection, runs the eval of test(ai): a gold set measures retrieval of knowledge base facts #3902 against it, and reads the RAG query p95 over the next 7 days.
  • THEN The re-index takes less than 1 hour. The point count equals the chunk count. Every point has a non-empty visibility. The eval reports nDCG@10 at or above 0.50 and exact-identifier nDCG@10 at or above 0.65, both above B0prod with p < 0.05. Natural-language is not lower than dense only by more than its bootstrap interval. The alias switches after the eval passes, and the 7-day p95 is at or below 737 ms.

Existing Tool Considered

Qdrant (qdrant/qdrant, Apache-2.0, maintained) is the tool. The alternatives check in the issue body gives the verdict in-use: the repository already uses Qdrant. The block lists what Qdrant covers and lacks. This change adds the project-side parts that the block lists as lacking: the required visibility field on every point, the eval-gated alias switch, and the removal of the client BM25 and merge. It sends Document with qdrant/bm25 on upsert and on query, and the first task confirms the installed qdrant-client. The issue estimates about 0.40M tokens and 6 hours plus the re-index.

Key questions

  • How does the store get server-side BM25 from the chunk text and the query text?: Send models.Document(text=chunk.content, model='qdrant/bm25') under bm25 on upsert. Send models.Document(text=query, model='qdrant/bm25') in the bm25 prefetch. Add a test that the indexer and retriever build this object and import no fastembed. The first task confirms the installed qdrant-client. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, src/devops_cli/ai/rag/retriever.py]
    • Chosen: Client Document with qdrant/bm25. Qdrant computes the sparse vector on the server and needs no model weights.
    • Rejected: Client BM25 scorer. It cannot score chunks outside the dense pool, which is the problem.
    • Rejected: fastembed in the client. It loads a model in the ingest process and adds a dependency.
  • Which RRF k does the query set?: Set an explicit k that makes the first-rank weight 1/61. Use k 61 when Qdrant ranks from 0, else k 60. The first task checks the rank base in the live Qdrant source. (best practice) [sources: src/devops_cli/ai/rag/retriever.py]
    • Chosen: Explicit k for a 1/61 top weight. It matches the study fusion at 1/(60 + rank).
    • Rejected: Default k 2. It overweights the top ranks and is not the study fusion.
    • Rejected: No explicit k. The fusion changes with the client default.
  • Does the change delete src/devops_cli/ai/lexical.py?: No. Keep the module and remove its use from the RAG retriever path only. Conversation search still calls the scorer. (best practice) [sources: src/devops_cli/ai/lexical.py, src/devops_cli/ai/rag/retriever.py]
    • Chosen: Keep the module and remove it from the RAG path. Conversation search shares the scorer, so a deletion breaks it.
    • Rejected: Delete the module. It breaks conversation search.
    • Rejected: Copy the scorer into the retriever. Two copies drift apart.
  • How does the migration replace the devops_code and devops_docs collections?: Ingest into a dated collection and point the devops_rag alias at it. The old collections stay read-only for 7 days and give a rollback. The switch is one alias update. (best practice) [sources: src/devops_cli/ai/rag/qdrant.py, src/devops_cli/ai/rag/retriever.py]
    • Chosen: A dated collection behind an alias. The switch is one step and the old collections give a rollback.
    • Rejected: Recreate one collection in place. There is no rollback, and the query fails during the re-index.
    • Rejected: Write both schemas. Two write paths must stay in step.
  • How is the eval gate enforced on the alias switch?: Add a guard in the switch code. It reads the eval result and refuses to move the alias when nDCG@10 is below 0.50 or exact-identifier nDCG@10 is below 0.65. A test checks the refusal offline. (best practice) [sources: src/devops_cli/ai/rag/qdrant.py]
    • Chosen: A guard in the switch code. The safe order is the only order and a test checks it offline.
    • Rejected: A runbook step. A person can skip it under time pressure.
    • Rejected: A CI check. CI holds no live collection and no eval result.
  • Which payload fields does the new collection hold?: Write today's fields, including commit and doc_class when the chunk has them, plus a required visibility and the keyword indexes for category, language and symbol_names. The indexer already writes commit and doc_class in _build_chunk_point. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, src/devops_cli/ai/rag/models.py]
    • Chosen: Today's fields plus required visibility. The change needs visibility and the indexes, and the code already writes commit and doc_class.
    • Rejected: Require feat(ai): RAG points carry the commit and the document class #4921 first. It blocks the re-index on an item that the code already covers.
    • Rejected: Omit visibility. The issue needs visibility on every point.
  • Does the re-index depend on feat(k8s): let Argo Workflows run roadmap pods in devops #4566?: No hard dependency. The code change can use the workstation ingest path, and the live re-index is a post-merge person step. feat(k8s): let Argo Workflows run roadmap pods in devops #4566 stays related. If neither the cluster nor the workstation path works, that step blocks. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, tests/commands/test_ai_rag_commands.py]
  • What does the ingest do when a chunk has no visibility value?: Refuse the point and raise an error. The issue needs a non-empty visibility on every point, and a default would hide missing data. (best practice) [sources: src/devops_cli/ai/rag/indexer.py]
    • Chosen: Refuse the point. The issue needs a non-empty value on every point.
    • Rejected: Default to private. It hides missing data and changes the filter result.
    • Rejected: Write no field. It breaks the visibility requirement.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#3902, #4965, #4967

Moved to new items

#7755

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/feature
    scope/ai
    status/new
    value/medium
    effort/high
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: Searches and the Qdrant docs show that Qdrant already ships everything the issue asks to adopt: named dense and sparse vectors, a sparse vector with the IDF modifier filled server-side from the chunk text by the qdrant/bm25 model, the Query API with prefetch plus RRF fusion and an explicit k, and collection aliases. The issue itself states Qdrant 1.19.1 is live in the project, so the change is a configuration and migration of the existing store, not new code.

    The repository already uses this tool.

    Tool: qdrant/qdrant (https://github.com/qdrant/qdrant)

    • License: Apache-2.0
    • Last activity: 2026-11-15
    • Maintained: yes

    Covers:

    • Named dense and sparse vectors on one collection, behind a collection alias
    • Sparse vector with the idf modifier, IDF kept at the collection level
    • Server-side BM25 from the chunk text with the qdrant/bm25 model (a Document is sent on upsert and on query, so no model weights or GPU are needed)
    • One Query API call with several prefetches (dense and bm25) and rrf fusion, with k set explicitly
    • Full-text index with BM25 as the second arm the issue wants to measure on 1.20
    • Filters inside each prefetch, so the same payload filter applies to both arms

    Lacks:

    Tools considered:

    Searches run:

    • Qdrant sparse vector BM25 IDF modifier server-side, results: 5
    • Qdrant Query API prefetch RRF fusion k parameter, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 181f85e while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/ai/rag/chunker.py, src/devops_cli/ai/rag/ingest.py, src/devops_cli/ai/rag/reranker.py.

  7. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 86358b6 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  8. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  9. added
    status/ready
    and removed
    status/new
    on Nov 29, 2026
  10. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/aisource/agentstatus/readytype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions