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.
🚀 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 callsdisable()- Stop interceptingadd_memory(content, metadata, tags)- Add memory manuallysearch(query, limit)- Search memoriesget_context(query, limit)- Get formatted contextclear(namespace)- Clear memories
Storage Backends
SQLiteStore(db_path)- SQLite storagePostgresStore(connection_string)- PostgreSQL storage
Architecture
AIMemo works by intercepting LLM API calls:
- Pre-call: Searches relevant memories based on user query
- Injection: Adds context to the conversation
- 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
- GitHub Issues: Bug reports and feature requests
- Email: jason@example.com
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aimemo-1.0.0.tar.gz.
File metadata
- Download URL: aimemo-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2559149b2ada9f5a0f284f7e7a8b8dac8652da522ba14d77f715950c476e31e
|
|
| MD5 |
f736c7283dacaaf7eaf9cd18f8e8ad3f
|
|
| BLAKE2b-256 |
ccded5f4ea002ea00415378763a6ddceb642a84fea3a20e46f6927995ef21785
|
File details
Details for the file aimemo-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aimemo-1.0.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efbd33d15a1a68eab187c6d9f57a8889e39bca90adeaf921c10b3618fb763948
|
|
| MD5 |
9ce973040509b80318d100f0c38d08ca
|
|
| BLAKE2b-256 |
6cc5e923171a9c67ef5b8a3337a3540946b9f4498bda0afd13c805084f50a332
|