Skip to main content

Memory storage and retrieval system for Bruno AI Platform

Project description

Bruno Memory

Memory storage and retrieval system for Bruno AI Platform

CI Lint PyPI version Python 3.11+ License: MIT

Dependencies

pip install git+https://github.com/meggy-ai/bruno-core.git
pip install git+https://github.com/meggy-ai/bruno-llm.git

Bruno Memory provides multiple backend storage options for conversation history, user context, and semantic memory while maintaining a consistent API for AI assistants to interact with. It implements the MemoryInterface from bruno-core with full embedding support via bruno-llm.

๐Ÿ“š Documentation

View Full Documentation | Quick Start | API Reference | Examples

โœจ Features

  • Multiple Storage Backends: SQLite, PostgreSQL, Redis, ChromaDB, Qdrant
  • Semantic Search: Vector-based similarity search using embeddings
  • Session Management: Track conversations across multiple sessions
  • Memory Compression: Automatic summarization of old conversations
  • Context Building: Intelligent context window management
  • Async/Await Support: Full async support for high performance
  • Type Safety: Complete type hints and Pydantic models
  • Easy Configuration: Environment-based configuration

๐Ÿš€ Quick Start

Installation

# Basic installation
pip install bruno-memory

# With SQLite support (default)
pip install bruno-memory[sqlite]

# With PostgreSQL support  
pip install bruno-memory[postgresql]

# With Redis caching
pip install bruno-memory[redis]

# With vector database support
pip install bruno-memory[vector]

# With all backends
pip install bruno-memory[all]

Basic Usage

import asyncio
from bruno_memory import MemoryFactory
from bruno_core.models.message import Message, MessageRole

async def main():
    # Create memory backend
    memory = MemoryFactory.create("sqlite", database_path="./conversations.db")
    
    # Store a message
    message = Message(
        role=MessageRole.USER,
        content="Hello, how are you today?"
    )
    await memory.store_message(message, conversation_id="conv_1")
    
    # Retrieve messages
    messages = await memory.retrieve_messages("conv_1", limit=10)
    print(f"Found {len(messages)} messages")
    
    # Search messages semantically (requires embedding provider)
    results = await memory.search_messages("greeting", limit=5)
    
    # Get conversation context
    context = await memory.get_context(user_id="user_123")
    print(f"Context has {len(context.messages)} messages")

if __name__ == "__main__":
    asyncio.run(main())

๐Ÿ—๏ธ Architecture

Bruno Memory is built with a modular architecture:

bruno-memory/
โ”œโ”€โ”€ backends/          # Storage backend implementations
โ”‚   โ”œโ”€โ”€ sqlite/        # SQLite backend (file-based)
โ”‚   โ”œโ”€โ”€ postgresql/    # PostgreSQL backend (production)
โ”‚   โ”œโ”€โ”€ redis/         # Redis backend (caching)
โ”‚   โ””โ”€โ”€ vector/        # Vector DB backends (ChromaDB, Qdrant)
โ”œโ”€โ”€ managers/          # Memory management components
โ”‚   โ”œโ”€โ”€ conversation.py    # Session lifecycle management
โ”‚   โ”œโ”€โ”€ context_builder.py # Context window construction
โ”‚   โ”œโ”€โ”€ retriever.py       # Search and retrieval
โ”‚   โ”œโ”€โ”€ compressor.py      # Memory compression
โ”‚   โ””โ”€โ”€ embedding.py       # Embedding management
โ””โ”€โ”€ utils/             # Utility components
    โ”œโ”€โ”€ cache.py           # Caching layer
    โ”œโ”€โ”€ migration_manager.py # Schema migrations
    โ””โ”€โ”€ analytics.py       # Usage analytics

๐Ÿ“Š Backend Comparison

Backend Use Case Performance Features Setup Complexity
SQLite Development, Single-user Good Basic search, FTS โญ Easy
PostgreSQL Production, Multi-user Excellent Advanced search, JSON โญโญ Medium
Redis Caching, Sessions Excellent TTL, Pub/Sub โญโญ Medium
ChromaDB Semantic search Good Vector similarity โญโญโญ Advanced
Qdrant Production vectors Excellent Hybrid search โญโญโญ Advanced

๐Ÿ”ง Configuration

Environment Variables

# Backend selection
BRUNO_MEMORY_BACKEND=postgresql
BRUNO_MEMORY_DATABASE_URL=postgresql://user:pass@localhost:5432/bruno

# Embedding provider (from bruno-llm)
BRUNO_LLM_EMBEDDING_PROVIDER=ollama
BRUNO_LLM_EMBEDDING_BASE_URL=http://localhost:11434

# Memory settings
BRUNO_MEMORY_MAX_MESSAGES=1000
BRUNO_MEMORY_COMPRESS_AFTER_DAYS=30

Programmatic Configuration

from bruno_memory import MemoryFactory

# SQLite backend
memory = MemoryFactory.create("sqlite", {
    "database_path": "./conversations.db",
    "enable_fts": True,
    "max_connections": 10
})

# PostgreSQL backend
memory = MemoryFactory.create("postgresql", {
    "host": "localhost",
    "port": 5432,
    "database": "bruno",
    "username": "postgres",
    "password": "secret",
    "pool_size": 20
})

# Redis backend
memory = MemoryFactory.create("redis", {
    "host": "localhost", 
    "port": 6379,
    "db": 0,
    "ttl_seconds": 3600
})

# ChromaDB backend
memory = MemoryFactory.create("chromadb", {
    "persist_directory": "./chroma_db",
    "collection_name": "conversations"
})

๐Ÿ” Semantic Search

Bruno Memory integrates with bruno-llm for embedding-based semantic search:

from bruno_memory import MemoryFactory
from bruno_llm.embedding_factory import EmbeddingFactory

# Set up embedding provider
embedding_provider = EmbeddingFactory.create("ollama", {
    "base_url": "http://localhost:11434",
    "model": "nomic-embed-text"
})

# Create memory with embedding support
memory = MemoryFactory.create("chromadb", {
    "persist_directory": "./vectors",
    "embedding_provider": embedding_provider
})

# Search semantically
results = await memory.search_messages(
    query="What did we discuss about machine learning?",
    limit=5
)

๐Ÿ“ˆ Performance

Bruno Memory is designed for high performance:

  • Async/Await: All operations are async for maximum concurrency
  • Connection Pooling: Efficient database connection management
  • Caching: Multi-level caching with Redis support
  • Batch Operations: Bulk operations for large datasets
  • Streaming: Stream large result sets to avoid memory issues

Benchmarks

Operation SQLite PostgreSQL Redis ChromaDB
Store Message 1ms 2ms 0.5ms 5ms
Retrieve 100 Messages 10ms 8ms 2ms 15ms
Search (semantic) N/A 50ms N/A 20ms
Context Building 15ms 12ms 5ms 25ms

๐Ÿงช Testing

Quick Testing

# Install with dev dependencies
pip install bruno-memory[dev]

# Run tests
pytest

# Run with coverage
pytest --cov=bruno_memory --cov-report=html

Docker-Based Testing

Bruno Memory includes comprehensive Docker-based testing infrastructure for all backends:

# Quick start - run all tests with Docker services
make test-docker

# Test specific backends
make test-postgresql  # PostgreSQL backend only
make test-redis       # Redis backend only
make test-chromadb    # ChromaDB vector backend
make test-qdrant      # Qdrant vector backend
make test-vector      # All vector backends

# Use minimal profile (PostgreSQL + Redis only)
make test-docker-minimal

# Keep environment running for iterative development
./scripts/run-tests-docker.ps1 -KeepEnv

Manual Service Management

# Start all services
make docker-up

# Check service status
make docker-status

# View logs
make docker-logs

# Stop services (preserve data)
make docker-down

# Complete cleanup (remove data)
make docker-teardown

Cross-Platform Scripts

All scripts are available in both PowerShell (Windows) and Bash (Linux/Mac):

# PowerShell (Windows)
.\scripts\setup-test-env.ps1 -Profile full
.\scripts\run-tests-docker.ps1 -Verbose
.\scripts\teardown-test-env.ps1 -Volumes

# Bash (Linux/Mac)
bash scripts/setup-test-env.sh --profile full
bash scripts/run-tests-docker.sh --verbose
bash scripts/teardown-test-env.sh --volumes

๐Ÿ“– Full Docker testing documentation: DOCKER_TESTING_QUICKSTART.md

Test Profiles

  • minimal: PostgreSQL + Redis (fastest)
  • full: All services including ChromaDB and Qdrant
  • ci: CI-optimized with tmpfs and no volumes

Service Ports

Service Port Use Case
PostgreSQL 5432 Relational storage with pgvector
Redis 6379 Caching and sessions
ChromaDB 8000 Vector similarity search
Qdrant 6333 (HTTP), 6334 (gRPC) Production vector search

๐Ÿ”— Integration

With Bruno Core

from bruno_core import BaseAssistant
from bruno_memory import MemoryFactory

class MyAssistant(BaseAssistant):
    def __init__(self):
        # Initialize memory backend
        memory = MemoryFactory.create_from_env()
        super().__init__(memory=memory)
    
    async def process_message(self, message):
        # Memory automatically handles storage
        response = await self.generate_response(message)
        return response

With Bruno LLM

from bruno_llm import LLMFactory
from bruno_llm.embedding_factory import EmbeddingFactory
from bruno_memory import MemoryFactory

# Create providers
llm = LLMFactory.create("ollama")
embeddings = EmbeddingFactory.create("ollama")

# Create memory with embedding support
memory = MemoryFactory.create("chromadb", {
    "embedding_provider": embeddings
})

# Use together
async def rag_search(query: str):
    # Find relevant memories
    memories = await memory.search_messages(query, limit=5)
    
    # Use in LLM prompt
    context = "\\n".join([m.content for m in memories])
    response = await llm.generate(
        f"Context: {context}\\n\\nQuestion: {query}"
    )
    return response

๐Ÿ“š Documentation

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

# Clone the repository
git clone https://github.com/meggy-ai/bruno-memory.git
cd bruno-memory

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate

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

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Related Projects

๐Ÿ“ž Support


Made with โค๏ธ by the meggy-ai team.

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

bruno_memory-0.1.5.tar.gz (177.9 kB view details)

Uploaded Source

Built Distribution

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

bruno_memory-0.1.5-py3-none-any.whl (85.7 kB view details)

Uploaded Python 3

File details

Details for the file bruno_memory-0.1.5.tar.gz.

File metadata

  • Download URL: bruno_memory-0.1.5.tar.gz
  • Upload date:
  • Size: 177.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bruno_memory-0.1.5.tar.gz
Algorithm Hash digest
SHA256 27cba81e02cd9adda8ba468fcab699b59aea30fcf26cb8efad53f4f800be394a
MD5 be0c001e550192f336155ddc5b51740a
BLAKE2b-256 53751898047c67522938f2f639bda54fa2fdf1d300fe7c9e88208b6c12d21cff

See more details on using hashes here.

Provenance

The following attestation bundles were made for bruno_memory-0.1.5.tar.gz:

Publisher: publish.yml on meggy-ai/bruno-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bruno_memory-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: bruno_memory-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 85.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bruno_memory-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 32eef69bb5f0b99d7229a87366630446dc33ebad62b6d6ceeaf2a63e7c0433f0
MD5 062a5b6886c1edad3e241744e2fb7eff
BLAKE2b-256 b9e3ee299f429469dc8594d814e870bcb75bd238f56a838fe59e80f0e28dcebc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bruno_memory-0.1.5-py3-none-any.whl:

Publisher: publish.yml on meggy-ai/bruno-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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