$ show mem0ai/mem0
Mem0 is a production-grade memory layer for AI agents, providing persistent, searchable, and updatable memory across sessions. It operates as both an open-source Python/TypeScript SDK and a hosted platform (api.mem0.ai). The core library abstracts away LLM providers (OpenAI, Anthropic, Groq, vLLM, etc.), embedding models, vector stores (over 20 backends including Qdrant, Pinecone, PGVector, Chroma, Weaviate, and many more), and rerankers behind a consistent config-driven interface. Memory operations (add, search, update, delete) support scoping by user, agent, session, or run, and leverage hybrid search combining semantic, BM25, and entity-boost signals with configurable reranking. The repository is architected as a monorepo with a clear separation of concerns: the core SDK packages (`mem0/` for Python, `mem0-ts/` for TypeScript), a self-hosted FastAPI server with a Next.js dashboard, CLI tools in both Python and Node.js, and a comprehensive plugin ecosystem for AI coding agents (Claude Code, Cursor, Codex, Kimi, Antigravity, Pi Agent, OpenClaw, etc.). Each integration follows a uniform hook adapter pattern, translating native agent events into memory operations via MCP servers or shared core modules. The platform backend includes authentication, API key management, telemetry via PostHog, and a webhook system for event-driven workflows. Key data flows: An application calls `memory.add()` with messages and metadata → the SDK extracts facts via an LLM → embeds them using the configured embedder → stores vectors and metadata in the chosen vector store. On `memory.search()`, the query is embedded, hybrid-scored against stored vectors (with optional reranking), and results are returned with relevance scores. The system supports temporal reasoning (timestamp filtering, memory decay), entity-based partitioning, custom categories, and feedback mechanisms to refine future retrievals. External dependencies include LLM APIs, vector databases, embedding services, and optionally Redis/SQLite for local history.
The LLM identified 5 files worth highlighting for reuse:
Hybrid scoring utility that combines semantic similarity, BM25 keyword scores, and entity boost signals into a single relevance score. Includes sigmoid normalization, adaptive divisor, threshold gating, and an explainability flag (`score_details`). Demonstrated in both Python and TypeScript implementations; extraction requires only the scoring logic and a few imports from `math`.
Abstract base class for all LLM providers. Detects reasoning models (e.g., o1, deepseek-reasoner) and automatically swaps `max_tokens` for `max_completion_tokens`, drops `top_p`, and filters unsupported parameters. Subclasses only implement `generate_response()` and `_parse_response()`. The `_get_supported_params()` method enables clean forward-compatibility. This pattern is reusable across any multi-provider LLM integration.
Output formatter for the Node.js CLI that supports text, JSON, table, agent-envelope, and plain modes. Uses ANSI colors and a rich panel layout for help text. Sanitizes output per command (e.g., entity lists, config keys). The formatter is completely self-contained with no internal imports beyond `branding.ts`. Can be extracted as a standalone CLI output library for TypeScript tools.
Plugin build orchestrator that assembles a plugin bundle from source files, validates the plugin schema against JSON schemas (mcp.schema.json, plugin.schema.json), computes a content hash, and outputs a structured build manifest. Supports portable mode (bundled core) and native mode (external core). The validation logic is schema-driven and reusable for any agent plugin that follows the MCP/plugin manifest conventions.
Text lemmatization utility for BM25 preprocessing. Removes stop words, punctuation, and applies simple suffix stripping (e.g., '-ing', '-ed', '-ly', '-er', '-est', '-ness', '-ment', '-ation'). Does not rely on external NLP libraries, making it lightweight and portable. Useful for any text retrieval system that benefits from normalization before keyword indexing.