Skip to content

test(longmemeval): MMR diversity rerank flag + replay recording (#1120) - #1127

Merged
ajianaz merged 4 commits into
developfrom
test/1120-mmr-diversity
Aug 27, 2026
Merged

ajianaz merged 4 commits into
developfrom
test/1120-mmr-diversity

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What

  • mmr.py: greedy MMR (Maximal Marginal Relevance) rerank — relevance from rank-based RRF 1/(60+rank), similarity from TF-IDF cosine over candidate session texts (pure stdlib, no model)
  • run_eval.py: --mmr-lambda flag (default OFF / None → no-op), MMR block after session dedup
  • test_mmr.py: 13 unit tests (no-op semantics, diversity behavior, relevance override, cosine sanity, mismatch raises, determinism, big-pool permutation) — all passing

Why

Multi-session questions need several distinct evidence sessions in the top-k; near-duplicate sessions crowd them out. MMR is zero-model post-processing — consistent with the single-model (EmbeddingGemma) decision; no new downloads, no runtime deps. Default OFF preserves baseline for A/B.

Testing

  • python3 test_mmr.py → 13/13 PASS
  • python3 run_eval.py --help → --mmr-lambda present
  • Local smoke A/B (2Q, hybrid, isolated HOME): pending — will post numbers before merge

Comment thread benchmarks/longmemeval/run_eval.py Fixed
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • benchmarks/longmemeval/run_eval.py:463 — recall_and_evaluate returns {"session": {**session_recall, **session_ndcg}, "_retrieved_session_ids": ...} — the key lives at the top level of metrics, but the writer does metrics.pop("_retrieved_session_ids", []) which is also top-level... however the key was placed as a sibling of "session", so metrics["_retrieved_session_ids"] exists and pop works — BUT the key is also merged nowhere into "session"; the actual bug risk: if any code iterates metrics keys expecting only metric names, the underscore key leaks. More importantly, verify: the returned dict is {"session": {...}, "_retrieved_session_ids": [...]} so pop("_retrieved_session_ids") on that dict does retrieve it correctly. The residual issue is that the underscore key pollutes the metrics dict shape for any other consumer of metrics before the pop (e.g. aggregation code that sums metric values across entries would encounter a list value).

Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz force-pushed the test/1120-mmr-diversity branch from 8212f99 to 3c03487 Compare August 27, 2026 05:51
"retrieval_results": {"metrics": metrics},
"retrieval_results": {
"metrics": metrics,
# Post-rerank session order — enables offline replay of
@ajianaz

ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

Re: _retrieved_session_ids pollution finding — verified false positive. The writer pops the key from the same dict object before serialization (metrics.pop("_retrieved_session_ids", []) at run_eval.py:465 precedes json.dumps at :468), so the underscore key never reaches the JSONL. The only consumer of the metrics dict is this single writer; no aggregation code touches it between return and pop (print_metrics.py reads the resulting file, not the in-memory dict).

@ajianaz

ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

A/B Evaluation Result (multisession15, Modal, identical config)

Metric baseline (hybrid) MMR λ=0.7 delta
recall_all@5 0.8956 0.7600 -0.1356
recall_all@10 0.9644 0.9311 -0.0333
ndcg_any@5 0.8364 0.7007 -0.1357
ndcg_any@10 0.8657 0.7776 -0.0881

Per-question R@5: 5/15 degraded (worst -0.500), 0 improved — on multi-session questions, the exact segment MMR targets, diversity-forcing demotes near-duplicate relevant sessions out of top-k.

Decision: --mmr-lambda stays default OFF (as shipped in this PR). The flag + retrieved_session_ids replay recording land as experiment infrastructure; the negative result above is the documented reason not to enable it for LongMemEval-style session recall workloads. A fast50 MMR run adds no decision value given the target segment itself regressed.

Re: review finding _retrieved_session_ids pollution — see comment: verified false positive (key is popped from the same dict object before serialization; no other consumer).

@ajianaz ajianaz changed the title bench(longmemeval): MMR diversity rerank (#1120) test(longmemeval): MMR diversity rerank flag + replay recording (#1120) Aug 27, 2026
@ajianaz
ajianaz merged commit ac951f7 into develop Aug 27, 2026
17 of 19 checks passed
@ajianaz
ajianaz deleted the test/1120-mmr-diversity branch August 27, 2026 07:15
ajianaz added a commit that referenced this pull request Sep 6, 2026