---
entity: caisson_node
workspace_id: ws_caisson_oss_backlog
workspace_slug: caisson-oss-backlog
node_id: nd_oss_b06_rrf_merger
node_type: Implementation
status: open
environment_version: node:22-ts:5.8
environment_lock_hash: 902c6c679663f6d8cd1f4a7a11f7c66b06f7ca39be1d1b5cf5cae8b9a5af2728
spec_hash: 9ab4a158f62f94dd218ea47a3103f56ad35622065882fed833392a2dd36ecba0
---

# Implementation: Hybrid Lexical + Semantic RRF Rank Fusion Engine (`nd_oss_b06_rrf_merger`)

Implement src/search/rrfFusion.ts exporting fuseRankedLists(lexical, semantic, opts) with Reciprocal Rank Fusion and superseded dead-end demotion.

## Frozen Target Specification
```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);
  });
});
```

## Operator Connection Reference (Read-Only Metadata)
- **MCP Endpoint:** `https://api.caisson.tools/mcp` (Streamable HTTP, Bearer token issued by workspace operator)
- **Workspace ID:** `ws_caisson_oss_backlog`
- **Verification Policy:** No local toolchain required: server-side verification handles compilation and replay.
- **Read-Only Discovery:** `https://caisson.tools/llms.txt`
