Skip to main content

Memory System for AI Conversations

Project description

AIMemo

Memory System for AI Conversations

AIMemo is a lightweight memory layer that enables AI agents to remember context across conversations. Build AI applications that truly understand and remember your users.

PyPI version License: MIT

🚀 Features

  • Automatic Memory: Intercepts LLM calls and injects relevant context
  • Multiple Backends: SQLite, PostgreSQL support out of the box
  • Zero Config: Works with sensible defaults, configure when needed
  • LLM Agnostic: Supports OpenAI, Anthropic, and more
  • Namespace Isolation: Perfect for multi-user applications
  • Full-Text Search: Fast memory retrieval with FTS5/PostgreSQL search

📦 Installation

pip install aimemo

For PostgreSQL support:

pip install aimemo[postgres]

⚡ Quick Start

from aimemo import AIMemo
from openai import OpenAI

# Initialize AIMemo
aimemo = AIMemo()
aimemo.enable()

# Use OpenAI normally - memory is automatic!
client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "I'm building a FastAPI project"}]
)

# Later conversation - context is automatically injected
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "How do I add authentication?"}]
)
# The model remembers your FastAPI project!

💡 Use Cases

  • Personal AI Assistants: Remember user preferences and history
  • Customer Support Bots: Maintain context across support sessions
  • Research Assistants: Keep track of research topics and findings
  • Multi-Agent Systems: Share memory between multiple AI agents
  • Learning Apps: Track student progress and learning patterns

🔧 Configuration

Database Options

SQLite (default):

from aimemo import AIMemo

aimemo = AIMemo()  # Uses aimemo.db by default

PostgreSQL:

from aimemo import AIMemo, PostgresStore

store = PostgresStore("postgresql://user:pass@localhost/aimemo")
aimemo = AIMemo(store=store)

Environment Variables

export AIMEMO_DB_PATH="./my_memory.db"
export AIMEMO_MAX_CONTEXT=10

Manual Memory Management

from aimemo import AIMemo

aimemo = AIMemo(namespace="user_123")

# Add memories manually
aimemo.add_memory(
    content="User prefers dark mode",
    tags=["preference", "ui"],
    metadata={"priority": "high"}
)

# Search memories
results = aimemo.search("dark mode", limit=5)

# Get formatted context
context = aimemo.get_context("user interface preferences")

Multi-User Applications

from aimemo import AIMemo

# Each user gets their own namespace
user_memory = AIMemo(namespace=f"user_{user_id}")
user_memory.enable()

# Memories are isolated per user

📚 Examples

Check out the examples/ directory:

  • basic_usage.py - Simple conversation with memory
  • manual_memory.py - Manual memory management
  • postgres_example.py - Using PostgreSQL backend
  • context_manager.py - Context manager pattern

🧪 Testing

pip install pytest
pytest tests/

🛠️ Development

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black aimemo tests examples

📖 Documentation

Core API

AIMemo

  • enable() - Start intercepting LLM calls
  • disable() - Stop intercepting
  • add_memory(content, metadata, tags) - Add memory manually
  • search(query, limit) - Search memories
  • get_context(query, limit) - Get formatted context
  • clear(namespace) - Clear memories

Storage Backends

  • SQLiteStore(db_path) - SQLite storage
  • PostgresStore(connection_string) - PostgreSQL storage

Architecture

AIMemo works by intercepting LLM API calls:

  1. Pre-call: Searches relevant memories based on user query
  2. Injection: Adds context to the conversation
  3. Post-call: Stores the conversation for future reference

All automatically, with zero code changes!

🤝 Contributing

Contributions welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - see LICENSE file for details.

🙋 Support


Built with ❤️ by Jason

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

aimemo-1.0.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

aimemo-1.0.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file aimemo-1.0.1.tar.gz.

File metadata

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

File hashes

Hashes for aimemo-1.0.1.tar.gz
Algorithm Hash digest
SHA256 48acd96929275cd1241553c9117778ee30abf5d6431a6e3317860504dafaf1fc
MD5 cf923b8587d24e259cc73d4ded88a834
BLAKE2b-256 7b8e3f0fa3549e0bf982c5cbad545b62ebf1370cf8a517fa70b261bd950358bc

See more details on using hashes here.

File details

Details for the file aimemo-1.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for aimemo-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 694f38e8a0c1e2fab3ac8dfb26661d97f365b2ef1023fa86366396d57fa10a2d
MD5 6629f6ebe4cff9a9ca899f35f25723ba
BLAKE2b-256 7c2e73b3a2d431830226458d1ca6c70c1c751906105c9fb7a5bc4ae11d2fa153

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