Skip to main content

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 nine 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//! | `recall_where`      | semantic retrieval filtered by metadata            |
13//! | `recall_fused`      | vector + graph fused retrieval                     |
14//! | `relate`            | create a typed edge between two memories           |
15//! | `forget`            | delete a memory                                    |
16//! | `why`               | recall + multi-hop graph traversal                 |
17//! | `feedback`          | reinforce or penalize a memory after use           |
18//! | `remember_extracted`| extract facts from raw text and auto-wire the graph|
19//!
20//! ## License boundary (non-negotiable)
21//!
22//! This crate exposes **memory semantics only** (results), never raw database
23//! capabilities (`query(velesql)`, `create_collection`, `upsert(vectors)`,
24//! `traverse(graph)`). Exposing the raw engine would constitute a "Substantial
25//! Set" of the Software's features and breach the `VelesDB` Core License 1.0
26//! (§1, No Hosted or Managed Service). See `VISION.md` §5 and `PLAN.md` Phase 4A.
27
28/// Wall-clock "today" as a `YYYYMMDD` integer, read only by `remember`'s
29/// auto-date stamping (see [`storage::AUTO_DATE_FIELD`]) — never by the
30/// context compiler, which stays clock-free and deterministic. Internal:
31/// nothing outside the crate needs to read the clock directly.
32mod clock;
33/// The deterministic context compiler (EPIC-P-070): classify, dedup, and pack
34/// caller-supplied context fragments under a token budget — no LLM, no cloud,
35/// every decision auditable. Gated behind the default `context` feature.
36#[cfg(feature = "context")]
37pub mod context;
38/// Format recalled facts as a chronological, date-prefixed timeline with a
39/// "now" anchor — the dated-context representation measured to lift temporal
40/// question answering, shipped as product behavior rather than a harness prompt.
41pub mod dated_context;
42pub mod embedder;
43pub mod error;
44pub mod extract;
45/// Vector+graph score fusion — the ranking layer behind
46/// [`service::MemoryService::recall_fused`]. Internal: callers reach it only
47/// through that method.
48mod fusion;
49/// The streamable-HTTP transport (multi-client mode): lets several MCP
50/// clients share ONE `velesdb-memory` process instead of each spawning its
51/// own stdio process and fighting over the store's single-writer `flock`.
52/// Gated behind the (non-default) `http` feature — see the module docs and
53/// the crate README's "HTTP transport (multi-client)" section.
54#[cfg(feature = "http")]
55pub mod http;
56/// Content-addressed memory ids — internal; ids surface through the service API.
57pub(crate) mod id;
58/// Resource caps (DoS limits) shared by every adapter — the single source of
59/// truth for fact size, recall limit, and `why` hop depth.
60pub mod limits;
61/// The MCP server transport. Gated behind the default `mcp` feature so library
62/// consumers (e.g. the language bindings) can depend on the memory core without
63/// pulling the `rmcp`/`tokio` server stack.
64#[cfg(feature = "mcp")]
65pub mod mcp;
66/// The domain data model — the value types the memory layer exchanges
67/// (`Link`, `Recollection`, `ColumnFilter`, `Explanation`, …), separate from the
68/// service that computes them.
69pub mod model;
70/// Optional second-stage re-scoring of a fused recall pool (bring your own
71/// cross-encoder/LLM). Never wired in by default — see [`rerank::Reranker`].
72pub mod rerank;
73/// Shared JSON Schema post-processing (strips `schemars`' non-standard integer
74/// `format` keywords so strict MCP clients don't warn on every id field).
75mod schema;
76pub mod service;
77/// The storage backend abstraction — [`storage::MemoryStore`] and the
78/// default, file-backed [`storage::NativeStore`]. Implement `MemoryStore` to
79/// run the wedge over a different backend (e.g. an in-memory one for WASM).
80pub mod storage;
81/// Locally-generated TLS material (a cached self-signed CA + short-lived
82/// leaf certs) for the streamable-HTTP transport's HTTPS-by-default
83/// listener — see the module docs for the full design rationale. Gated
84/// behind `http` since it exists only to serve that transport.
85#[cfg(feature = "http")]
86pub mod tls;
87
88/// Default embedding dimension — the single source of truth, taken from the
89/// SDK's own default so the server, library, and tests never restate the
90/// value. `velesdb_core::agent` (where the canonical constant lives) is
91/// itself `persistence`-gated, so a `persistence`-free build (e.g.
92/// `velesdb-wasm`) falls back to `FALLBACK_DIMENSION`.
93#[cfg(feature = "persistence")]
94pub const DEFAULT_DIMENSION: usize = velesdb_core::agent::DEFAULT_DIMENSION;
95#[cfg(not(feature = "persistence"))]
96pub const DEFAULT_DIMENSION: usize = FALLBACK_DIMENSION;
97
98/// The hand-written value the `persistence`-free arm of
99/// [`DEFAULT_DIMENSION`] falls back to (the canonical constant's module is
100/// feature-gated away there). The `persistence` build — CI's default —
101/// statically asserts it still equals the canonical value, so drift fails
102/// to compile instead of silently splitting the wasm default dimension
103/// from the native one.
104const FALLBACK_DIMENSION: usize = 384;
105#[cfg(feature = "persistence")]
106const _: () = assert!(
107    FALLBACK_DIMENSION == velesdb_core::agent::DEFAULT_DIMENSION,
108    "update FALLBACK_DIMENSION to match velesdb_core::agent::DEFAULT_DIMENSION"
109);
110
111#[cfg(feature = "context")]
112pub use context::ContextCompiler;
113pub use dated_context::{format_dated_context, DatedContext};
114pub use embedder::{DynEmbedder, EmbedError, Embedder, HashEmbedder};
115#[cfg(feature = "ollama")]
116pub use embedder::{OllamaEmbedder, DEFAULT_OLLAMA_MODEL, DEFAULT_OLLAMA_URL};
117pub use error::{ErrorCategory, MemoryError};
118#[cfg(feature = "extract")]
119pub use extract::OllamaExtractor;
120pub use extract::{DynExtractor, ExtractError, ExtractedFact, Extractor};
121#[cfg(feature = "mcp")]
122pub use mcp::McpServer;
123pub use model::{
124    ColumnFilter, ColumnOp, Explanation, FusionOptions, Link, MemoryEdge, MemoryNode, Recollection,
125};
126pub use rerank::{DynReranker, RerankError, Reranker};
127pub use service::{MemoryService, Metadata};
128#[cfg(feature = "persistence")]
129pub use storage::NativeStore;
130pub use storage::{MemoryStore, AUTO_DATE_FIELD};