Skip to main content

mnemefusion_core/
lib.rs

1// Crate-level lint configuration
2#![allow(clippy::result_large_err)] // redb::Error is 160+ bytes; boxing it is a future refactor
3#![allow(clippy::too_many_arguments)] // several internal functions have >7 args by design
4#![allow(clippy::type_complexity)] // complex return types in query pipeline
5
6//! MnemeFusion Core
7//!
8//! A unified memory engine for AI applications—"SQLite for AI memory."
9//!
10//! MnemeFusion provides four-dimensional memory indexing (semantic, temporal,
11//! causal, entity) in a single embedded database file with zero external dependencies.
12//!
13//! # Quick Start
14//!
15//! ```no_run
16//! use mnemefusion_core::{MemoryEngine, Config};
17//!
18//! // Open or create a database
19//! let engine = MemoryEngine::open("./brain.mfdb", Config::default()).unwrap();
20//!
21//! // Add a memory
22//! let embedding = vec![0.1; 384]; // Your embedding vector
23//! let id = engine.add(
24//!     "Project deadline moved to March 15th".to_string(),
25//!     embedding,
26//!     None,
27//!     None,
28//!     None,
29//!     None,
30//! ).unwrap();
31//!
32//! // Retrieve a memory
33//! let memory = engine.get(&id).unwrap();
34//!
35//! // Close the database
36//! engine.close().unwrap();
37//! ```
38//!
39//! # Architecture
40//!
41//! MnemeFusion is built on:
42//! - **redb**: ACID-compliant embedded storage
43//! - **usearch**: High-performance vector similarity search (HNSW)
44//! - **petgraph**: Graph algorithms for causal and entity relationships
45//!
46//! All data is stored in a single `.mfdb` file, making it easy to backup,
47//! version, and deploy.
48
49pub mod config;
50pub mod error;
51pub mod graph;
52pub mod index;
53pub mod ingest;
54pub mod memory;
55pub mod query;
56pub mod slm;
57pub mod storage;
58pub mod trace;
59pub mod types;
60pub mod util;
61
62// Native LLM inference module (only available with entity-extraction feature)
63#[cfg(feature = "entity-extraction")]
64pub mod inference;
65
66// Entity extraction module (only available with entity-extraction feature)
67#[cfg(feature = "entity-extraction")]
68pub mod extraction;
69
70// Embedding engine module (only available with embedding-onnx feature)
71pub mod embedding;
72
73// Public API exports
74pub use config::Config;
75pub use error::{Error, Result};
76pub use graph::{CausalEdge, CausalPath, CausalTraversalResult, EntityQueryResult, GraphManager};
77pub use index::{TemporalIndex, TemporalResult, VectorIndex, VectorIndexConfig, VectorResult};
78pub use ingest::{EntityExtractor, SimpleEntityExtractor};
79pub use memory::{
80    contextualize_for_embedding, first_person_to_third, EmbeddingFn, MemoryEngine, ScopedMemory,
81};
82pub use query::{
83    AdaptiveWeightConfig, FusedResult, FusionEngine, IntentClassification, IntentClassifier,
84    IntentWeights, QueryIntent, QueryPlanner,
85};
86
87// SLM exports (only available when slm feature is enabled)
88#[cfg(feature = "slm")]
89pub use slm::{SlmClassifier, SlmConfig};
90
91#[cfg(not(feature = "slm"))]
92pub use slm::SlmConfig; // Config always available, but SlmClassifier only with feature
93
94// Native inference exports (only available with entity-extraction feature)
95#[cfg(feature = "entity-extraction")]
96pub use inference::{InferenceEngine, JsonGrammar};
97
98// Entity extraction exports (only available with entity-extraction feature)
99#[cfg(feature = "entity-extraction")]
100pub use extraction::{
101    ExtractedEntity, ExtractedFact, ExtractionResult, LlmEntityExtractor, ModelTier,
102    TriplexExtractor,
103};
104
105// Embedding engine export (only available with embedding-onnx feature)
106#[cfg(feature = "embedding-onnx")]
107pub use embedding::EmbeddingEngine;
108
109pub use trace::{Trace, TraceRecorder, TraceStep, TraceValue};
110pub use types::{
111    AddResult, BatchError, BatchResult, Entity, EntityId, FilterOp, Memory, MemoryId, MemoryInput,
112    MetadataFilter, Source, SourceType, Timestamp, UpsertResult, NAMESPACE_METADATA_KEY,
113    SOURCE_METADATA_KEY,
114};