Skip to main content

bb_runtime/roles/
index.rs

1//! `IndexRuntime` - role trait for vector-index implementations.
2//!
3//! Per `docs/ROLES.md` §6. The trait carries the universal pair
4//! (`atomic_opset` + `dispatch_atomic`); the engine routes through
5//! `dispatch_atomic` and never invokes Shape-1 role methods at
6//! runtime. Author Contract impls (`crate::contracts::Index`)
7//! define the user-facing surface; `#[derive(bb::Index)]` emits the
8//! bridge into `IndexRuntime::dispatch_atomic`.
9//!
10//! The opset declares four ops: `Add`, `Search`, `Remove`, `Train`.
11//! `Train` carries the optional calibration pass; impls that skip
12//! training keep the default `Contract::train` no-op and the derive
13//! routes the op through `dispatch_atomic` like any other arm.
14
15use crate::atomic::{AtomicOpsetDecl, DispatchResult};
16use crate::runtime::RuntimeResourceRef;
17use crate::slot_value::SlotValue;
18
19/// Role trait for vector-index implementations.
20pub trait IndexRuntime: Send + Sync {
21    /// Index-impl-specific error type.
22    type Error: std::error::Error + Send + Sync + 'static;
23
24    /// Atomic-op opset this impl owns.
25    fn atomic_opset(&self) -> AtomicOpsetDecl;
26
27    /// Rust-dispatch entry point for atomic ops.
28    fn dispatch_atomic(
29        &mut self,
30        op_type: &str,
31        inputs: &[(&str, &dyn SlotValue)],
32        ctx: &mut RuntimeResourceRef<'_>,
33    ) -> Result<DispatchResult, Self::Error>;
34}