How yashghogre/mem1 works
Project type and purpose
• This is an open-source Python tool/prototype that replicates the “Mem0” LLM memory architecture (per the Mem0 paper) and tries to extend or outperform it.
• It has two main code modules:
• mem1/ – the core memory library (embedders, vector store, graph database, schemas, retrieval logic)
• assistant/ – the orchestration/service layer (CLI entrypoint, config, infra adapters, utils, telemetry via Langfuse)
File structure
• Top level: Dockerfile, docker-compose.yml, justfile (CLI), .env, config.py, pyproject.toml
• mem1/:
• core.py – main memory pipeline
• infra/ (database adapters: Mongo, vector DB, graph DB; embedder; schema)
• utils/ (enums, models, prompts)
• assistant/:
• main.py – CLI/web server entrypoint
• infra/ (wrappers around mem1’s infra with dependency injection)
• deps/ (third-party integrations like Langfuse telemetry)
• utils/ (logging, context handling, special commands)
README for additional insights
• Uses Nix for environment, uv (uvu?) for dependency syncing, Docker Compose for MongoDB and vector DB services
• Runs as a long-lived Python process (CLI or API), connects to LLM via API (no local Llama now)
• Persists embeddings & metadata to vector store and primary DB, supports prompt augmentation
Components
a. User/CLI (just app) – initiates the run, issues prompts
b. Docker Compose – orchestrates MongoDB, vector DB (e.g., Qdrant/Pinecone emulator)
c. Python Application (assistant/main.py + assistant infra)
d. Core Memory Library (mem1/core.py + mem1/infra modules)
e. Embedder & Inference
• mem1.infra.embedder → calculates vector embeddings (via OpenAI API)
• mem1.infra.inference → wraps LLM API calls for response generation
f. Datastores
• MongoDB (document store for session history, schemas)
• Vector DB (nearest-neighbor search)
• Graph DB (optional knowledge graph for relationships)
g. Telemetry/Logging (Langfuse via assistant/deps)
h. External LLM API (OpenAI or other HTTP endpoint)
Relationships & data flows
• User→CLI→Python App
• App calls mem1.core for pipeline orchestration
• Core calls embedder → External LLM API (for embeddings)
• Core calls inference → External LLM API (for next-token generation)
• Core writes/reads to/from Vector DB and MongoDB / Graph DB
• App emits telemetry events via Langfuse
• Responses return back up chain to the user
Architectural patterns & design principles
• Layered architecture:
• Presentation/CLI layer (assistant/main.py)
• Service/orchestration layer (assistant/infra + utils)
• Core library layer (mem1/core + mem1/infra)
• Infrastructure adapters (datastores, LLM API)
• Dependency injection in assistant/infra to swap adapters during testing
• Modular separation of memory logic (mem1) vs. orchestration (assistant)
• Externalize configuration via .env and config.py
• Containerized dependencies (Mongo, vector DB) via Docker Compose