ringdb/query.rs
1use std::time::Duration;
2
3/// A ring query: find all vectors whose Euclidean distance to `query`
4/// lies within `[d - lambda, d + lambda]`.
5///
6/// Internally, ringdb uses squared L2 distances to avoid computing square
7/// roots. The ring bounds become:
8///
9/// ```text
10/// lower_sq = max(0, d - lambda)²
11/// upper_sq = (d + lambda)²
12/// ```
13pub struct RingQuery<'a> {
14 /// The query vector. Must have length equal to `RingDb::dims()`.
15 pub query: &'a [f32],
16 /// Target distance (centre of the ring).
17 pub d: f32,
18 /// Half-width of the ring.
19 pub lambda: f32,
20}
21
22/// Result of a ring query.
23pub struct QueryResult {
24 /// IDs of all vectors whose distance to the query falls within
25 /// `[d - lambda, d + lambda]`. IDs correspond to insertion order
26 /// (first inserted vector has ID 0).
27 pub ids: Vec<u32>,
28 /// Name of the backend that executed the query (e.g. `"cpu"`, `"wgpu"`, `"cuda"`).
29 pub backend_used: &'static str,
30 /// Wall-clock time for the query (excluding dataset upload).
31 pub elapsed: Duration,
32}