Skip to content

fix: preserve retrieval order when MMR diversity is zero - #139

Open
March-7 wants to merge 1 commit into
pathwaycom:mainfrom
March-7:codex/round93-mmr-zero-preserve-order
Open

March-7 wants to merge 1 commit into
pathwaycom:mainfrom
March-7:codex/round93-mmr-zero-preserve-order

Conversation

@March-7

@March-7 March-7 commented Oct 22, 2026

Copy link
Copy Markdown

Scope

  • Small change that can be reviewed in one short sitting
  • Substantial change approved by a maintainer (link below)

Related issues and approval

No existing issue found for this behavior. This is a small, self-contained fix under the direct-PR path in CONTRIBUTING.md.

Problem and resulting behavior

With query decomposition and rag.mmr.diversity: 0, MMR re-sorts round-robin retrieval results by their original per-query scores. Those scores are not comparable: a later sub-query hit can replace the first result even though zero diversity promises plain top-k.

Return the incoming leading hits unchanged at zero diversity. Positive-diversity scoring and selection remain unchanged.

Approach and review guidance

Add the zero-diversity fast path and regressions for non-monotonic scores, the DuckDB retrieval endpoint with decomposition, full-pool behavior, and positive-diversity relevance/novelty controls.

AI assistance was used to investigate, implement, and validate this change. The endpoint tests use synthetic vectors and deterministic model responses; database queries and retrieval/ranking code run normally. No real model-quality improvement is claimed.

Verification

  • Identical new regression selection: base 4 failed / 4 passed; patched 8 passed (29 deselected in both).
  • python -m pytest tests/test_rag_quality.py tests/test_documents.py tests/test_hybrid.py -q: 100 passed on the patch.
  • Independent local HTTP/SDK + DuckDB replay: both affected decomposition cases recover the expected order; two ordinary-query controls also pass.
  • python -m ruff check serviette tests: passed with Ruff 0.16.10, within the project's dev pin.
  • git diff --check: passed.

A broader baseline test selection had 112 passes and 3 import failures because LiteLLM is not installed. Full package, engine-backed indexing, external-model, Docker/backend integration, and multi-version tests were not run.

Checklist

  • I have read CONTRIBUTING.md.
  • For substantial work, I linked maintainer approval and explained the approach.
  • I followed the project's code style and reported relevant verification results.
  • I updated tests and documentation where needed, or explained why no updates are needed.
  • I described any breaking changes and migration steps, if applicable.

No configuration or API change; the existing zero-diversity contract is restored. No documentation update is needed for the behavior already documented in MmrConfig.

@CLAassistant

CLAassistant commented Oct 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants