Skip to content

fix(ai): rank RAG hits by fusion, not by the weighted score #4965

Description

@dan-petty

Problem or Motivation

With the defaults (rerank=True, hybrid=True), SearchReranker (src/devops_cli/ai/rag/reranker.py:149) sorts the hits by its own weighted score: 0.5 vector, 0.2 token overlap and fixed bonuses. Retriever._rank_results returns that order when rerank is on (src/devops_cli/ai/rag/retriever.py:421-422), so the RRF order of the hybrid step has no effect.

On the 62-query project eval set of #4961, the weighted score lowers quality:

  • nDCG@10: 0.386 (current path, B0) against 0.468 for dense search only (D0). D0 - B0 is +0.082 [+0.006, +0.159], bootstrap p 0.036 (sign-flip p 0.043).
  • MRR@10: 0.423 against 0.557 (p 0.011).
  • On the 42 natural-language queries, D0 - B0 is +0.113 (p 0.024).
  • It also lowers the hybrid pool: B2w (hybrid plus the weighted score) 0.430 against B2f (hybrid only) 0.514.

This is the largest gain of the plan that needs no GPU and no cluster change.

Proposed Solution & Architectural Design

Delete SearchReranker, its rerank flag path and the DEFAULT_RERANKER_* weights (src/devops_cli/config/defaults.py:414-416 and 509-510). The final order is the RRF order of the hybrid step until the cross-encoder stage of #4961 (child 7) comes. Remove the settings that no code reads any more, and update the RAG text in ARCHITECTURE.md and the generated settings reference. No shim (alpha before 1.0.0).

Target Subsystem

src/devops_cli/ai/rag/ (reranker, retriever), src/devops_cli/config/defaults.py, ARCHITECTURE.md.

Existing Tool Considered

This change deletes code and adds none. The eval scorer of #3902 measures the result. Estimated cost: about 0.12M tokens and 2 hours.

Acceptance criteria

  • git grep finds no SearchReranker and no DEFAULT_RERANKER_ constant.
  • On the eval set of test(ai): a gold set measures retrieval of knowledge base facts #3902, the production path has nDCG@10 of at least 0.45, and it is above B0prod (0.393) with p < 0.05 (paired comparison).
  • RAG query p95 stays at or below 737 ms in devops_cli_rag_query_duration_ms over 7 days.

Dependencies

#3902 (the eval set and the scorer).

Source: #4961

Alternatives check of 2026-11-27: partly.
Tool: AmenRa/ranx (https://github.com/AmenRa/ranx), MIT, last activity 2025-08-07, not maintained.
Reason: Searches found ranx, an open MIT library that fuses ranked runs (RRF and other combiners) and scores nDCG/MRR with paired significance tests, so it covers the fusion ordering and the eval metric; it cannot delete SearchReranker, its flag, settings or docs, and the hybrid step already does RRF.

Covers:

  • Reciprocal rank fusion of vector and lexical ranked runs
  • nDCG@10 and MRR@10 scoring over a query set
  • Paired significance tests between two runs

Lacks:

  • Removal of SearchReranker, its rerank flag and weight constants
  • Order wired into Retriever with no new dependency
  • Duplicates the RRF already inside the hybrid step

Proposed design

Problem statement

With the defaults, SearchReranker sorts the RAG hits by its own weighted score. Retriever._rank_results then returns that order, so the RRF order of the hybrid step has no effect. On the 62-query eval set, the weighted score lowers nDCG@10 from 0.468 to 0.386 and MRR@10 from 0.557 to 0.423. The change deletes the weighted reranker and its settings, so the hybrid RRF order becomes the final order until the cross-encoder stage of #4961 comes.

Acceptance criteria

Requirement: Fusion order is the final order

The retriever SHALL return the reciprocal-rank-fusion order of the hybrid step as the final order of the hits.

Scenario: Hybrid query keeps the fused order

  • WHEN a test runs a hybrid query with hybrid=True against a stub search that returns a fixed hit set
  • THEN the returned hits follow the fused order and no weighted-score sort changes it

Requirement: No weighted reranker in the source

The module devops_cli.ai.rag.reranker MUST hold no SearchReranker class and the module devops_cli.config.defaults MUST hold no DEFAULT_RANKER_ constant.

Scenario: The reranker names are absent

  • WHEN a test imports devops_cli.ai.rag.reranker and devops_cli.config.defaults
  • THEN neither module has an attribute SearchReranker or an attribute whose name starts with DEFAULT_RANKER_

Requirement: Retriever takes no rerank flag

Retriever MUST NOT accept a rerank argument and MUST keep its hybrid argument.

Scenario: Retriever refuses rerank

  • WHEN a test builds Retriever with rerank=True
  • THEN the call raises TypeError and a build with hybrid=True and no rerank argument succeeds

Requirement: Documentation names no reranker key

ARCHITECTURE.md and the generated settings reference MUST NOT name a reranker setting.

Scenario: The docs check passes

  • WHEN uv run devops ci --check --only docs runs on the change
  • THEN the check passes and the generated settings reference holds no DEFAULT_RANKER_ key

Existing Tool Considered

The alternatives check of 2026-11-15 in the body of this issue returned none, with no tool. No open, maintained tool or library covers the need, and the check gives its reason and the tool that it considered. RRF already lives in the hybrid step of Retriever, so an outside fusion package would duplicate it. The change deletes code and adds none; the written cost is about 0.12M tokens and 2 hours.

Key questions

  • Which order do the hits take when the weighted score goes?: The hits take the reciprocal-rank-fusion order of the hybrid step. The retriever keeps no weighted sort. A cross-encoder rerank waits for child 7 of feat(ai): track embedding and reranking serving for retrieval #4961. (best practice) [sources: src/devops_cli/ai/rag/retriever.py, src/devops_cli/ai/rag/reranker.py:149]
  • Does the rerank path stay behind a shim?: No. Delet the class, the rerank parameter and the DEFAULT_RANKER_ constants, and keep no shim. The pre-1.0 policy removes a superseded path instead of keeping it behind a flag. (best practice) [sources: docs/adr/0001-github-is-the-roadmap-source.md, docs/adr/0005-review-findings-come-from-tools-not-models.md]
    • Chosen: Delet the path and its settings. ADR 0001 and ADR 0005 remove a superseded path rather than keep it, before 1.0.0.
    • Rejected: Keep a no-op shim. It keeps settings that no code reads and leaves the documentation stale.
  • Which code and tests change?: Retriever imports SearchReranker and builds it, and takes the rerank flag. The test tests/ai/rag/test_embedding_model_compatibility.py uses the class. Remove the import, the construction and the parameter, and update that test. [sources: src/devops_cli/ai/rag/retriever.py, src/devops_cli/ai/rag/reranker.py:149, tests/ai/rag/test_embedding_model_compatibility.py]
  • Which settings become unused and must go?: The DEFAULT_RANKER_ constants of src/devops_cli/config/defaults.py go. Each setting that only the class reads goes with them. The generated settings reference changes to match. [sources: src/devops_cli/config/defaults.py]
  • Which documentation must change?: The RAG text of ARCHITECTURE.md and the generated settings reference change. The docs row of Static Analysis refuses a generated document that is not the output of its generator. Run uv run devops ci --check --only docs. [sources: ARCHITECTURE.md, docs/adr/0004-ci-is-the-authoritative-gate.md, CONTEXT.md]
  • How are the quality gain and the latency verified?: A follow-up issue verifies the quality and the latency. The eval scorer needs the 62-query set of test(ai): a gold set measures retrieval of knowledge base facts #3902, and the p95 needs 7 days of production data. The pull request of this issue cannot check either one. (best practice) [sources: src/devops_cli/telemetry/instruments.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/bug
    scope/ai
    status/new
    value/high
    effort/low
    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: none

    Reason: Searches turned up only general reranking/fusion material — the sentence-transformers CrossEncoder (a cross-encoder reranker) and small hybrid-retrieval demo repositories — none of which provides the change the issue asks for: deleting the in-repo SearchReranker weighted score and letting the existing RRF order of the hybrid step stand. The issue itself states the change deletes code and adds no dependency, and the cross-encoder stage belongs to a later child of #4961, so no external tool or library covers this need.

    Tool: none found

    Lacks:

    Tools considered:

    Searches run:

    • reciprocal rank fusion python library hybrid retrieval RRF, results: 5
    • rank fusion reranker library pypi maintained 2025, results: 5
    • "reciprocal rank fusion" github repository implementation, results: 5
    • llama_index QueryFusionRetriever reciprocal rerank documentation, results: 5
    • cross-encoder reranker sentence-transformers retrieve and rerank, results: 5
    • rrf rank fusion package pypi, results: 5
    • haystack document joiner reciprocal rank fusion, results: 5
    • sentence-transformers CrossEncoder, 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 0cdf3e4 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.

  7. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  8. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 059df0f (see proposed design in issue body).

    Moved to new items: #6287.

  9. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: none, no tool. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • ranx hybrid fusion reciprocal rank fusion retrieval, results: 5
    • reciprocal rank fusion python library rank lists, results: 5
    • ranx pypi reciprocal rank fusion, results: 5
    • pyserini fusion reciprocal rank fusion hybrid retrieval, results: 5
    • ranx fusion rrf documentation rank fusion algorithms, results: 5
    • AmenRa ranx python ranking evaluation fusion library readme, results: 5

    Sources:

  10. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 29, 2026
  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 29, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  13. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:17 UTC

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/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions