mentedb_cognitive/lib.rs
1//! # mentedb-cognitive: Cognitive Engine for MenteDB
2//!
3//! This crate implements the seven cognitive features that distinguish MenteDB
4//! from a conventional vector database. These features run at write time and
5//! read time, giving the engine awareness of the knowledge it holds.
6//!
7//! ## Modules
8//!
9//! - [`interference`]: Detects pairs of memories similar enough to confuse an LLM,
10//! generates disambiguation text, and reorders context to maximize separation.
11//!
12//! - [`pain`]: Records negative experiences (failed actions, user corrections) as
13//! pain signals with intensity and decay. Surfaces warnings during context assembly.
14//!
15//! - [`phantom`]: Detects references to entities not present in the knowledge base
16//! (phantom memories). Flags gaps so the agent can acquire missing knowledge.
17//!
18//! - [`speculative`]: Pre-assembles context windows for predicted upcoming queries
19//! based on conversation trajectory. Uses cosine similarity on embeddings with
20//! keyword overlap as fallback.
21//!
22//! - [`stream`]: Monitors the LLM's output token stream in real time, comparing
23//! against stored facts to detect contradictions, forgotten knowledge, corrections,
24//! and reinforcements mid-generation.
25//!
26//! - [`trajectory`]: Tracks the reasoning arc of a conversation as a sequence of
27//! decision states. Learns topic transition patterns via a Markov chain frequency
28//! map that improves predictions over time. Supports resume context generation,
29//! next-topic prediction, and feedback reinforcement from cache hits.
30//!
31//! - [`write_inference`]: Runs inference at write time to detect contradictions,
32//! create relationship edges, mark obsolete memories, adjust confidence, and
33//! trigger belief propagation automatically.
34
35/// Interference detection between confusable memories.
36pub mod interference;
37/// Pain signal registry for negative experience tracking.
38pub mod pain;
39/// Phantom memory detection for knowledge gaps.
40pub mod phantom;
41/// Speculative context pre assembly cache.
42pub mod speculative;
43/// Real time LLM output stream monitoring.
44pub mod stream;
45/// Conversation trajectory tracking and prediction.
46pub mod trajectory;
47/// Write time inference engine for automatic relationship discovery.
48pub mod write_inference;
49
50pub use interference::{InterferenceDetector, InterferencePair};
51pub use pain::{PainRegistry, PainSignal};
52pub use phantom::{EntityRegistry, PhantomConfig, PhantomMemory, PhantomPriority, PhantomTracker};
53pub use speculative::{CacheEntry, CacheStats, SpeculativeCache};
54pub use stream::{CognitionStream, StreamAlert, StreamConfig, TokenEvent};
55pub use trajectory::{DecisionState, TrajectoryNode, TrajectoryTracker, TransitionMap};
56pub use write_inference::{InferredAction, WriteInferenceConfig, WriteInferenceEngine};