Skip to main content

InMemoryVectorStore

Struct InMemoryVectorStore 

Source
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>
where D: Serialize + Eq,

Source

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();
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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,

Source

pub fn index<M>(self, model: M) -> InMemoryVectorIndex<M, D>
where M: EmbeddingModel,

Source

pub fn iter( &self, ) -> impl Iterator<Item = (&String, &(D, OneOrMany<Embedding>))>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<D> Clone for InMemoryVectorStore<D>
where D: Clone + Serialize,

Source§

fn clone(&self) -> InMemoryVectorStore<D>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D> Default for InMemoryVectorStore<D>
where D: Default + Serialize,

Source§

fn default() -> InMemoryVectorStore<D>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D> Freeze for InMemoryVectorStore<D>

§

impl<D> RefUnwindSafe for InMemoryVectorStore<D>
where D: RefUnwindSafe,

§

impl<D> Send for InMemoryVectorStore<D>
where D: Send,

§

impl<D> Sync for InMemoryVectorStore<D>
where D: Sync,

§

impl<D> Unpin for InMemoryVectorStore<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for InMemoryVectorStore<D>

§

impl<D> UnwindSafe for InMemoryVectorStore<D>
where D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more