Execute a filtered k-NN query. # Parameters - `query` — query vector. - `predicate_signature` — optional stable predicate; if present and a subindex exists for it, that subindex is used directly. - `allowed` — bitmap of allowed IDs for the NaviX fallback path. Ignored when a subindex is matched. - `k` — number of nearest neighbours to return. - `ef_se
(
&self,
query: &[f32],
predicate_signature: Option<&PredicateSignature>,
allowed: RoaringBitmap,
k: usize,
ef_search: usize,
metric: DistanceMe
| 41 | /// |
| 42 | /// Up to `k` nearest-neighbour results, sorted by ascending distance. |
| 43 | pub fn route( |
| 44 | &self, |
| 45 | query: &[f32], |
| 46 | predicate_signature: Option<&PredicateSignature>, |
| 47 | allowed: RoaringBitmap, |
| 48 | k: usize, |
| 49 | ef_search: usize, |
| 50 | metric: DistanceMetric, |
| 51 | ) -> Vec<SearchResult> { |
| 52 | // Fast path: subindex hit. |
| 53 | if let Some(sig) = predicate_signature |
| 54 | && let Some(subindex) = self.collection.get(sig) |
| 55 | { |
| 56 | return subindex.search(query, k, ef_search); |
| 57 | } |
| 58 | |
| 59 | // Slow path: NaviX adaptive-local filtered search on the global index. |
| 60 | let opts = NavixSearchOptions { |
| 61 | k, |
| 62 | ef_search, |
| 63 | allowed, |
| 64 | brute_force_threshold: 0.001, |
| 65 | }; |
| 66 | navix_search(self.fallback, query, &opts, metric) |
| 67 | .into_iter() |
| 68 | .map(|r| SearchResult { |
| 69 | id: r.id, |
| 70 | distance: r.distance, |
| 71 | }) |
| 72 | .collect() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #[cfg(test)] |