Skip to main content

rig_memvid/
lib.rs

1//! Memvid-backed persistent memory for [Rig](https://crates.io/crates/rig-core).
2//!
3//! See the crate-level [README](../README.md) for a quick-start. The two
4//! main types are:
5//!
6//! - [`MemvidStore`] — implements [`rig::vector_store::VectorStoreIndex`].
7//!   Wire it into an agent with `agent.dynamic_context(n, store.clone())`.
8//! - [`MemvidPersistHook`] — implements
9//!   [`rig::agent::PromptHook`]. Attach with
10//!   `prompt.with_hook(hook)` to record every turn into the same store.
11//!
12//! Sharing a single [`MemvidStore`] between recall and persistence is the
13//! intended pattern: writes through the hook are visible to subsequent
14//! searches in the same process.
15//!
16//! # Re-exports
17//!
18//! [`memvid_core`] is re-exported so callers do not need to add it as a
19//! direct dependency to construct [`memvid_core::PutOptions`],
20//! [`memvid_core::AclContext`], or [`memvid_core::SearchRequest`] when
21//! reaching for [`MemvidStore::search`] / [`MemvidStore::put_text`].
22//!
23//! # Platform support
24//!
25//! The crate is `cfg`-gated off on `wasm`: memvid relies on synchronous
26//! file I/O and a process-level file lock that have no analogue under
27//! `wasm32-unknown-unknown`. On wasm targets the crate is intentionally
28//! empty so that downstream crates can still depend on it transitively
29//! without a build break.
30
31#![cfg_attr(not(target_family = "wasm"), deny(missing_docs))]
32
33#[cfg(target_family = "wasm")]
34compile_error!(
35    "rig-memvid does not currently support `wasm` targets: memvid-core requires \
36     synchronous file I/O and OS-level file locks. Disable rig-memvid for wasm \
37     builds via Cargo target-specific dependencies."
38);
39
40#[cfg(not(target_family = "wasm"))]
41mod cards_context;
42#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
43mod compactor;
44#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
45mod dedup;
46#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
47mod demotion;
48#[cfg(not(target_family = "wasm"))]
49mod error;
50#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
51mod frame_writer;
52#[cfg(not(target_family = "wasm"))]
53mod hook;
54#[cfg(not(target_family = "wasm"))]
55pub mod inmem;
56#[cfg(not(target_family = "wasm"))]
57mod memory_graph;
58#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
59pub mod metadata;
60#[cfg(all(not(target_family = "wasm"), feature = "context-projection"))]
61pub mod projection;
62#[cfg(all(not(target_family = "wasm"), feature = "context-projection"))]
63pub use projection::{
64    IntoContextItem, MemoryCandidate, MemoryContextPack, SupersededCandidate,
65    card_docs_to_context_items, inmem_hits_to_context_items, items_to_memory_candidates,
66    memory_cards_to_context_items, search_hits_to_context_items, supersede,
67};
68#[cfg(all(
69    not(target_family = "wasm"),
70    feature = "context-projection",
71    feature = "compaction"
72))]
73pub use projection::{
74    MemoryFrameRole, PartitionedHits, frame_role, partition_search_hits_by_role,
75    typed_search_hit_to_context_item, typed_search_hits_to_context_items,
76    typed_search_hits_to_memory_candidates,
77};
78#[cfg(not(target_family = "wasm"))]
79mod store;
80
81#[cfg(not(target_family = "wasm"))]
82pub use cards_context::{CardDoc, CardSelection, MemoryCardContext};
83#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
84pub use compactor::MemvidStoringCompactor;
85#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
86pub use demotion::MemvidDemotionHook;
87#[cfg(not(target_family = "wasm"))]
88pub use error::MemvidError;
89#[cfg(not(target_family = "wasm"))]
90pub use hook::{
91    MemoryConfig, MemoryConfigBuilder, MemvidPersistHook, WriteFailure, WriteFailureAction,
92    WriteFailurePhase, WritePolicy, WriteTransform,
93};
94#[cfg(not(target_family = "wasm"))]
95pub use inmem::{Episode, InMemoryError, InMemoryHit, InMemoryStore};
96#[cfg(not(target_family = "wasm"))]
97pub use memory_graph::MemoryGraph;
98#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
99pub use metadata::{FrameKind, MemvidFrameMetadata};
100/// Re-exports of the `rig-memory` compaction surface so callers can
101/// build a `CompactingMemory<M, P, MemvidStoringCompactor<C>>` without
102/// adding `rig-memory` as a direct dependency.
103#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
104pub use rig::memory::{Compactor, DemotionHook, MemoryError};
105#[cfg(all(not(target_family = "wasm"), feature = "compaction"))]
106pub use rig_memory::{CompactingMemory, TemplateCompactor, TextSummary};
107#[cfg(not(target_family = "wasm"))]
108pub use store::{MemvidFilter, MemvidStore, MemvidStoreBuilder};
109
110#[cfg(not(target_family = "wasm"))]
111pub use memvid_core::types::{LogicMeshStats, SearchHitEntity};
112/// Re-exports of the memvid-core memory-card surface that
113/// [`MemvidStore`] returns from
114/// [`MemvidStore::entity_memories`] and friends. Re-exported here so
115/// callers do not need a direct `memvid-core` dependency just to name
116/// the structured-memory types.
117#[cfg(not(target_family = "wasm"))]
118pub use memvid_core::{
119    EntityKind, FollowResult, MemoryCard, MemoryCardId, MemoryKind, MeshEdge, MeshNode, Polarity,
120    VersionRelation,
121};
122
123#[cfg(not(target_family = "wasm"))]
124pub use memvid_core;