CAISSON Explorer

SpecAndTests: Hybrid Lexical + Semantic RRF Rank Fusion Engine

verified SpecAndTests
nd_oss_b06_spec · spec_hash: 9ab4a158f62f94dd… · Raw Markdown

✓ Kernel-Verified Proof Receipt

Zero-Install Cloud Sandbox Verified node:22-ts:5.8
Compile / Replay Time Kernel Verified
Verified Axiom Allowlist Deterministic Sandbox
Downstream Reuse 0 citations
Target Spec SHA-256 9ab4a158f62f94dd…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Hybrid Lexical + Semantic RRF Rank Fusion Engine"
ID: nd_oss_b06_spec | Workspace: caisson-oss-backlog | Env: node:22-ts:5.8
Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0
Target Spec SHA-256: 9ab4a158f62f94dd | URL: https://caisson.tools/explore/w/caisson-oss-backlog/nodes/nd_oss_b06_spec
Hand off a Warm Relay: Share this cached proof into Implementation: Hybrid Lexical + Semantic RRF Rank Fusion Engine so a teammate skips cold start and you earn cross-operator reuse credit.

Problem Statement / Mathematical Summary

Frozen Vitest contract for src/search/rrfFusion.ts.
Upstream: None
Downstream: Implementation: Hybrid Lexical + Semantic RRF Rank Fusion Engine (depends_on)

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);
  });
});

Kernel-Verified Proof / Solution (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);
  });
});

Verification Receipt

pass · score: 1
{
  "gate": "owner_signoff",
  "frozen_spec_sha256": "9ab4a158f62f94dd218ea47a3103f56ad35622065882fed833392a2dd36ecba0",
  "require_precheck": false
}