Skip to main content

MemvidStore

Struct MemvidStore 

Source
pub struct MemvidStore { /* private fields */ }
Expand description

A persistent, file-backed vector / lexical index over a memvid .mv2 archive.

MemvidStore is cheap to clone (it shares an Arc<Mutex<Memvid>> with every clone) and can be both read from and written to concurrently from multiple async tasks. Writes are serialised through the inner mutex.

§Concurrency

Every public method on the underlying Memvid handle — including search, vec_search_with_embedding, frame_count, and the various put_* writers — takes &mut self. Reads cannot run in parallel with other reads, so the inner lock is a Mutex rather than an RwLock. Workloads that require concurrent reads should open separate read-only handles via MemvidStoreBuilder::open_read_only.

The lock is std::sync::Mutex (not tokio::sync::Mutex): the crate is intentionally runtime-agnostic and the clippy await_holding_lock lint enforces that no .await ever happens while a guard is live. Every guard in this module is scope-dropped before any async boundary.

Unlike most rig vector stores, MemvidStore is not parameterised over an EmbeddingModel: memvid embeds queries internally using whichever engine its file is configured with (BM25/Tantivy when the lex feature is enabled, HNSW + BGE-small when vec is enabled). Pass plain text in VectorSearchRequest::query and let memvid do the rest.

Implementations§

Source§

impl MemvidStore

Source

pub fn from_memvid(memvid: Memvid) -> Self

Wraps an already-open Memvid handle.

Source

pub fn frame_count(&self) -> Result<usize, MemvidError>

Number of frames currently stored in the underlying .mv2 file.

Source

pub fn stats(&self) -> Result<Stats, MemvidError>

Aggregate statistics for the underlying memory.

Source

pub fn builder() -> MemvidStoreBuilder

Begin building a new store. See MemvidStoreBuilder.

Source

pub fn put_text( &self, text: &str, options: PutOptions, ) -> Result<u64, MemvidError>

Append a UTF-8 text payload to the archive and immediately commit.

Returns the assigned frame_id. When the store has been built with an embedder (vec feature), the text is embedded and stored alongside its frame so that subsequent VectorStoreIndex::top_n calls perform semantic search.

Source

pub fn put_text_uncommitted( &self, text: &str, options: PutOptions, ) -> Result<u64, MemvidError>

Append a payload without committing. The caller is responsible for invoking MemvidStore::commit before a subsequent search will see the new frame.

Source

pub fn commit(&self) -> Result<(), MemvidError>

Flush any pending writes to disk.

Source

pub fn search( &self, request: SearchRequest, ) -> Result<SearchResponse, MemvidError>

Run a SearchRequest directly. Useful for callers that need memvid-native features (cursors, ACL contexts, etc.) that do not map onto VectorSearchRequest.

§Concurrency

Acquires the store’s inner Mutex for the duration of the call. Do not invoke this (or any other MemvidStore method) from within a crate::WriteTransform closure: hook writes already hold a path through put_text and a re-entrant call would deadlock.

Source

pub fn memory_card_count(&self) -> Result<usize, MemvidError>

Total number of memvid_core::MemoryCards currently stored on the memories track.

Cards are produced automatically when frames are written with memvid_core::PutOptions::extract_triplets enabled (the default, also exposed through crate::MemoryConfig::extract_triplets). They form a structured Subject-Predicate-Object index over the underlying free-text frames.

Source

pub fn all_memory_cards(&self) -> Result<Vec<MemoryCard>, MemvidError>

Snapshot of every memvid_core::MemoryCard currently on the memories track, cloned to owned values so the inner lock is released before returning.

Useful for callers that need to filter / sort across the entire card set (for example crate::MemoryCardContext’s EntityMentions selection strategy). Avoid in hot paths against very large archives: returns one allocation per card.

Source

pub fn cards_for_query( &self, query: &str, ) -> Result<Vec<MemoryCard>, MemvidError>

Cards whose entity mentions appear (case-insensitive, whole-word) in query. Filters behind the inner mutex so only matching cards are cloned out, avoiding the full-archive snapshot that MemvidStore::all_memory_cards performs.

Source

pub fn put_memory_card( &self, card: MemoryCard, ) -> Result<MemoryCardId, MemvidError>

Insert a fully-built memvid_core::MemoryCard onto the memories track. The card’s id field is overwritten with a freshly assigned memvid_core::MemoryCardId, which is returned.

Useful for tests, deterministic seeding, or callers that have their own structured-extraction pipeline upstream of memvid’s.

Source

pub fn entity_memories( &self, entity: &str, ) -> Result<Vec<MemoryCard>, MemvidError>

All memory cards associated with entity, returned as owned values (the underlying lock is released before returning).

Returns an empty Vec if the entity is unknown. Pair with MemvidStore::current_memory when only the latest non-retracted value of a single slot is needed.

Source

pub fn current_memory( &self, entity: &str, slot: &str, ) -> Result<Option<MemoryCard>, MemvidError>

The most recent non-retracted card for the given entity and slot, if any. Mirrors memvid_core::Memvid::get_current_memory.

Source

pub fn entity_preferences( &self, entity: &str, ) -> Result<Vec<MemoryCard>, MemvidError>

All preference-kind cards for entity, in insertion order.

Source

pub fn aggregate_memory_slot( &self, entity: &str, slot: &str, ) -> Result<Vec<String>, MemvidError>

Aggregate every distinct value recorded for entity/slot across all sessions. Useful for slots that legitimately accumulate (lists of hobbies, places lived in, etc.).

Source

pub fn memory_timeline( &self, entity: &str, ) -> Result<Vec<MemoryCard>, MemvidError>

Event-kind cards for entity in chronological order.

Source

pub fn mesh_node_count(&self) -> Result<usize, MemvidError>

Number of entity nodes in the underlying memvid Logic-Mesh.

The Logic-Mesh is memvid’s graph track: typed entity nodes (memvid_core::MeshNode) connected by relationship edges (memvid_core::MeshEdge). Populated automatically when frames are written with NER-style enrichment (controlled by memvid_core::PutOptions).

Source

pub fn mesh_edge_count(&self) -> Result<usize, MemvidError>

Number of relationship edges in the Logic-Mesh.

Source

pub fn find_entity(&self, name: &str) -> Result<Option<MeshNode>, MemvidError>

Find an entity node by canonical or display name (case-insensitive).

Source

pub fn frame_entities( &self, frame_id: u64, ) -> Result<Vec<MeshNode>, MemvidError>

All entity nodes mentioned in frame_id. Returns owned values so the inner lock is released before returning.

Source

pub fn entities_by_kind( &self, kind: EntityKind, ) -> Result<Vec<MeshNode>, MemvidError>

All entity nodes of the given memvid_core::EntityKind.

Source

pub fn follow_relationship( &self, start: &str, link_type: &str, hops: usize, ) -> Result<Vec<FollowResult>, MemvidError>

Traverse the Logic-Mesh starting from start, following edges of link_type up to hops deep. Wraps memvid_core::Memvid::follow.

Useful for “who reports to alice’s manager?”-style relationship queries. Returns the result list directly; callers that want streaming traversal should call memvid’s logic_mesh() API by holding their own clone of the inner memvid_core::Memvid handle.

Trait Implementations§

Source§

impl Clone for MemvidStore

Source§

fn clone(&self) -> MemvidStore

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 Debug for MemvidStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl InsertDocuments for MemvidStore

Source§

async fn insert_documents<Doc>( &self, documents: Vec<(Doc, OneOrMany<Embedding>)>, ) -> Result<(), VectorStoreError>

Persist documents into the underlying .mv2 file.

Note: caller-supplied embeddings are intentionally ignored. On the lex-only path the document JSON is written as bytes and embeddings are dropped. When this store is configured with a local embedder (vec feature) every document is re-embedded with that model so memvid’s vector index stays consistent with its bound model identifier.

Source§

impl MemoryGraph for MemvidStore

Source§

type Error = MemvidError

Error returned by graph queries. Must be convertible to rig::vector_store::VectorStoreError when used with an adapter that exposes a rig::vector_store::VectorStoreIndex (such as crate::MemoryCardContext).
Source§

fn memory_card_count(&self) -> Result<usize, Self::Error>

Total number of cards currently stored.
Source§

fn all_memory_cards(&self) -> Result<Vec<MemoryCard>, Self::Error>

Snapshot of every card. Used by selection strategies that need to filter / sort across the whole set.
Source§

fn entity_memories(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error>

All cards for entity. Empty Vec for unknown entities.
Source§

fn current_memory( &self, entity: &str, slot: &str, ) -> Result<Option<MemoryCard>, Self::Error>

Most recent non-retracted value for entity/slot, if any.
Source§

fn entity_preferences( &self, entity: &str, ) -> Result<Vec<MemoryCard>, Self::Error>

Preference-kind cards for entity.
Source§

fn memory_timeline(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error>

Event-kind cards for entity in chronological order.
Source§

fn cards_for_query(&self, query: &str) -> Result<Vec<MemoryCard>, Self::Error>

Cards whose entity mentions appear in query (case-insensitive whole-word match). The default implementation snapshots the entire archive via MemoryGraph::all_memory_cards and filters in pure Rust, which is correct but clones every card; backends backed by a graph store should override this to filter behind their own locking / indexing and avoid the intermediate full-archive allocation.
Source§

impl VectorStoreIndex for MemvidStore

Source§

async fn top_n<T>( &self, req: VectorSearchRequest<Self::Filter>, ) -> Result<Vec<(f64, String, T)>, VectorStoreError>
where T: for<'a> Deserialize<'a> + WasmCompatSend,

Run a search and deserialise each hit’s JSON representation into T.

§Contract

The type T must be deserialisable from a SearchHit JSON object — i.e. either T = SearchHit itself, or a struct whose fields are a subset of SearchHit’s public fields (frame_id, text, score, metadata, …). Use serde_json::Value for an opaque view.

This method does not round-trip user-defined document types. If you persisted JSON documents through InsertDocuments and want them back, use VectorStoreIndex::top_n_ids for the frame ids and then MemvidStore::search for full-fidelity access via the memvid-native SearchRequest API.

§Example
use memvid_core::SearchHit;
use rig::vector_store::{
    VectorSearchRequest, VectorStoreIndex,
    request::VectorSearchRequestBuilder,
};
use rig_memvid::{MemvidFilter, MemvidStore};

let req: VectorSearchRequest<MemvidFilter> =
    VectorSearchRequestBuilder::<MemvidFilter>::default()
        .query("hello")
        .samples(5)
        .build();
let hits: Vec<(f64, String, SearchHit)> = store.top_n(req).await?;
Source§

type Filter = MemvidFilter

The filter type for this backend.
Source§

async fn top_n_ids( &self, req: VectorSearchRequest<Self::Filter>, ) -> Result<Vec<(f64, String)>, VectorStoreError>

Returns the top N most similar document IDs as (score, id) tuples.

Auto Trait Implementations§

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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> 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, F> Tool for T
where F: SearchFilter<Value = Value> + WasmCompatSend + WasmCompatSync + for<'de> Deserialize<'de>, T: VectorStoreIndex<Filter = F>,

Source§

const NAME: &'static str = "search_vector_store"

The name of the tool. This name should be unique within a single ToolSet or other registration scope that dispatches tools by name.
Source§

type Error = VectorStoreError

The error type of the tool.
Source§

type Args = VectorSearchRequest<F>

The arguments type of the tool.
Source§

type Output = Vec<VectorStoreOutput>

The output type of the tool.
Source§

async fn definition(&self, _prompt: String) -> ToolDefinition

A method returning the tool definition. The user prompt can be used to tailor the definition to the specific use case.
Source§

async fn call( &self, args: <T as Tool>::Args, ) -> Result<<T as Tool>::Output, <T as Tool>::Error>

The tool execution method. Both the arguments and return value are a String since these values are meant to be the output and input of LLM models (respectively)
Source§

fn name(&self) -> String

A method returning the name of the tool.
Source§

impl<T> ToolDyn for T
where T: Tool,

Source§

fn name(&self) -> String

Returns the tool name used for dispatch.
Source§

fn definition<'a>( &'a self, prompt: String, ) -> Pin<Box<dyn Future<Output = ToolDefinition> + Send + 'a>>

Returns the provider-facing tool schema.
Source§

fn call<'a>( &'a self, args: String, ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>

Calls the tool with JSON-encoded arguments and returns model-facing text.
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<I, F> VectorStoreIndexDyn for I
where I: VectorStoreIndex<Filter = F>, F: Debug + Clone + SearchFilter<Value = Value> + WasmCompatSend + WasmCompatSync + Serialize + for<'de> Deserialize<'de> + 'static,

Source§

fn top_n<'a>( &'a self, req: VectorSearchRequest, ) -> Pin<Box<dyn Future<Output = Result<Vec<(f64, String, Value)>, VectorStoreError>> + Send + 'a>>

Returns the top N documents for a JSON-serializable request.
Source§

fn top_n_ids<'a>( &'a self, req: VectorSearchRequest, ) -> Pin<Box<dyn Future<Output = Result<Vec<(f64, String)>, VectorStoreError>> + Send + 'a>>

Returns only the top N document IDs for a JSON-serializable request.
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
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> Fruit for T
where T: Send + Downcast,

Source§

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

Source§

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

Source§

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