Hierarchical memory model
Sessions hold conversations, conversations hold topics, topics hold exchanges. Four levels of grouping so retrieval scopes to the right slice instead of dumping the whole history.
Alpha on PyPI · MCP server included
Memorg is a Python library that stores, organises, and retrieves context for LLM apps. Sessions and topics on top of SQLite, semantic search via USearch and OpenAI embeddings, token-budget-aware retrieval, and an MCP server out of the box.
# pip install memorg (Python 3.11+)
from memorg import MemorgSystem
from memorg.storage.sqlite_storage import SQLiteStorageAdapter
from memorg.vector_store.usearch_vector_store import USearchVectorStore
from openai import AsyncOpenAI
system = MemorgSystem(
storage=SQLiteStorageAdapter("memory.db"),
vector_store=USearchVectorStore("memory.db"),
openai_client=AsyncOpenAI(),
)
session = await system.create_session("user_123", {})
conversation = await system.start_conversation(session.id)
results = await system.search_context("what did we discuss about the API?") 4 levels
session · conversation · topic · exchange
SQLite + USearch
one file. no managed services.
MIT
pip install memorg · Python 3.11+
What is Memorg?
Memorg is a pip-installable Python library (MIT, Python 3.11+) that gives an LLM app durable, structured memory. It combines a four-level hierarchy — session → conversation → topic → exchange — with a USearch vector index and OpenAI embeddings, all in a single SQLite file. Retrieval blends semantic similarity, recency, and importance, then trims results to a per-session token budget so the model gets the most useful context that still fits its window.
The problem
What you get
Sessions hold conversations, conversations hold topics, topics hold exchanges. Four levels of grouping so retrieval scopes to the right slice instead of dumping the whole history.
Every exchange is embedded with an OpenAI model and stored in a USearch index alongside SQLite. Searches return the most semantically relevant context, not the most recent.
Results are ranked by a deterministic blend of semantic similarity, recency, and importance, so a decision from yesterday outweighs an aside from last week.
A built-in token counter fits returned context to the model window you set when creating the session, so the LLM gets the most useful payload that still fits.
Memory items can be documents, notes, or arbitrary tagged blobs. Search across types or scope to one kind. The chat hierarchy is the default, not the cage.
SQLite for persistence, USearch for the vector index — both in a single file you can copy. No managed service required to develop or ship.
A FastMCP server ships with the package so Claude, Cursor, and other MCP-aware clients can read and write Memorg without bespoke glue code.
Architecture
Your app calls Memorg; Memorg persists to a single file that combines SQLite storage and a USearch index, embeds text with OpenAI, and can expose an MCP server. No separate vector database.
Use cases
Keep a chat coherent across turns, sessions, and days without stuffing the whole history into every prompt.
→Move past a bare vector store to retrieval that understands users, sessions, recency, and importance.
→Drop deterministic recall next to any orchestrator without adopting a whole agent runtime.
→Give a support assistant per-customer recall so it stops asking for context the customer already gave.
→Store documents, notes, and arbitrary items alongside conversations and search across them.
→Honest comparisons
Memory is a crowded space. These are the projects teams ask about most — read the trade-offs, including where the other tool is the better answer.
The best-known managed memory layer with a hosted offering and an LLM-driven extraction pipeline. Memorg is library-first, deterministic, and runs entirely on your machine.
A full agent runtime with a memory abstraction baked in. Memorg is just the memory layer; bring whatever agent loop you already use.
A memory service built on a temporal knowledge graph, with a hosted cloud offering. Memorg is a local-first, single-file SQLite library with deterministic retrieval and no separate service to run.
FAQ
No. It is a Python library that uses a vector index (USearch) and a relational store (SQLite) together. The vector index handles similarity search; SQLite holds the hierarchy, metadata, and the source-of-truth content. You get vector recall without running a vector DB.
A blended one. Queries are embedded with OpenAI, USearch returns nearest neighbours, and results are re-scored with importance and recency before being trimmed to the session token budget. There is no LLM reranker by default — the scoring is deterministic.
Memorg ships with an OpenAI client integration for embeddings and chat. The MCP server exposes Memorg to any MCP-aware client (Claude Desktop, Cursor, etc.). For other providers you can use Memorg as a library and feed the retrieved context into whatever generation call you already make.
Storage and vector search are local. Embedding and generation call OpenAI, which requires a network and an OPENAI_API_KEY. Swapping in another embedder is a contained change because the vector store interface is small.
USearch keeps the index small and fast even at millions of items, and SQLite handles the metadata fine at that scale. The practical limit is your embedding budget and how aggressively you prune low-importance items.
pip install memorg. Python 3.11+. Dependencies include openai, tiktoken, aiosqlite, numpy, usearch, and fastmcp. No native services to run.
The package is published on PyPI and the project is in alpha (per its own classifier). The data model, retrieval API, and MCP server are stable enough to build on; expect refinements at the edges.
Those frameworks include memory as one feature among many. Memorg is just the memory layer — a small surface area you can drop next to any orchestrator. It does not own your prompts, your tools, or your agent loop.
Explore Memorg
The rest of the site: the full feature set, the architecture, the reasoning behind the design, and reference material.
The full feature set — hierarchy, semantic search, blended ranking, token budget, single-file SQLite, and the MCP server.
The architecture end to end: the four-level hierarchy, SQLite + USearch storage, embeddings, and the retrieval path.
Install with pip, create a session, store exchanges, and call search_context() — a copy-paste walkthrough.
Where Memorg fits: chat continuity, upgrading naive RAG, agent memory, support-bot recall, and documents as memory.
Honest trade-offs against Mem0, Letta (MemGPT), and Zep — including where the other tool is the better answer.
Answers grouped by basics, retrieval, operations, and integration — read before you pip install.
Plain-language definitions of the core concepts: sessions, topics, exchanges, memory items, blended retrieval, and more.
The design thesis — why memory should be infrastructure, not a framework, and why Memorg is built the way it is.
Engineering essays on memory design: forgetting as a feature, agents vs chatbots, and the 50-line-bandage problem.
Drop Memorg next to your LLM client, point it at a SQLite file, and call search_context() when you need recall. That is the whole API.