langchain_rust/vectorstore/
options.rs

1use std::sync::Arc;
2
3use serde_json::Value;
4
5use crate::embedding::embedder_trait::Embedder;
6
7/// The `VecStoreOptions` struct is responsible for determining options when
8/// interacting with a Vector Store. The options include `name_space`, `score_threshold`,
9/// `filters`, and `embedder`.
10///
11/// # Usage
12/// ```rust,ignore
13/// let options = VecStoreOptions::new()
14///     .with_name_space("my_custom_namespace")
15///     .with_score_threshold(0.5)
16///     .with_filters(json!({"genre": "Sci-Fi"}))
17///     .with_embedder(my_embedder);
18/// ```
19pub struct VecStoreOptions {
20    pub name_space: Option<String>,
21    pub score_threshold: Option<f32>,
22    pub filters: Option<Value>,
23    pub embedder: Option<Arc<dyn Embedder>>,
24}
25
26impl Default for VecStoreOptions {
27    fn default() -> Self {
28        Self::new()
29    }
30}
31
32impl VecStoreOptions {
33    pub fn new() -> Self {
34        VecStoreOptions {
35            name_space: None,
36            score_threshold: None,
37            filters: None,
38            embedder: None,
39        }
40    }
41
42    pub fn with_name_space<S: Into<String>>(mut self, name_space: S) -> Self {
43        self.name_space = Some(name_space.into());
44        self
45    }
46
47    pub fn with_score_threshold(mut self, score_threshold: f32) -> Self {
48        self.score_threshold = Some(score_threshold);
49        self
50    }
51
52    pub fn with_filters(mut self, filters: Value) -> Self {
53        self.filters = Some(filters);
54        self
55    }
56
57    pub fn with_embedder<E: Embedder + 'static>(mut self, embedder: E) -> Self {
58        self.embedder = Some(Arc::new(embedder));
59        self
60    }
61}