{"id":16436,"library":"mentedb","title":"MenteDB: AI Agent Memory Database","description":"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.","status":"active","version":"0.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/nambok/mentedb","tags":["javascript","database","ai","agents","memory","rust","vector","knowledge-graph","typescript"],"install":[{"cmd":"npm install mentedb","lang":"bash","label":"npm"},{"cmd":"yarn add mentedb","lang":"bash","label":"yarn"},{"cmd":"pnpm add mentedb","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"MenteDB is an ESM-first package. CommonJS 'require' syntax is not supported for direct imports and will lead to errors.","wrong":"const MenteDB = require('mentedb');","symbol":"MenteDB","correct":"import { MenteDB } from 'mentedb';"},{"note":"Enums like MemoryType are exported as named exports.","wrong":null,"symbol":"MemoryType","correct":"import { MemoryType } from 'mentedb';"},{"note":"CognitionStream is a named export, not a default export.","wrong":"import CognitionStream from 'mentedb';","symbol":"CognitionStream","correct":"import { CognitionStream } from 'mentedb';"},{"note":"Enums like EdgeType are exported as named exports.","wrong":null,"symbol":"EdgeType","correct":"import { EdgeType } from 'mentedb';"}],"quickstart":{"code":"import { MenteDB, MemoryType, EdgeType, CognitionStream, TrajectoryTracker } from 'mentedb';\n\n// Initialize your embedding model (example placeholder)\nconst embeddingFromYourModel = Array(1536).fill(0.123);\nconst queryEmbedding = Array(1536).fill(0.456);\n\nasync function runMenteDB() {\n  // Open or create a database\n  const db = new MenteDB('./my-agent-memory-data');\n  console.log('MenteDB initialized.');\n\n  // Store a memory\n  const id = db.store({\n    content: 'The deploy key rotates every 90 days',\n    memoryType: MemoryType.Semantic,\n    embedding: embeddingFromYourModel,\n    tags: ['infra', 'security'],\n  });\n  console.log(`Stored memory with ID: ${id}`);\n\n  // Vector similarity search\n  const hits = db.search(queryEmbedding, 2);\n  console.log('Search hits:', hits);\n\n  // MQL recall with token budget\n  const ctx = db.recall('RECALL similar(\"deploy key rotation\") LIMIT 10');\n  console.log('Recall context:', ctx.text, `(${ctx.totalTokens} tokens)`);\n\n  // Relate memories (assuming 'otherId' exists, e.g., from another store call)\n  // const otherId = db.store({ content: 'Another related fact', memoryType: MemoryType.Semantic, embedding: embeddingFromYourModel });\n  // db.relate(id, otherId, EdgeType.Supersedes);\n  // console.log(`Related ${id} to ${otherId}`);\n\n  // Simulate an LLM token stream for cognition\n  const stream = new CognitionStream();\n  const llmTokens = ['Hello', ' ', 'world', '!'];\n  for (const token of llmTokens) {\n    stream.feedToken(token);\n  }\n  console.log('Drained CognitionStream buffer:', stream.drainBuffer());\n\n  // Track reasoning trajectory\n  const tracker = new TrajectoryTracker();\n  tracker.recordTurn('Discuss JWT auth', 'investigating', ['Which algorithm?', 'Token lifetime?']);\n  tracker.recordTurn('Token lifetime', 'decided:15 minutes');\n  console.log('Resume context:', tracker.getResumeContext());\n  console.log('Predicted next topics:', tracker.predictNextTopics());\n\n  // Forget a memory\n  db.forget(id);\n  console.log(`Forgot memory with ID: ${id}`);\n\n  // Close the database\n  db.close();\n  console.log('MenteDB closed.');\n}\n\nrunMenteDB().catch(console.error);","lang":"typescript","description":"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."},"warnings":[{"fix":"Always pin to exact versions (e.g., `npm install mentedb@0.3.1`) and thoroughly review release notes before upgrading in production environments. Regular dependency audits are recommended.","message":"As a pre-1.0 release (currently v0.3.1), MenteDB's API is subject to frequent changes. Major and minor version bumps may introduce breaking changes without extensive migration guides.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Ensure Rust and `napi-rs` are installed as per the `mentedb` README. Check `npm install` logs for specific compilation errors related to the native addon. Run `npm run build` in the `sdks/typescript` directory if troubleshooting.","message":"If a prebuilt native binary is not available for your platform, `npm install` may fail. Building from source requires Rust and the `napi-rs` toolchain to be installed and correctly configured on your system.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Develop or integrate an embedding generation service (e.g., OpenAI, Cohere, custom model) to produce numerical vector representations of your memory content and queries. Pass these `number[]` arrays to `db.store()` and `db.search()`.","message":"MenteDB's `store` and `search` methods rely on external embedding vectors. You must integrate a separate AI model (e.g., an LLM embedding API) to generate these `number[]` arrays before interacting with the database.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Install Rust and `napi-rs` build tools, then try installing again. Alternatively, check the GitHub releases for prebuilt binaries for your specific platform or consult the project's documentation for supported environments.","cause":"The `mentedb` package includes a native Node.js addon, and `npm install` failed to find a precompiled binary for your operating system and architecture.","error":"Error: No prebuilt binary for your platform..."},{"fix":"Ensure your project is configured for ES Modules (add `\"type\": \"module\"` to `package.json`) and use `import { MenteDB } from 'mentedb';` syntax.","cause":"This error typically occurs when attempting to use CommonJS `require()` syntax to import `mentedb`, which is an ESM-first package.","error":"TypeError: MenteDB is not a constructor"},{"fix":"Verify the `dataDir` path exists and is writable by the Node.js process. Ensure no other process is actively using the same database directory. If corruption is suspected, try deleting the directory and restarting (losing data).","cause":"The specified `dataDir` path for `new MenteDB(dataDir)` is invalid, lacks write permissions, or points to a corrupted database file.","error":"Error: Failed to open database at path..."}],"ecosystem":"npm"}