← Back to Pull requests

fix: single weighted-RRF fusion entry, one spelling for the rewrite path, README restructured #88

Closed
unknown closed this pull request without merging on Oct 08, 2026 10:39 UTC
View on GitHub
unknown unknown commented on Oct 08, 2026 10:04 UTC
Author

Summary

Closes the two code items in #84 (items 2 and 3), plus the two review findings from #87 that were substantive rather than cosmetic. No capability is added and no benchmark number is introduced.

The theme is that "weighted RRF runs once, with query-aware weights" should be a property the code and the tests both prove, instead of a sentence in a README that the code contradicted.

1 · One fusion entry (#84 item 3)

retrieval/parallel_recall.py fuses with the query-aware per-path weights produced by core/pipeline.py::_build_rrf_weights (regulation → BM25 1.5, visual → CLIP 2.0). Downstream of it, _merge_and_dedup re-scored the already-fused list with a second weighting pass over w_text / w_clip / w_ocr. That pass is removed; _union_dedup replaces it and only collapses duplicate doc_ids — the duplicates ES Fallback appends after fusion — preserving order, scores and object identity.

What the removed pass actually did, verified before changing anything

rrf_fusion() already returns unique documents, RecallResult has no embedding_type, so every result took the same w_text multiplier; the rank term came from insertion order, which made the score monotonically decreasing, so sorting descending preserved the incoming order exactly. Reconstructed and run against a fused-plus-fallback list: the output order was identical to the input.

The pass was therefore order-preserving, not relevance-changing. #87 described it as cancelling the first pass's weighting; that was overstated, and the CHANGELOG entry here says so plainly rather than inheriting the claim. The real defect was a ~48-line pass whose docstring and call-site comment claimed query-aware fusion it never applied, sitting directly downstream of the fusion that does apply it — and any future change that made it non-uniform would have silently reordered a fused list. That is the fragility worth removing.

2 · One spelling for the rewrite recall path (#84 item 2)

The path was rewrite_variants (plural) in the config.json topology key and in qdrant_paths, and rewrite_variant (singular) in the path_results key, the _build_rrf_weights weight key and the RecallResult.source value.

The mismatch was silent: the weight still resolved, because both singular sites agreed with each other. But qdrant_paths never matched the registered key, so a Qdrant failure on the rewrite path could not raise its warning — a permanently unreachable diagnostic. Now one spelling, matching the config topology, everywhere including docs and the exceptions comment.

3 · Regression contracts

tests/test_architecture_contract.py gains seven tests, each of which fails on the pre-change tree:

  • _union_dedup preserves relative order, scores and object identity — the structural guard against a second scoring pass returning.

  • _union_dedup keeps the fused copy over a later duplicate.

  • rrf_fusion is called exactly once per recall request, with the weights the pipeline built, and the post-fusion step leaves the result untouched.

  • core/pipeline.py contains no rrf_score and no _merge_and_dedup.

  • The config topology keys, the registered path_results keys and the weight keys are the same set.

  • The rewrite path is spelled identically in config, weights and result source.

  • The rewrite-path Qdrant warning is reachable (the future raises; the branch must fire).
  • Verified by reverting each fix in isolation: the naming test and the diagnostic test both fail against the singular spelling.

    4 · README restructured

    Five sections a reader arrives with: Problem (why this domain needs RAG), Architecture (offline build and online Q&A, split explicitly), Retrieval Pipeline (the seven online stages, the recall-path table, the single fusion entry with the formula, a design-trade-off table and the four hallucination gates), Evaluation, Production Readiness.

    The trade-off table is the part worth reading: why retrieval over fine-tuning, why hybrid over either single retriever, why rank fusion over score normalization, why two rerank stages, why dynamic rather than fixed recall, why refusal, why layered filtering. Each row carries the cost and the rejected alternative, so the choice is auditable rather than asserted.

    5 · Evaluation: framework ready, execution pending

    The section states the split explicitly and then explains why retrieval metrics are currently not attributable, which is the part that was missing:

  • All 301 golden-set rows lack doc_id / chunk_id / source_id, so relevance falls back to Level-2 normalized exact text. A re-chunk, an OCR variation or a merged passage silently zeroes a match — the measured recall would then reflect the build pipeline's incidental choices rather than retrieval quality.

  • complexity and visual_required are 0/301, so the dynamic-2–4-path and visual breakdowns cannot be produced at all (#86).

  • The framework deliberately does not substitute an LLM judge, an embedding-similarity threshold, fuzzy matching or a hand-written id map to close that gap: those raise recall and are not reproducible, which is shaping the metric instead of the system. Reporting no number is the correct outcome until the ids exist. The fix path is cheap — the offline build already emits doc_id and chunk_id.
  • Measured field coverage, business_type / difficulty distributions and the 262-distinct-passage figure were recomputed from the committed dataset, not copied. No metric value appears anywhere.

    6 · Two evidence corrections from review on #87

    Both were raised by the review bot and were correct:

  • The monolith request path was graded LOCAL_REAL_VALIDATION. The five local validations cover individual mechanisms (Redis session, Redis rate limit, nginx client IP, authenticated ES 8.11, authenticated Prometheus scrape); none is a full-stack run of /api/query, and in that run Qdrant was not exercised and the model stack was blocked. Now REPO_VERIFIED / PENDING with what would close it.

  • The microservice remedy was described as a two-line sys.path addition per service. retrieval-service and generation-service also import monitoring_service.metrics_collector, and no monitoring_service package exists — only the retrieval_service symlink. Both keep failing after that change. The remedy now states the package has to be normalised too.
  • 7 · Production Validation Checklist

    A new subsection under Production Readiness lists every gate between "architecture demo" and "may take real traffic", each linked to its VAL-* entry, all marked not executed. Backed by five entries added to docs/deferred-runtime-validation.md, which previously named these only in prose: real Qdrant (VAL-STORE-001), fail-closed degradation with no rerank weights (VAL-DEGRADE-001 — deterministic, needs no environment, highest value in the repository), whether the second rerank stage helps at all (VAL-RERANK-001, including when the answer is negative), production infrastructure topology (VAL-TOPO-001) and sustained alert evaluation (VAL-ALERT-001).

    Not changed

  • No capability, no new retrieval mode, no new model, no new cache layer.

  • No benchmark number, performance figure, deployment record or customer data.

  • The microservice import fix itself (#84 item 1) is not in this PR — it needs a package rename and is tracked separately; only the overstated remedy text was corrected.

  • retrieval_service symlink untouched.
  • Verification

    python3 -m pytest tests/ -q     2576 passed, 15 skipped
    ruff check .                    All checks passed!
    ruff format --check .           293 files already formatted
    python3 scripts/check_repo_consistency.py   Repository consistency check passed.
    

    Reviewer notes

    1. Is the corrected characterisation of the removed fusion pass right? That it was order-preserving, and the defect was a misleading pass rather than a wrong ranking — the reconstruction is in the commit message and the CHANGELOG.
    2. Do the design-trade-off rows in the new Retrieval Pipeline section match the code, or does any of them claim a benefit this repository cannot support?

    Refs #84. Follow-up to #87 (whose wording for items 2 and 3 this supersedes).

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Xander-Xai Review duration: 35m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #88"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%