Skip to main content

Human-like memory for AI agents. 10x cheaper than RAG. Zero vector DB needed.

Project description

om-memory

License Python Versions PyPI Version

Human-like memory for AI agents. 10x cheaper than RAG. Zero vector DB needed.

om-memory is the first-ever Python implementation of Observational Memory (OM) — a revolutionary approach to AI agent memory. Instead of embedding every message and retrieving similar ones per turn (RAG), OM continuously compresses conversation history into a dense, evolving text log of "observations" using two background agents (Observer and Reflector).

What is Observational Memory?

Observational Memory (OM) maintains a stable text context window of the user's conversation. The observation log is plain text that stays stable in the context window, enabling prompt caching (75-90% token cost discount from providers like OpenAI/Anthropic). Traditional RAG injects different retrieved chunks every turn, breaking the cache and costing up to 10x more.

Why om-memory?

  • 10x Cheaper than RAG: By leveraging prompt caching on a stable context window.
  • Zero Vector DB Needed: Uses standard storage backends (SQLite, Postgres, etc.) — no embeddings, no vector search.
  • Better Accuracy: Maintains narrative continuity better than fragmented vector retrieval (Highest recorded on LongMemEval).
  • Framework-Agnostic: Middleware pattern. om-memory manages context, you make your own LLM calls with LangChain, LlamaIndex, or raw Python.
  • Observable by Default: Full event tracking, metrics, and Streamlit dashboard integration.

Quick Start

om-memory provides sensible defaults out of the box (SQLite storage, OpenAI gpt-4o-mini for background compression).

import asyncio
from om_memory import ObservationalMemory

async def main():
    # 1. Initialize OM (Zero config needed, uses SQLite + OPENAI_API_KEY)
    om = ObservationalMemory()
    
    # 2. Get context for a user thread
    thread_id = "user_123"
    context = await om.aget_context(thread_id=thread_id)
    
    # 3. Build your prompt and call YOUR LLM
    prompt = f"System: You are a helpful assistant.\n{context}\nUser: Hello!"
    response = "Hello! How can I help you today?" # Replace with actual LLM call
    
    # 4. Tell OM what happened so it can remember for next time
    await om.aadd_message(thread_id=thread_id, role="user", content="Hello!")
    await om.aadd_message(thread_id=thread_id, role="assistant", content=response)

if __name__ == "__main__":
    asyncio.run(main())

How It Works

  1. Block 1 (Observations): A compressed, timestamped log of facts, decisions, and preferences. Handled by the Reflector agent.
  2. Block 2 (Recent Messages): The uncompressed recent turns of the conversation. Once this grows past a threshold, the Observer agent compresses it into Block 1.

Installation

pip install om-memory

Optional dependencies:

  • pip install om-memory[anthropic] - Anthropic provider support
  • pip install om-memory[postgres] - PostgreSQL storage backend
  • pip install om-memory[dashboard] - Streamlit dashboard

Documentation

Full documentation available in the repository examples.

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

om_memory-0.2.4.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

om_memory-0.2.4-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file om_memory-0.2.4.tar.gz.

File metadata

  • Download URL: om_memory-0.2.4.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for om_memory-0.2.4.tar.gz
Algorithm Hash digest
SHA256 439bcf69ad258379983627c4d471d0789c3e1e184eb288f3527ff3113b99f0e8
MD5 e7a38eeeed74e40bc35e7ebb6c410ea7
BLAKE2b-256 7ea05a98f907eb440f88781ebd8e5991eccd63ffd1592c5590aa3179a18481e7

See more details on using hashes here.

File details

Details for the file om_memory-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: om_memory-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for om_memory-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e4e60752922ee21a8082544ce480cf04fd9603cea58a2c116d203ff55d4c9fb0
MD5 af9fda759bba0887427f5b35833cb878
BLAKE2b-256 53a92ce767bba404f0d2c0f574bc3bacc87a39d13fc1d7cf94eb991a6fd7f9d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page