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.1.tar.gz (29.4 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.1-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: om_memory-0.2.1.tar.gz
  • Upload date:
  • Size: 29.4 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.1.tar.gz
Algorithm Hash digest
SHA256 f24e690ca6589e0b21e366088755c9d3acf2e0d590d0b35c43fe4c484ac2a1a7
MD5 41986d06ea06a0bf576bee19e734680d
BLAKE2b-256 a7a65bebc990bb3a050de91feb6f643aa1891f5d4ab16fa0c7810da2bb3b1b9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: om_memory-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 36.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f258869fc820e2990ef0d89dea806d9fedefcaa6b93e15a9de870d925fb76244
MD5 a06eb64e4fdfdb277cf60762371786c1
BLAKE2b-256 ec21e0af6eb543286c29a3a986e7c811624d0c05cc72c4c1841adc6de80423a5

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