Skip to main content

weavatrix_search_vector/storage/
mapped_batch.rs

1use super::MappedVectorIndex;
2use crate::error::SearchError;
3use crate::hit::SearchHit;
4use crate::hnsw::SearchPolicy;
5use crate::parallel;
6
7impl MappedVectorIndex {
8    /// Searches mapped queries using bounded standard-library workers.
9    ///
10    /// # Errors
11    ///
12    /// Returns the first query error in input order or a worker-panic error.
13    pub fn search_batch(
14        &self,
15        queries: &[&[f32]],
16        count: usize,
17    ) -> Result<Vec<Vec<SearchHit>>, SearchError> {
18        self.search_batch_with_policy(
19            queries,
20            count,
21            SearchPolicy::new(self.header.config.expansion_query),
22        )
23    }
24
25    /// Searches mapped queries with a shared per-query recall policy.
26    ///
27    /// # Errors
28    ///
29    /// Returns the first query error in input order or a worker-panic error.
30    pub fn search_batch_with_policy(
31        &self,
32        queries: &[&[f32]],
33        count: usize,
34        policy: SearchPolicy,
35    ) -> Result<Vec<Vec<SearchHit>>, SearchError> {
36        let policy = policy.validate()?;
37        parallel::search_batch(queries, self.header.config.query_threads, |query| {
38            self.search_with_policy(query, count, policy)
39        })
40    }
41}