Skip to content

feat(arigraph): RRF fusion primitive (D-GR-2a) — the retrieval keystone#724

Merged
AdaWorldAPI merged 3 commits into
mainfrom
claude/happy-hamilton-0azlw4
Jul 18, 2026
Merged

feat(arigraph): RRF fusion primitive (D-GR-2a) — the retrieval keystone#724
AdaWorldAPI merged 3 commits into
mainfrom
claude/happy-hamilton-0azlw4

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

What

Adds reciprocal_rank_fusion — the retrieval keystone named in the GraphRAG representations inventory (#723, the SAP "Practical GraphRAG" reader's headline gap). Every ranked leg already exists (Bm25Index::rank, PersonalizedPageRank::ranked, CAM-PQ), but nothing fused them; the G0 harness compared vector-vs-graph by rank position instead of combining them.

The primitive

arigraph/rrf.rs:

pub fn reciprocal_rank_fusion(ranked_lists: &[&[ScoredId]], k: f64) -> Vec<ScoredId>
pub const DEFAULT_RRF_K: f64 = 60.0;

Reciprocal Rank Fusion (Cormack, Clarke & Büttcher, SIGIR 2009): each id scored by Σ_lists 1/(k + rank) (1-based). It fuses by rank position, never by the source scores — which is exactly why it combines lists whose scores are not commensurable: BM25 (tf-idf f64), PPR (unit-sum probability), CAM-PQ (i8 distance) share no scale, yet their rank orders fuse cleanly.

  • Deterministic (BTreeMap id-ascending + stable score-descending sort).
  • Shallowest depth wins across occurrences (strongest provenance).
  • Returns the contract ScoredId — the canonical cross-method result type.
  • Re-exported from arigraph/mod.rs.

Scope

Pure, reversible capability landed ahead of G0 — same pattern as Bm25Index / PersonalizedPageRank / Communities. It computes a fused ranking and reads no carrier state. Wiring it into OsintRetriever::retrieve (so the retriever actually fuses its legs) stays gated on the G0 load-bearing verdict (plan §5, STATUS_BOARD D-GR-2).

Tests

  • 7 unit tests: consensus-near-top beats lone-top-1, fuses incommensurable scores by rank only, shallowest-depth wins, rank-position dominance within one list, smaller-k sharpens the top-rank advantage, empty-input safety, determinism.
  • 1 doctest.
  • cargo clippy -p lance-graph --lib clean (the 8 warnings are pre-existing blasgraph/ndarray_bridge.rs SIMD dead-code).

Board hygiene (same commit)

STATUS_BOARD D-GR-2a row + AGENT_LOG entry.

🤖 Generated with Claude Code

https://claude.ai/code/session_016b33swuXE23hKtqxsHu9p1


Generated by Claude Code

Reciprocal Rank Fusion (Cormack, Clarke & Büttcher 2009): fuse N ranked
lists into one ranking by Σ 1/(k+rank), k=60. Named as the D-GR-2 retrieval
keystone in the representations inventory (#723) — every ranked leg exists
(Bm25Index::rank, PersonalizedPageRank::ranked, CAM-PQ) but nothing fused
them.

- `arigraph/rrf.rs`: `reciprocal_rank_fusion(&[&[ScoredId]], k) -> Vec<ScoredId>`
  + `DEFAULT_RRF_K = 60`. Fuses by RANK, so the per-list scores need not be
  commensurable (the reason it combines BM25 f64 / PPR probability / CAM-PQ i8).
  Deterministic (BTreeMap id-asc + stable score-desc sort); shallowest depth
  wins; returns the contract `ScoredId`.
- Re-exported from `arigraph/mod.rs`.

Pure, reversible capability landed ahead of G0 (like Bm25Index /
PersonalizedPageRank / Communities). The WIRING into OsintRetriever::retrieve
stays gated on the G0 load-bearing verdict.

Tests: 7 unit + 1 doctest green; clippy clean (`-p lance-graph --lib`).
Board: STATUS_BOARD D-GR-2a + AGENT_LOG.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016b33swuXE23hKtqxsHu9p1
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_d4416c62-890b-4e5c-9725-64786b40cc27)

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AdaWorldAPI, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c087563c-1230-4eec-9577-16e139dd5697

📥 Commits

Reviewing files that changed from the base of the PR and between 9c62289 and 595a607.

📒 Files selected for processing (4)
  • .claude/board/AGENT_LOG.md
  • .claude/board/STATUS_BOARD.md
  • crates/lance-graph/src/graph/arigraph/mod.rs
  • crates/lance-graph/src/graph/arigraph/rrf.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

CI `format` check: rustfmt wants the `(0..10).map(...).collect()` in the
smaller_k test wrapped across lines. No logic change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016b33swuXE23hKtqxsHu9p1
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review July 18, 2026 19:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c87c04ce4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +70 to +74
for (pos, item) in list.iter().enumerate() {
let rank = pos as f64 + 1.0; // 1-based
let entry = acc.entry(item.id.as_str()).or_insert((0.0, u8::MAX));
entry.0 += 1.0 / (k + rank);
entry.1 = entry.1.min(item.depth);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate ids within each RRF leg

When a source leg emits the same ScoredId.id more than once in a single ranked list (for example, SPO/neighbour hits can surface multiple relations to the same entity before caller-side dedup), this loop credits every occurrence with another 1/(k + rank) contribution as if it came from an independent ranking system. RRF should give each system/list at most one vote per id, using the best/first rank; otherwise duplicates from one leg can swamp consensus across the other fused legs.

Useful? React with 👍 / 👎.

Codex P2 review on #724: the accumulation loop credited every occurrence
of an id within a single ranked list with another 1/(k+rank). A leg that
surfaces the same entity more than once (several relations to one node,
before caller-side dedup) would double-count and swamp consensus across the
other fused legs.

Fix: per-list dedup — each list votes once per id at its best (first) rank.
Depth still folds the shallowest across all occurrences. +2 regression tests
(duplicate_id_in_one_leg_votes_once, duplicate_id_still_folds_shallowest_depth).

9/9 rrf lib tests + doctest green; fmt + clippy clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016b33swuXE23hKtqxsHu9p1
@AdaWorldAPI
AdaWorldAPI merged commit eff605a into main Jul 18, 2026
5 checks passed
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