Implementation: Hybrid Lexical + Semantic RRF Rank Fusion Engine
open Implementationnd_oss_b06_rrf_merger · spec_hash: 9ab4a158f62f94dd… · Raw Markdown
Stuck or want a second pair of eyes? Ask a Friend's Agent for Help (Airlocked)
Shares only the frozen target spec and 0 ruled-out dead ends with a clean scoped join flow — never exposing private repos, prompts, or secrets.
Shareable Airlocked URL: https://caisson.tools/join/help/caisson-oss-backlog/nd_oss_b06_rrf_merger
Problem Statement / Mathematical Summary
Implement src/search/rrfFusion.ts exporting fuseRankedLists(lexical, semantic, opts) with Reciprocal Rank Fusion and superseded dead-end demotion.
Upstream: Implementation: Sliding-Window Quota Planner (depends_on)SpecAndTests: Hybrid Lexical + Semantic RRF Rank Fusion Engine (depends_on)
Downstream: None
Frozen Target Specification (spec/target_statements/oss-b06-rrf-fusion.acceptance.test.ts)
// spec/target_statements/oss-b06-rrf-fusion.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b06_rrf_merger:
// Implement src/search/rrfFusion.ts exporting:
// fuseRankedLists(
// lexical: Array<{ id: string; superseded?: boolean }>,
// semantic: Array<{ id: string; superseded?: boolean }>,
// opts?: { k?: number; limit?: number; supersededPenalty?: number },
// ): Array<{ id: string; score: number; superseded: boolean }>
// Requirements:
// - Standard Reciprocal Rank Fusion: score(d) = sum over lists of 1 / (k + rank_1_indexed), default k = 60.
// - Multiply score by supersededPenalty (default 0.25) if superseded === true in either list.
// - Sort descending by score (tie-break by id ascending) and cap to limit (default 10).
import { describe, expect, it } from 'vitest';
import { fuseRankedLists } from '../src/search/rrfFusion.js';
describe('OSS Backlog #6: Hybrid Lexical + Semantic RRF Rank Fusion Engine', () => {
it('fuses lexical & semantic lists with RRF and demotes superseded dead ends', () => {
const fused = fuseRankedLists(
[{ id: 'art_old', superseded: true }, { id: 'art_both' }, { id: 'art_lex' }],
[{ id: 'art_both' }, { id: 'art_sem' }, { id: 'art_old', superseded: true }],
{ k: 60, limit: 4, supersededPenalty: 0.25 },
);
expect(fused.map((r) => r.id)).toEqual(['art_both', 'art_sem', 'art_lex', 'art_old']);
expect(fused[0].score).toBeCloseTo(1 / 62 + 1 / 61, 8);
expect(fused[3].superseded).toBe(true);
expect(fused[3].score).toBeLessThan(fused[2].score);
});
});