Long-term memory for AI Agents
Project description
Soika Memory - Long-term Memory for AI Agents
Soika Memory is a comprehensive memory management system that provides long-term memory capabilities for AI agents and applications. It enables storage, retrieval, and semantic search of conversation history and contextual information using vector databases and graph networks.
Features
๐ง Core Memory Management
- Create memories: Store conversation messages and context for users, agents, or runs
- Retrieve memories: Get all memories with flexible filtering options
- Search memories: Semantic search through stored memories using vector similarity
- Update memories: Modify existing memories with new information
- Delete memories: Remove specific memories or bulk delete with filters
๐ Graph Memory
- Knowledge Graph: Extract entities and relationships from conversations
- Graph Search: Find related information through entity relationships
- Multiple Graph Stores: Support for Neo4j, Memgraph, and AWS Neptune
๐ Multiple LLM Providers
- OpenAI: GPT models with structured output support
- Azure OpenAI: Enterprise-grade OpenAI integration
- Anthropic: Claude models
- Google Gemini: Gemini Pro models
- Groq: High-speed inference
- DeepSeek: Cost-effective models
- XAI: Grok models
- SoikaStack: Integrated AI framework with multi-model support
๐ Vector Store Support
- Qdrant: Default vector database
- Pinecone: Managed vector database
- Chroma: Open-source vector database
- PGVector: PostgreSQL with vector extension
- Google Vertex AI: Vector search
- Baidu: Chinese market support
- LangChain: Framework integration
๐ Flexible Deployment
- REST API: FastAPI-based server with OpenAPI documentation
- Python Client: Sync and async client libraries
- Proxy Integration: Memory-enhanced OpenAI API proxy
- Docker Support: Container deployment
Quick Start
Installation
pip install ai-memory
Or with optional dependencies:
# With graph support
pip install memory[graph]
# With all vector stores
pip install memory[vector_stores]
# Full installation
pip install memory[graph,vector_stores]
Basic Usage
from soika_memory import Memory
# Initialize memory with SoikaStack provider
m = Memory(
config={
"llm": {
"provider": "soikastack",
"config": {
"api_key": "your-soikastack-api-key",
"model": "llama3.3",
"base_url": "http://localhost:4141/v1"
}
},
"embedder": {
"provider": "soikastack",
"config": {
"api_key": "your-soikastack-api-key",
"model": "bge-m3"
}
}
}
)
# Alternative: Use OpenAI provider
# m = Memory(
# config={
# "llm": {
# "provider": "openai",
# "config": {
# "api_key": "your-openai-api-key",
# "model": "gpt-4"
# }
# },
# "embedder": {
# "provider": "openai",
# "config": {
# "api_key": "your-openai-api-key",
# "model": "text-embedding-3-large"
# }
# }
# }
# )
```python
from soika_memory import Memory
# Initialize with default configuration
memory = Memory()
# Add a memory
result = memory.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice")
print(result)
# Search memories
search_results = m.search("software engineer", user_id="john_doe")
print(search_results)
# Get all memories
all_memories = m.get_all(filters={"user_id": "john_doe"})
print(all_memories)
REST API Server
Start the memory server:
cd server
python main.py
The API will be available at http://localhost:8000 with documentation at /docs.
API Examples
Create Memory:
curl -X POST "http://localhost:8000/memories" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "I love pizza"},
{"role": "assistant", "content": "Great! I will remember that."}
],
"user_id": "user123"
}'
Search Memories:
curl -X POST "http://localhost:8000/search" \
-H "Content-Type: application/json" \
-d '{
"query": "food preferences",
"user_id": "user123"
}'
Get All Memories:
curl "http://localhost:8000/memories?user_id=user123"
Configuration
Memory supports extensive configuration options:
config = {
"llm": {
"provider": "openai", # openai, azure_openai, anthropic, gemini, etc.
"config": {
"api_key": "your-api-key",
"model": "gpt-4",
"temperature": 0.1
}
},
"embedder": {
"provider": "openai",
"config": {
"api_key": "your-api-key",
"model": "text-embedding-3-large"
}
},
"vector_store": {
"provider": "qdrant", # qdrant, pinecone, chroma, pgvector, etc.
"config": {
"host": "localhost",
"port": 6333
}
},
"graph_store": {
"provider": "neo4j", # neo4j, memgraph, neptune
"config": {
"url": "bolt://localhost:7687",
"username": "neo4j",
"password": "password"
}
}
}
Advanced Features
Graph Memory
Enable graph memory to extract and store entity relationships:
# Enable graph memory
m = Memory(config=config, enable_graph=True)
# Add complex information
messages = [
{"role": "user", "content": "Alice works at Google as a software engineer and lives in Mountain View"}
]
result = m.add(messages, user_id="user123")
# Access extracted relationships
relations = result.get("relations", {})
entities = relations.get("added_entities", [])
Space-based Isolation
Organize memories by workspace or project:
# Add memories to different spaces
m.add(messages, user_id="user123", space_id="project_alpha")
m.add(messages, user_id="user123", space_id="project_beta")
# Search within specific space
results = m.search("query", user_id="user123", space_id="project_alpha")
Async Operations
Use async client for high-performance applications:
from soika_memory import AsyncMemory
async def main():
m = AsyncMemory(config=config)
# Async operations
result = await m.add(messages, user_id="user123")
search_results = await m.search("query", user_id="user123")
all_memories = await m.get_all(filters={"user_id": "user123"})
Docker Deployment
Using Docker Compose
version: '3.8'
services:
memory-server:
build: .
ports:
- "8000:8000"
environment:
- OPENAI_API_KEY=your-openai-api-key
- QDRANT_HOST=qdrant
- QDRANT_PORT=6333
depends_on:
- qdrant
qdrant:
image: qdrant/qdrant
ports:
- "6333:6333"
volumes:
- qdrant_storage:/qdrant/storage
Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Client SDK โ โ REST API โ โ Proxy Server โ
โ (Sync/Async) โ โ (FastAPI) โ โ (OpenAI) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโ
โ Memory Core โ
โ (Engine) โ
โโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ LLM โ โ Vector โ โ Graph โ
โ Providers โ โ Stores โ โ Stores โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Testing
Run the test suite:
# Basic functionality test
cd server
python simple_test.py
# Advanced scenarios
python advanced_test.py
# API endpoint testing
python test_endpoints.py
# Space isolation demo
bash final_demo.sh
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Roadmap
- Real-time memory synchronization
- Multi-modal memory support (images)
- Advanced graph analytics
- Memory compression and archival
- Federated memory networks
Memory - Making AI agents truly intelligent with persistent, searchable, and contextual memory.
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 soika_memory-1.2.2.tar.gz.
File metadata
- Download URL: soika_memory-1.2.2.tar.gz
- Upload date:
- Size: 115.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
837fe7485fb9ca8359d3c97d780030d2306e9f853dab720a8c72fb5d3cbb581d
|
|
| MD5 |
d641be9f533318cdb409fb12a83672aa
|
|
| BLAKE2b-256 |
18f22816d44de23675a62b595adeceb930fe8f6592e3fe7357f04dff5fe3f036
|
File details
Details for the file soika_memory-1.2.2-py3-none-any.whl.
File metadata
- Download URL: soika_memory-1.2.2-py3-none-any.whl
- Upload date:
- Size: 178.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624409ec528995e0a4918e39e3cd5f148717f6387d2383b70fa1e1052b2c362f
|
|
| MD5 |
f0ddf90a25412cbd985052d57b0b7919
|
|
| BLAKE2b-256 |
e20661fde0c46b3e1bd60d0a744717ec881a16262e7f8e4dc09dc7c259ef55de
|