tidaldb/tidal/benches/fusion.rs
jordan 192c473f55 feat: complete Milestone 5 — full-text search, RRF fusion, and creator search
- M5p1: BM25 text indexing via Tantivy with background syncer (0.26ms @ 10K docs)
- M5p2: RRF fusion layer combining BM25 + ANN scores (46µs @ 1K candidates)
- M5p3: unified Search query API (8-stage pipeline, BM25 + vector + ranking)
- M5p4: creator text + vector indexing and creator search executor (< 20ms @ 200 creators)
- Refactor db/mod.rs into focused sub-modules (creators, items, sessions, signals, etc.)
- Decompose monolithic files into directory modules (query/executor, ranking/diversity, etc.)
- Split brute.rs → brute/mod.rs + brute/tests.rs; extract search executor helpers
- Add benches: fusion, search, session, text_index
- Add M5 UAT test suites (m5_uat, m5_search, m5p4_creator_search, text_index)
- Update blog posts, roadmap, content strategy, and M5 planning docs
- Add tmp/ and .claude/worktrees/ to .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 23:53:16 -07:00

73 lines
1.8 KiB
Rust

#![allow(clippy::unwrap_used)]
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use tidaldb::query::{HybridFusion, RetrievalMode, route_results};
use tidaldb::schema::EntityId;
fn make_bm25(n: u64) -> Vec<(EntityId, f32)> {
(0..n).map(|i| (EntityId::new(i), (n - i) as f32)).collect()
}
fn make_ann(n: u64) -> Vec<(EntityId, f32)> {
(500..500 + n)
.enumerate()
.map(|(i, id)| (EntityId::new(id), i as f32 * 0.001))
.collect()
}
fn bench_rrf_fuse_1k(c: &mut Criterion) {
let bm25 = make_bm25(1_000);
let ann = make_ann(1_000);
let fusion = HybridFusion::new();
c.bench_function("rrf_fuse_1k_per_list", |b| {
b.iter(|| {
let results = fusion.fuse(black_box(&bm25), black_box(&ann));
black_box(results)
});
});
}
fn bench_route_hybrid(c: &mut Criterion) {
let bm25 = make_bm25(1_000);
let ann = make_ann(1_000);
let fusion = HybridFusion::new();
c.bench_function("route_hybrid_1k", |b| {
b.iter(|| {
let r = route_results(
black_box(RetrievalMode::Hybrid),
black_box(&bm25),
black_box(&ann),
black_box(&fusion),
);
black_box(r)
});
});
}
fn bench_route_text_only(c: &mut Criterion) {
let bm25 = make_bm25(1_000);
let fusion = HybridFusion::new();
c.bench_function("route_text_only_1k", |b| {
b.iter(|| {
let r = route_results(
black_box(RetrievalMode::TextOnly),
black_box(&bm25),
&[],
black_box(&fusion),
);
black_box(r)
});
});
}
criterion_group!(
fusion_benches,
bench_rrf_fuse_1k,
bench_route_hybrid,
bench_route_text_only
);
criterion_main!(fusion_benches);