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/// Format recalled facts as a chronological, date-prefixed timeline with a
25/// "now" anchor — the dated-context representation measured to lift temporal
26/// question answering, shipped as product behavior rather than a harness prompt.
27pub mod dated_context;
28pub mod embedder;
29pub mod error;
30pub mod extract;
31/// Vector+graph score fusion — the ranking layer behind
32/// [`service::MemoryService::recall_fused`]. Internal: callers reach it only
33/// through that method.
34mod fusion;
35/// Content-addressed memory ids — internal; ids surface through the service API.
36pub(crate) mod id;
37/// Resource caps (DoS limits) shared by every adapter — the single source of
38/// truth for fact size, recall limit, and `why` hop depth.
39pub mod limits;
40/// The MCP server transport. Gated behind the default `mcp` feature so library
41/// consumers (e.g. the language bindings) can depend on the memory core without
42/// pulling the `rmcp`/`tokio` server stack.
43#[cfg(feature = "mcp")]
44pub mod mcp;
45/// The domain data model — the value types the memory layer exchanges
46/// (`Link`, `Recollection`, `ColumnFilter`, `Explanation`, …), separate from the
47/// service that computes them.
48pub mod model;
49/// Optional second-stage re-scoring of a fused recall pool (bring your own
50/// cross-encoder/LLM). Never wired in by default — see [`rerank::Reranker`].
51pub mod rerank;
52/// Shared JSON Schema post-processing (strips `schemars`' non-standard integer
53/// `format` keywords so strict MCP clients don't warn on every id field).
54mod schema;
55pub mod service;
56/// The storage backend abstraction — [`storage::MemoryStore`] and the
57/// default, file-backed [`storage::NativeStore`]. Implement `MemoryStore` to
58/// run the wedge over a different backend (e.g. an in-memory one for WASM).
59pub mod storage;
60
61/// Default embedding dimension — the single source of truth, taken from the
62/// SDK's own default so the server, library, and tests never restate the
63/// value. `velesdb_core::agent` (where the canonical constant lives) is
64/// itself `persistence`-gated, so a `persistence`-free build (e.g.
65/// `velesdb-wasm`) falls back to [`FALLBACK_DIMENSION`].
66#[cfg(feature = "persistence")]
67pub const DEFAULT_DIMENSION: usize = velesdb_core::agent::DEFAULT_DIMENSION;
68#[cfg(not(feature = "persistence"))]
69pub const DEFAULT_DIMENSION: usize = FALLBACK_DIMENSION;
70
71/// The hand-written value the `persistence`-free arm of
72/// [`DEFAULT_DIMENSION`] falls back to (the canonical constant's module is
73/// feature-gated away there). The `persistence` build — CI's default —
74/// statically asserts it still equals the canonical value, so drift fails
75/// to compile instead of silently splitting the wasm default dimension
76/// from the native one.
77const FALLBACK_DIMENSION: usize = 384;
78#[cfg(feature = "persistence")]
79const _: () = assert!(
80 FALLBACK_DIMENSION == velesdb_core::agent::DEFAULT_DIMENSION,
81 "update FALLBACK_DIMENSION to match velesdb_core::agent::DEFAULT_DIMENSION"
82);
83
84pub use dated_context::{format_dated_context, DatedContext};
85pub use embedder::{DynEmbedder, EmbedError, Embedder, HashEmbedder};
86#[cfg(feature = "ollama")]
87pub use embedder::{OllamaEmbedder, DEFAULT_OLLAMA_MODEL, DEFAULT_OLLAMA_URL};
88pub use error::{ErrorCategory, MemoryError};
89#[cfg(feature = "extract")]
90pub use extract::OllamaExtractor;
91pub use extract::{DynExtractor, ExtractError, ExtractedFact, Extractor};
92#[cfg(feature = "mcp")]
93pub use mcp::McpServer;
94pub use model::{
95 ColumnFilter, ColumnOp, Explanation, FusionOptions, Link, MemoryEdge, MemoryNode, Recollection,
96};
97pub use rerank::{DynReranker, RerankError, Reranker};
98pub use service::{MemoryService, Metadata};
99pub use storage::MemoryStore;
100#[cfg(feature = "persistence")]
101pub use storage::NativeStore;