MenteDB/Documentation
GitHub

MenteDB Documentation

A purpose-built Rust database for AI agent memory. Not a vector DB wrapper. A ground-up storage engine with HNSW indexing, graph-based belief propagation, and transformer-optimized context assembly.

12

Rust crates in a cargo workspace

3

SDKs: Python, TypeScript, MCP

30

MCP tools across 5 categories

Installation

Install MenteDB in your preferred language or as an MCP server.

Python
pip install mentedb
Rust
cargo add mentedb
TypeScript / Node.js
npm install @mentedb/sdk
MCP Server
cargo install mentedb-mcp

Quick Start

Get up and running with MenteDB in Python in under a minute.

python
from mentedb import MenteDB

db = MenteDB("./my-agent-memory")

# Store memories with types
db.store("User prefers Python for backend work", memory_type="semantic", tags=["preference", "language"])
db.store("Sprint planning meeting scheduled Friday", memory_type="episodic", tags=["meeting"])

# Search by text (uses hash embedding)
results = db.search_text("programming language preference", k=5)

# Create relationships
mem1 = db.store("User prefers PostgreSQL", memory_type="semantic")
mem2 = db.store("User switched to SQLite", memory_type="semantic")
db.relate(mem2, mem1, "supersedes", weight=1.0)

# Retrieve a specific memory
memory = db.get_memory(mem1)

# Delete a memory
db.forget(mem1)

Core Concepts

Memory Types

  • semantic , facts, preferences, and knowledge. "User prefers dark mode."
  • episodic , events and experiences. "Deployed v2.1 on Tuesday."
  • procedural , how-to knowledge. "Run tests with pytest -x."

Graph Relationships

Memories are connected through typed, weighted edges: supersedes, contradicts, supports, related_to, caused_by.

Belief Propagation

When memory A supersedes memory B, searches automatically exclude B. This ensures your agent never acts on stale information without manual cleanup.

Context Assembly

Builds optimized context windows using U-curve ordering, placing important items at the start and end where LLM attention is strongest. Token budget aware.

Delta Serving

After the first turn, only new or changed memories are sent to the LLM, reducing memory retrieval tokens by ~90% across multi-turn conversations.

Salience Decay

Memories gradually lose relevance over time unless they are accessed. Frequently used memories stay prominent while stale ones fade naturally.

API Reference (Python)

MenteDB(path: str)

Open or create a database at the given path.

Returns: MenteDB instance

store(content: str, memory_type: str, tags: list[str] = [], embedding: list[float] | None = None, agent_id: str | None = None)

Store a new memory. Returns the UUID of the created memory.

Returns: str (UUID)

search_text(query: str, k: int)

Search memories by text content using hash embedding.

Returns: list[SearchResult] (id, score)

search(embedding: list[float], k: int)

Search memories by raw vector embedding.

Returns: list[SearchResult] (id, score)

relate(source_id: str, target_id: str, edge_type: str, weight: float = 1.0)

Create a relationship between two memories.

Returns: None

forget(memory_id: str)

Delete a memory by its ID.

Returns: None

get_memory(memory_id: str)

Retrieve a specific memory by ID.

Returns: dict (id, content, memory_type, tags, created_at)

recall(mql_query: str)

Execute an MQL query against the database.

Returns: RecallResult (text, total_tokens, memory_count)

ingest(conversation: str, provider: str | None = None, agent_id: str | None = None)

Extract and store memories from a conversation transcript.

Returns: None

API Reference (Rust)

The Rust API provides direct access to the core storage engine.

rust
use mentedb::MenteDb;

let mut db = MenteDb::open("./data")?;

// Store a memory node
let id = db.store(memory_node)?;

// Search by similarity
let results = db.recall_similar(&embedding, k)?;

// Retrieve by ID
let node = db.get_memory(id)?;

// Delete a memory
db.forget(id)?;

// Create a relationship
db.relate(edge)?;

API Reference (Node.js)

The TypeScript SDK provides a native Node.js interface to MenteDB.

typescript
import { MenteDB } from "@mentedb/sdk";

const db = new MenteDB("./my-agent-memory");

// Store a memory
const id = await db.store("User prefers TypeScript", {
  memoryType: "semantic",
  tags: ["preference", "language"],
});

// Search by text
const results = await db.searchText("language preference", { k: 5 });

// Create a relationship
await db.relate(newId, oldId, "supersedes");

// Retrieve a memory
const memory = await db.getMemory(id);

// Delete a memory
await db.forget(id);

MQL Query Language

MQL (Mente Query Language) is a SQL-inspired query language for searching and retrieving memories.

mql
RECALL memories WHERE tag = preference LIMIT 5

RECALL memories WHERE content ~> "database" LIMIT 10

RECALL memories NEAR [0.1, 0.2, ...] LIMIT 10
WHERE tag = value

Filter memories by tag.

WHERE content ~> "text"

Fuzzy text search within memory content.

NEAR [vector]

Vector similarity search using an embedding.

LIMIT n

Restrict the number of results returned.

Graph Relationships

Memories form a directed graph through typed, weighted edges.

Edge TypeDescriptionBelief Effect
supersedesNewer memory replaces an older oneTarget marked stale
contradictsMemory conflicts with anotherTarget marked stale
supportsMemory reinforces anotherIncreases salience
related_toGeneral associationNone
caused_byCausal relationshipNone
temporal_nextSequential orderingNone

Weight: 0.0 to 1.0, representing the strength of the relationship.

Belief propagation: Supersedes and contradicts edges automatically mark their targets as stale, removing them from search results.

Graph traversal: Find paths between memories, extract subgraphs, and discover related memories through edge traversal.

Context Assembly

The ContextAssembler builds optimized context windows for LLM consumption.

U-Curve Ordering

Places high-salience memories at the start and end of the context window, where LLM attention is strongest. Lower priority items go in the middle.

Token Budget

Respects the configured max_tokens limit. Memories are ranked by salience and packed into the budget, ensuring no overflow.

Delta Mode

Tracks what was sent in previous turns. On subsequent calls, only new or changed memories are included, reducing memory retrieval tokens by ~90%.

Benchmarks

Performance measured on real workloads. See the benchmarks directory for full results.

0.29ms

Insert latency

Average time to store a memory with embedding

<1ms

Context assembly at 10K

Building a full context window from 10,000 memories

90.7%

Token savings

Reduction via delta serving in multi-turn conversations

0%

Stale beliefs

Zero stale memories returned after belief propagation

4.8x

Faster than Mem0

PASS vs FAIL on stale beliefs, both using OpenAI embeddings

10K

Scale tested

10,000 memories with 6/6 belief changes correctly tracked

MCP Server

MenteDB ships a production MCP server with 32 tools across 5 categories. Connect Claude, Cursor, or any MCP-compatible client.

Installation

bash
cargo install mentedb-mcp

Quick Setup

Auto-configure MenteDB for your client with one command. This creates the MCP config, agent instructions, and alwaysAllow list automatically.

bash
# GitHub Copilot CLI
mentedb-mcp setup copilot

# Claude Desktop
mentedb-mcp setup claude

# Cursor
mentedb-mcp setup cursor

Running

bash
mentedb-mcp --data-dir ./agent-memory

Embeddings

The server uses local Candle embeddings by default (all-MiniLM-L6-v2, 384 dimensions). No API key is required for semantic search. The model auto-downloads from Hugging Face on first use (~80MB) and falls back to hash embeddings if the download fails (offline mode).

Using an API Key (Optional)

You can optionally configure OpenAI or Anthropic for LLM-based memory extraction via the ingest_conversation tool. This is not required for search, which uses local embeddings. Set the provider and API key in your MCP client configuration.

Note: OpenAI and Anthropic are used for the ingest_conversation tool (memory extraction), not for search or embeddings.

Claude Desktop Configuration

json
{
  "mcpServers": {
    "mentedb": {
      "command": "mentedb-mcp",
      "args": ["--data-dir", "~/.mentedb", "--llm-provider", "anthropic"],
      "env": {
        "MENTEDB_LLM_API_KEY": "sk-ant-..."
      }
    }
  }
}

Cursor Configuration

json
{
  "mcpServers": {
    "mentedb": {
      "command": "mentedb-mcp",
      "args": ["--data-dir", "~/.mentedb", "--llm-provider", "anthropic"],
      "env": {
        "MENTEDB_LLM_API_KEY": "sk-ant-..."
      }
    }
  }
}

GitHub Copilot (VS Code) Configuration

json
{
  "mcpServers": {
    "mentedb": {
      "command": "mentedb-mcp",
      "args": ["--data-dir", "~/.mentedb", "--llm-provider", "anthropic"],
      "env": {
        "MENTEDB_LLM_API_KEY": "sk-ant-..."
      }
    }
  }
}

GitHub Copilot CLI Configuration

File: ~/.copilot/mcp-config.json

json
{
  "mcpServers": {
    "mentedb": {
      "command": "mentedb-mcp",
      "args": ["--data-dir", "~/.mentedb"],
      "alwaysAllow": [
        "store_memory", "get_memory", "recall_memory", "search_memories",
        "relate_memories", "forget_memory", "forget_all", "ingest_conversation",
        "assemble_context", "get_related", "find_path", "get_subgraph",
        "find_contradictions", "propagate_belief", "consolidate_memories",
        "apply_decay", "compress_memory", "evaluate_archival", "extract_facts",
        "gdpr_forget", "process_turn", "record_pain", "detect_phantoms",
        "resolve_phantom", "record_trajectory", "predict_topics",
        "detect_interference", "check_stream", "write_inference",
        "register_entity", "get_cognitive_state", "get_stats"
      ]
    }
  }
}

The alwaysAllow list lets memory tools run without approval prompts. Remove it if you prefer manual approval per tool call. To add LLM extraction, add --llm-provider and env as shown above.

Generated Agent Instructions

The mentedb-mcp setupcommand writes the following instructions to your agent's config (e.g. copilot-instructions.md). This is what teaches the LLM to use MenteDB automatically:

markdown
# Memory

You have persistent memory via MenteDB. Use it automatically, never wait to be asked.

## Every turn (MANDATORY)

Call `process_turn` on EVERY conversation turn. This is the core memory loop:
- Pass the user's message and your response
- Increment `turn_id` each turn (start at 0)
- It automatically: searches relevant context, stores the conversation as searchable
  episodic memory, runs pain/contradiction checks, and returns context + warnings

On the FIRST turn, also call `get_cognitive_state` to check for active pain signals
or knowledge gaps.

## Store important facts yourself (MANDATORY)

YOU are the extraction engine. When you notice important information in the
conversation, call `store_memory` immediately:
- Preferences: "User prefers Rust for backends" → type: semantic, tags: [preference]
- Decisions: "Using PostgreSQL for the database" → type: semantic, tags: [decision]
- Corrections: "Actually the deadline is April" → type: correction
- Procedures: "Deploy with: cargo build --release" → type: procedural
- Mistakes: "Never retag releases" → type: anti_pattern

Don't store noise or chitchat. Store facts, preferences, decisions, and corrections.

## When to use other tools

- `search_memories`: Look up something specific outside of process_turn
- `record_pain`: When something goes wrong (bad advice, failed approach)
- `relate_memories`: When a fact changes, store new and relate with `supersedes`
- `forget_memory`: When the user says "forget" or "don't remember"

## Memory types

- semantic: facts, decisions, preferences, project details (most common)
- episodic: events, meetings, what happened (process_turn handles this)
- procedural: how to do things, workflows, commands
- correction: when the user corrects you
- anti_pattern: mistakes to avoid

## Tags

Always add tags. Use lowercase, descriptive tags like:
- Project names: project-mentedb, project-trading-bot
- Topics: database, deployment, testing, preference
- Context: decision, architecture, bug-fix

CLI Flags

--data-dir

Path to the data directory for storing memories.

Default: ./mente-data

--llm-provider

LLM provider for memory extraction (ingest). Supported: openai, anthropic.

Default: None

--llm-api-key

API key for the configured LLM provider.

Default: None

--llm-model

Model name for the configured LLM provider.

Default: Provider default

Environment Variables

MENTEDB_LLM_API_KEY

API key for the LLM provider. Overridden by --llm-api-key if both are set.

Default: None

MENTEDB_LLM_PROVIDER

LLM provider name. Overridden by --llm-provider if both are set.

Default: None

Agent Instructions

The mentedb-mcp setup command injects agent instructions that teach your LLM how to use MenteDB automatically. The instructions tell the LLM to:

  • Call process_turn on every conversation turn — this searches for relevant context, stores the conversation as episodic memory, and checks pain signals
  • Call store_memory when it recognises important information — preferences, decisions, corrections, procedures, anti-patterns
  • Use appropriate memory types (semantic, episodic, procedural, correction, anti_pattern) and descriptive tags
  • Use record_pain, relate_memories, and forget_memory when appropriate

The conversation LLM is the extraction engine — no second model or API key is needed. process_turnhandles the plumbing (search, store, warn), while the LLM handles the intelligence (what's worth remembering as structured data).

All 30 Tools by Category

Memory6 tools
storesearchrecallgetforgetingest
Search3 tools
search_textsearch_vectorsearch_by_tag
Graph6 tools
relateget_relatedfind_pathget_subgraphfind_contradictionspropagate_belief
Consolidation6 tools
consolidateapply_decaycompressevaluate_archivalextract_factsgdpr_forget
Cognitive8 tools
record_paindetect_phantomsresolve_phantomrecord_trajectorypredict_topicsdetect_interferencecheck_streamwrite_inference

Configuration

MenteDB can be configured via command-line arguments and environment variables.

--data-dir

Path to the data directory. Also accepts the first positional argument.

Default: ./mente-data

Embedding Dimensions

Dimensionality of stored embeddings. Handled automatically by the local Candle model.

Default: 384 (Candle local model)

HNSW: M

Maximum number of connections per node in the HNSW graph. Higher values improve recall at the cost of memory.

Default: 16

HNSW: ef_construction

Size of the dynamic candidate list during index construction. Higher values produce a better index but take longer.

Default: 200

HNSW: ef_search

Size of the dynamic candidate list during search. Higher values improve recall at the cost of speed.

Default: 50

--llm-provider

LLM provider for memory extraction via the ingest function. Supported: openai, anthropic.

Default: None

--llm-api-key

API key for the configured LLM provider.

Default: None