M2: RETRIEVE query pipeline with 5-stage execution (candidate → filter → score → diversify → limit),
usearch HNSW vector index, bitmap/range/universe filters, ranking profiles with signal scoring,
MMR diversity enforcement, and m2_uat integration tests.
M3: Entity system with typed metadata, relationship graph (follows/blocks/interactions),
creator entities, session tracking, and m3_uat integration tests.
M4: Advanced ranking with builtin functions (freshness, trending, controversy, wilson),
ranking executor with explain mode, query executor integration, benchmarks for
query/ranking/vector/filters/diversity, and m4_uat integration tests.
Includes: 9 new blog posts, marketing site updates, updated roadmap, and updated vision doc.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.6 KiB
Rust
117 lines
3.6 KiB
Rust
#![allow(clippy::unwrap_used)]
|
|
|
|
//! Criterion benchmarks for the diversity enforcement selector.
|
|
//!
|
|
//! Measures greedy selection across five scenarios:
|
|
//! - `max_per_creator` only (common case)
|
|
//! - `format_mix` only
|
|
//! - Both constraints combined
|
|
//! - Worst-case relaxation (all stages triggered)
|
|
//! - No constraints (fast path baseline)
|
|
|
|
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
|
use tidaldb::ranking::{DiversityConstraints, DiversitySelector, ScoredCandidate};
|
|
use tidaldb::schema::EntityId;
|
|
|
|
fn make_200_candidates(n_creators: usize) -> Vec<ScoredCandidate> {
|
|
(0..200_usize)
|
|
.map(|i| ScoredCandidate {
|
|
entity_id: EntityId::new(i as u64 + 1),
|
|
#[allow(clippy::cast_precision_loss)]
|
|
score: (200 - i) as f64 / 200.0,
|
|
signal_snapshot: vec![],
|
|
creator_id: Some(EntityId::new((i % n_creators) as u64 + 1)),
|
|
format: Some(if i % 3 == 0 {
|
|
"video".into()
|
|
} else {
|
|
"audio".into()
|
|
}),
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn bench_diversity_200_max_per_creator_2(c: &mut Criterion) {
|
|
let candidates = make_200_candidates(50);
|
|
let constraints = DiversityConstraints::new().max_per_creator(2);
|
|
c.bench_function("diversity_200_max_per_creator_2", |b| {
|
|
b.iter(|| {
|
|
DiversitySelector::select(
|
|
black_box(&candidates),
|
|
black_box(&constraints),
|
|
black_box(100),
|
|
)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn bench_diversity_200_format_mix(c: &mut Criterion) {
|
|
let candidates = make_200_candidates(200);
|
|
let constraints = DiversityConstraints::new().format_mix(0.6);
|
|
c.bench_function("diversity_200_format_mix", |b| {
|
|
b.iter(|| {
|
|
DiversitySelector::select(
|
|
black_box(&candidates),
|
|
black_box(&constraints),
|
|
black_box(100),
|
|
)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn bench_diversity_200_combined(c: &mut Criterion) {
|
|
let candidates = make_200_candidates(50);
|
|
let constraints = DiversityConstraints::new()
|
|
.max_per_creator(2)
|
|
.format_mix(0.6);
|
|
c.bench_function("diversity_200_combined", |b| {
|
|
b.iter(|| {
|
|
DiversitySelector::select(
|
|
black_box(&candidates),
|
|
black_box(&constraints),
|
|
black_box(100),
|
|
)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn bench_diversity_200_worst_case_relaxation(c: &mut Criterion) {
|
|
// All same creator -- unsatisfiable constraints trigger all relaxation stages.
|
|
let candidates = make_200_candidates(1);
|
|
let constraints = DiversityConstraints::new()
|
|
.max_per_creator(1)
|
|
.format_mix(0.4);
|
|
c.bench_function("diversity_200_worst_case_relaxation", |b| {
|
|
b.iter(|| {
|
|
DiversitySelector::select(
|
|
black_box(&candidates),
|
|
black_box(&constraints),
|
|
black_box(100),
|
|
)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn bench_diversity_200_no_constraints(c: &mut Criterion) {
|
|
let candidates = make_200_candidates(200);
|
|
let constraints = DiversityConstraints::new();
|
|
c.bench_function("diversity_200_no_constraints", |b| {
|
|
b.iter(|| {
|
|
DiversitySelector::select(
|
|
black_box(&candidates),
|
|
black_box(&constraints),
|
|
black_box(100),
|
|
)
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
bench_diversity_200_max_per_creator_2,
|
|
bench_diversity_200_format_mix,
|
|
bench_diversity_200_combined,
|
|
bench_diversity_200_worst_case_relaxation,
|
|
bench_diversity_200_no_constraints,
|
|
);
|
|
criterion_main!(benches);
|