velesdb_memory/lib.rs
1#![deny(unsafe_code)]
2//! # VelesDB-memory
3//!
4//! Local-first **memory** layer for AI agents, exposed through a single MCP
5//! server. This crate is the domain core: it maps five memory operations onto
6//! `VelesDB`'s in-core Agent Memory SDK.
7//!
8//! | Operation | Meaning |
9//! |------------|----------------------------------------------------|
10//! | `remember` | store a fact (+ optional links to other memories) |
11//! | `recall` | semantic retrieval of similar facts |
12//! | `relate` | create a typed edge between two memories |
13//! | `forget` | delete a memory |
14//! | `why` | recall + multi-hop graph traversal |
15//!
16//! ## License boundary (non-negotiable)
17//!
18//! This crate exposes **memory semantics only** (results), never raw database
19//! capabilities (`query(velesql)`, `create_collection`, `upsert(vectors)`,
20//! `traverse(graph)`). Exposing the raw engine would constitute a "Substantial
21//! Set" of the Software's features and breach the `VelesDB` Core License 1.0
22//! (§1, No Hosted or Managed Service). See `VISION.md` §5 and `PLAN.md` Phase 4A.
23
24/// The deterministic context compiler (EPIC-P-070): classify, dedup, and pack
25/// caller-supplied context fragments under a token budget — no LLM, no cloud,
26/// every decision auditable. Gated behind the default `context` feature.
27#[cfg(feature = "context")]
28pub mod context;
29/// Format recalled facts as a chronological, date-prefixed timeline with a
30/// "now" anchor — the dated-context representation measured to lift temporal
31/// question answering, shipped as product behavior rather than a harness prompt.
32pub mod dated_context;
33pub mod embedder;
34pub mod error;
35pub mod extract;
36/// Vector+graph score fusion — the ranking layer behind
37/// [`service::MemoryService::recall_fused`]. Internal: callers reach it only
38/// through that method.
39mod fusion;
40/// Content-addressed memory ids — internal; ids surface through the service API.
41pub(crate) mod id;
42/// Resource caps (DoS limits) shared by every adapter — the single source of
43/// truth for fact size, recall limit, and `why` hop depth.
44pub mod limits;
45/// The MCP server transport. Gated behind the default `mcp` feature so library
46/// consumers (e.g. the language bindings) can depend on the memory core without
47/// pulling the `rmcp`/`tokio` server stack.
48#[cfg(feature = "mcp")]
49pub mod mcp;
50/// The domain data model — the value types the memory layer exchanges
51/// (`Link`, `Recollection`, `ColumnFilter`, `Explanation`, …), separate from the
52/// service that computes them.
53pub mod model;
54/// Optional second-stage re-scoring of a fused recall pool (bring your own
55/// cross-encoder/LLM). Never wired in by default — see [`rerank::Reranker`].
56pub mod rerank;
57/// Shared JSON Schema post-processing (strips `schemars`' non-standard integer
58/// `format` keywords so strict MCP clients don't warn on every id field).
59mod schema;
60pub mod service;
61/// The storage backend abstraction — [`storage::MemoryStore`] and the
62/// default, file-backed [`storage::NativeStore`]. Implement `MemoryStore` to
63/// run the wedge over a different backend (e.g. an in-memory one for WASM).
64pub mod storage;
65
66/// Default embedding dimension — the single source of truth, taken from the
67/// SDK's own default so the server, library, and tests never restate the
68/// value. `velesdb_core::agent` (where the canonical constant lives) is
69/// itself `persistence`-gated, so a `persistence`-free build (e.g.
70/// `velesdb-wasm`) falls back to `FALLBACK_DIMENSION`.
71#[cfg(feature = "persistence")]
72pub const DEFAULT_DIMENSION: usize = velesdb_core::agent::DEFAULT_DIMENSION;
73#[cfg(not(feature = "persistence"))]
74pub const DEFAULT_DIMENSION: usize = FALLBACK_DIMENSION;
75
76/// The hand-written value the `persistence`-free arm of
77/// [`DEFAULT_DIMENSION`] falls back to (the canonical constant's module is
78/// feature-gated away there). The `persistence` build — CI's default —
79/// statically asserts it still equals the canonical value, so drift fails
80/// to compile instead of silently splitting the wasm default dimension
81/// from the native one.
82const FALLBACK_DIMENSION: usize = 384;
83#[cfg(feature = "persistence")]
84const _: () = assert!(
85 FALLBACK_DIMENSION == velesdb_core::agent::DEFAULT_DIMENSION,
86 "update FALLBACK_DIMENSION to match velesdb_core::agent::DEFAULT_DIMENSION"
87);
88
89#[cfg(feature = "context")]
90pub use context::ContextCompiler;
91pub use dated_context::{format_dated_context, DatedContext};
92pub use embedder::{DynEmbedder, EmbedError, Embedder, HashEmbedder};
93#[cfg(feature = "ollama")]
94pub use embedder::{OllamaEmbedder, DEFAULT_OLLAMA_MODEL, DEFAULT_OLLAMA_URL};
95pub use error::{ErrorCategory, MemoryError};
96#[cfg(feature = "extract")]
97pub use extract::OllamaExtractor;
98pub use extract::{DynExtractor, ExtractError, ExtractedFact, Extractor};
99#[cfg(feature = "mcp")]
100pub use mcp::McpServer;
101pub use model::{
102 ColumnFilter, ColumnOp, Explanation, FusionOptions, Link, MemoryEdge, MemoryNode, Recollection,
103};
104pub use rerank::{DynReranker, RerankError, Reranker};
105pub use service::{MemoryService, Metadata};
106pub use storage::MemoryStore;
107#[cfg(feature = "persistence")]
108pub use storage::NativeStore;