pub struct InMemoryVectorStore<D>where
D: Serialize,{ /* private fields */ }Expand description
InMemoryVectorStore is a simple in-memory vector store that stores embeddings in-memory using a HashMap.
Implementations§
Source§impl<D> InMemoryVectorStore<D>
impl<D> InMemoryVectorStore<D>
Sourcepub fn builder() -> InMemoryVectorStoreBuilder<D>
pub fn builder() -> InMemoryVectorStoreBuilder<D>
Create a new builder for configuring an InMemoryVectorStore.
§Examples
use rig_core::vector_store::InMemoryVectorStore;
let store = InMemoryVectorStore::<String>::builder()
.with_lsh()
.documents(documents)
.build();Sourcepub fn from_documents(
documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>,
) -> InMemoryVectorStore<D>
pub fn from_documents( documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>, ) -> InMemoryVectorStore<D>
Create a new InMemoryVectorStore from documents and their corresponding embeddings.
Ids are automatically generated have will have the form "doc{n}" where n
is the index of the document.
Uses BruteForce index strategy by default. For custom index strategies, use InMemoryVectorStore::builder.
Sourcepub fn from_documents_with_ids(
documents: impl IntoIterator<Item = (impl ToString, D, OneOrMany<Embedding>)>,
) -> InMemoryVectorStore<D>
pub fn from_documents_with_ids( documents: impl IntoIterator<Item = (impl ToString, D, OneOrMany<Embedding>)>, ) -> InMemoryVectorStore<D>
Create a new InMemoryVectorStore from documents and their corresponding embeddings with ids.
Uses BruteForce index strategy by default. For custom index strategies, use InMemoryVectorStore::builder.
Sourcepub fn from_documents_with_id_f(
documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>,
f: fn(&D) -> String,
) -> InMemoryVectorStore<D>
pub fn from_documents_with_id_f( documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>, f: fn(&D) -> String, ) -> InMemoryVectorStore<D>
Create a new InMemoryVectorStore from documents and their corresponding embeddings. Document ids are generated using the provided function.
Uses BruteForce index strategy by default. For custom index strategies, use InMemoryVectorStore::builder.
Sourcepub fn add_documents(
&mut self,
documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>,
)
pub fn add_documents( &mut self, documents: impl IntoIterator<Item = (D, OneOrMany<Embedding>)>, )
Add documents and their corresponding embeddings to the store.
Ids are automatically generated have will have the form "doc{n}" where n
is the index of the document.
Sourcepub fn add_documents_with_ids(
&mut self,
documents: impl IntoIterator<Item = (impl ToString, D, OneOrMany<Embedding>)>,
)
pub fn add_documents_with_ids( &mut self, documents: impl IntoIterator<Item = (impl ToString, D, OneOrMany<Embedding>)>, )
Add documents and their corresponding embeddings to the store with ids.
Sourcepub fn add_documents_with_id_f(
&mut self,
documents: Vec<(D, OneOrMany<Embedding>)>,
f: fn(&D) -> String,
)
pub fn add_documents_with_id_f( &mut self, documents: Vec<(D, OneOrMany<Embedding>)>, f: fn(&D) -> String, )
Add documents and their corresponding embeddings to the store. Document ids are generated using the provided function.
Sourcepub fn get_document<T>(&self, id: &str) -> Result<Option<T>, VectorStoreError>where
T: for<'a> Deserialize<'a>,
pub fn get_document<T>(&self, id: &str) -> Result<Option<T>, VectorStoreError>where
T: for<'a> Deserialize<'a>,
Get the document by its id and deserialize it into the given type.
Source§impl<D> InMemoryVectorStore<D>where
D: Serialize,
impl<D> InMemoryVectorStore<D>where
D: Serialize,
Trait Implementations§
Source§impl<D> Clone for InMemoryVectorStore<D>
impl<D> Clone for InMemoryVectorStore<D>
Source§fn clone(&self) -> InMemoryVectorStore<D>
fn clone(&self) -> InMemoryVectorStore<D>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more