Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

6.3 KB
Raw Blame

ADR-083 β€” Joint Rerank Re-Grid (Conditional Defaults for Rerank Path)

Status: Accepted β€” Implemented in ruflo 3.10.23 Date: 2026-05-30 Tracking: continuation of self-learning hardening cluster (ADR-077 β†’ 078 β†’ 079 β†’ 080 β†’ 081 β†’ 082 β†’ 083) Related: ADR-082 (single-axis grid-search)

Context

ADR-082 grid-searched the hybrid (non-rerank) hyperparameter space against the ADR-081 labelled corpus and shipped Ξ±=0.5, sw=2, mmr=0.7 β€” pushing hybrid nDCG@3 from 0.900 to 0.963. The rerank path was left at hw=0.5/cw=0.5 because the original rerank grid had been tested against the OLD Ξ±=0.6/sw=3.0 baseline; with Ξ±/sw shifting underneath, the joint optimum needed measuring.

ADR-082 flagged this explicitly: "Rerank's trade-off: top-1/MRR/P3 up, nDCG@3/top-3 marginally down. Net: positive but not unambiguous. A joint re-grid (including hybridWeight/ceWeight Γ— new Ξ±/sw) is tracked."

This is that re-grid.

Decision

Extended scripts/grid-search-retrieval.mjs with a joint rerank sweep:

  • hybridWeight Γ— ceWeight ∈ {(0.2,0.8), (0.3,0.7), (0.4,0.6), (0.5,0.5), (0.6,0.4), (0.7,0.3), (0.8,0.2)}
  • alpha ∈ {0.3, 0.5} (for the underlying hybrid stage when rerank is on)
  • subjectWeight ∈ {2.0, 3.0}

7 Γ— 2 Γ— 2 = 28 rerank configs, ~25 min wall-clock with the cross-encoder.

Key finding

The rerank path wants different hybrid sub-params than the non-rerank path:

Path Best Ξ± Best sw Best mmr Best hw/cw nDCG@3
Non-rerank (hybrid only) 0.5 2.0 0.7 β€” 0.963
Rerank 0.5 3.0 0.7 hw=0.7 cw=0.3 0.963

This makes intuitive sense: when the cross-encoder is doing the semantic understanding downstream, the hybrid stage can be more keyword-focused (higher subject weight). When hybrid is the final stage, lower subject weight gives the body tokens room to contribute relevance signal.

Implementation: subjectWeight default is now conditional on useRerank (3.0 if reranking, 2.0 otherwise). Explicit subjectWeight param still overrides.

New defaults

Parameter Non-rerank Rerank Change vs 3.10.22
alpha 0.5 0.5 unchanged
subjectWeight 2.0 3.0 rerank +1.0 (conditional default)
mmrLambda 0.7 0.7 unchanged
hybridWeight β€” 0.7 rerank: 0.5 β†’ 0.7
ceWeight β€” 0.3 rerank: 0.5 β†’ 0.3

Measured proof (N=385, 10 queries, labelled metric)

Rerank path:

Metric 3.10.22 (old joint defaults) 3.10.23 (ADR-083) Ξ”
Label top-1 hit rate 90% 90% tied
Label top-3 hit rate 90% 100% +10pp
Label MRR@3 0.925 0.950 +0.025
Label precision@3 0.700 0.700 tied
Label nDCG@3 0.900 0.963 +0.063 (+7%)
Label nDCG@5 0.904 0.944 +0.040

Hybrid (non-rerank) path: unchanged from 3.10.22 (nDCG@3 = 0.963).

Cumulative SOTA push (3.10.17 β†’ 3.10.23)

Metric (labelled) 3.10.17 cosine 3.10.19 hybrid 3.10.20 +rerank 3.10.22 3.10.23
Hybrid nDCG@3 0.000 0.900 0.900 0.963 0.963
Rerank nDCG@3 β€” β€” 0.913 0.900 0.963
Hybrid top-3 0% 90% 90% 100% 100%
Rerank top-3 β€” β€” 100% 90% 100%
Rerank precision@3 β€” β€” 0.667 0.700 0.700

Both retrieval paths now hit nDCG@3 = 0.963 on this corpus. The choice between them is now purely cost vs richness:

  • Hybrid (39 ms/query) β€” same nDCG, leaner top-3 (P3=0.533), use for hot paths
  • Rerank (1000 ms/query) β€” same nDCG, denser top-3 (P3=0.700), use for richness-first paths

Joint grid top-5 by nDCG@3 (full ranking)

Rank Config top-1 top-3 nDCG P3 MRR
1 hybrid Ξ±=0.5 sw=2 mmr=0.7 90% 100% 0.963 0.533 0.950
1 rerank hw=0.7 cw=0.3 Ξ±=0.5 sw=3 90% 100% 0.963 0.700 0.950
1 rerank hw=0.8 cw=0.2 Ξ±=0.3 sw=3 90% 100% 0.963 0.767 0.950
4 hybrid Ξ±=0.5 sw=3 mmr=0.7 90% 100% 0.955 0.533 0.950
4 rerank hw=0.8 cw=0.2 Ξ±=0.5 sw=3 90% 100% 0.955 0.700 0.950

Three configs tied at the corpus ceiling. Picked hw=0.7 cw=0.3 over hw=0.8 cw=0.2 because the latter underweights the cross-encoder's contribution (cw=0.2 leaves the CE doing almost nothing).

Reusable infrastructure shipped

  • scripts/grid-search-retrieval.mjs β€” extended with joint rerank sweep (28 configs across hw/cw Γ— Ξ± Γ— sw). Re-runnable on any corpus.
  • Conditional default logic in src/mcp-tools/neural-tools.ts β€” subjectWeight default depends on useRerank.
  • Run JSON at docs/benchmarks/runs/grid-search-retrieval-latest.json with the full 48-config matrix.

Honest limits

  • N=10 queries still β€” three configs tied at 0.963 are likely indistinguishable within noise.
  • Cross-repo generalisation pending β€” all numbers in ADRs 077-083 are on the ruflo corpus. The real SOTA test is "does this hold up on a different repo's history?" β€” pretrain on agentdb / agentic-flow, run a similar labelled bench, see if nDCG@3 stays near 0.96. Tracked for the next iteration.
  • Conditional defaults add complexity β€” callers passing explicit subjectWeight get consistent behaviour, but callers relying on defaults see different values based on rerank flag. This is documented in the schema but is a minor surprise.

Deliberately NOT in this round

  • Cross-repo generalisation test β€” biggest pending validation; next loop iteration.
  • Pure-precision configs (hw=0.4/cw=0.6 Ξ±=0.3 sw=3 hit P3=0.800 with nDCG=0.900) β€” would be the right opt-in for "richer top-K" but adds yet another config option. Skipping.
  • Larger cross-encoder (L-12 vs L-6) β€” corpus is already near ceiling; bigger model unlikely to help on N=10.

Verification

git clone https://github.com/ruvnet/ruflo && cd ruflo
npm install && ( cd v3/@claude-flow/cli && npx tsc )
node v3/@claude-flow/cli/scripts/pretrain-from-github.mjs

# Joint grid (~25 min)
cd v3/@claude-flow/cli && node scripts/grid-search-retrieval.mjs

# Verify new defaults
BENCH_NO_WRITE=1 node scripts/benchmark-pretrained-retrieval.mjs              # hybrid β†’ nDCG@3 0.963
RERANK=1 BENCH_NO_WRITE=1 node scripts/benchmark-pretrained-retrieval.mjs     # rerank β†’ nDCG@3 0.963 (was 0.900)