Skip to main content

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 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"
#             }
#         }
#     }
# )

# Add memories
messages = [
    {"role": "user", "content": "I'm John, a software engineer from San Francisco"},
    {"role": "assistant", "content": "Nice to meet you John!"}
]

result = m.add(messages, user_id="john_doe")
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 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

soika_memory-1.1.0.tar.gz (117.0 kB view details)

Uploaded Source

Built Distribution

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

soika_memory-1.1.0-py3-none-any.whl (179.0 kB view details)

Uploaded Python 3

File details

Details for the file soika_memory-1.1.0.tar.gz.

File metadata

  • Download URL: soika_memory-1.1.0.tar.gz
  • Upload date:
  • Size: 117.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for soika_memory-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ed841036256c25e35843b4e35f789edd8061037aabc98a76c6accef76519f5d6
MD5 c1583fb005c72da82413f097b10bdada
BLAKE2b-256 743e46c4d67a83b2d166e5954101506fdc73fcb6908f7c039102088163873f65

See more details on using hashes here.

File details

Details for the file soika_memory-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: soika_memory-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 179.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for soika_memory-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09e87e7a61bd2152872355db16b01ba8811a32d1a74f1f2083b0934707b6f59b
MD5 f31704ee39cc5ddc47a284a366017890
BLAKE2b-256 28c782a4f5b9942ee542b27e5a8c14c41cdde4e3d3aa1a8dae0bfbd743167952

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