MenteDB: AI Agent Memory Database

0.3.1 · active · verified Wed Apr 22

MenteDB is a purpose-built database engine designed for AI agent memory, providing capabilities like vector similarity search, a typed knowledge graph, token budget-aware context assembly, contradiction detection, and trajectory tracking. It delivers its full Rust-based engine as a native Node.js addon via `napi-rs`, offering zero runtime dependencies for prebuilt binaries. The package is currently at version 0.3.1, indicating an early development stage with potentially rapid API evolution. It releases frequently, with minor versions and bug fixes appearing regularly across its main package and internal sub-packages like `mentedb-storage` and `mentedb-query`. Its key differentiators include its focus on agent-specific cognitive features and its performance benefits from the Rust-native implementation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize MenteDB, store and search memories with embeddings, perform MQL recalls, and utilize its cognitive features like CognitionStream and TrajectoryTracker.

import { MenteDB, MemoryType, EdgeType, CognitionStream, TrajectoryTracker } from 'mentedb';

// Initialize your embedding model (example placeholder)
const embeddingFromYourModel = Array(1536).fill(0.123);
const queryEmbedding = Array(1536).fill(0.456);

async function runMenteDB() {
  // Open or create a database
  const db = new MenteDB('./my-agent-memory-data');
  console.log('MenteDB initialized.');

  // Store a memory
  const id = db.store({
    content: 'The deploy key rotates every 90 days',
    memoryType: MemoryType.Semantic,
    embedding: embeddingFromYourModel,
    tags: ['infra', 'security'],
  });
  console.log(`Stored memory with ID: ${id}`);

  // Vector similarity search
  const hits = db.search(queryEmbedding, 2);
  console.log('Search hits:', hits);

  // MQL recall with token budget
  const ctx = db.recall('RECALL similar("deploy key rotation") LIMIT 10');
  console.log('Recall context:', ctx.text, `(${ctx.totalTokens} tokens)`);

  // Relate memories (assuming 'otherId' exists, e.g., from another store call)
  // const otherId = db.store({ content: 'Another related fact', memoryType: MemoryType.Semantic, embedding: embeddingFromYourModel });
  // db.relate(id, otherId, EdgeType.Supersedes);
  // console.log(`Related ${id} to ${otherId}`);

  // Simulate an LLM token stream for cognition
  const stream = new CognitionStream();
  const llmTokens = ['Hello', ' ', 'world', '!'];
  for (const token of llmTokens) {
    stream.feedToken(token);
  }
  console.log('Drained CognitionStream buffer:', stream.drainBuffer());

  // Track reasoning trajectory
  const tracker = new TrajectoryTracker();
  tracker.recordTurn('Discuss JWT auth', 'investigating', ['Which algorithm?', 'Token lifetime?']);
  tracker.recordTurn('Token lifetime', 'decided:15 minutes');
  console.log('Resume context:', tracker.getResumeContext());
  console.log('Predicted next topics:', tracker.predictNextTopics());

  // Forget a memory
  db.forget(id);
  console.log(`Forgot memory with ID: ${id}`);

  // Close the database
  db.close();
  console.log('MenteDB closed.');
}

runMenteDB().catch(console.error);

view raw JSON →