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

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

# Run tests
pytest

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

# Run integration tests (requires services)
docker-compose up -d  # Start test services
pytest -m integration

# Run benchmarks
pytest -m benchmark

๐Ÿ”— 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.4.tar.gz (136.6 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.4-py3-none-any.whl (84.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bruno_memory-0.1.4.tar.gz
  • Upload date:
  • Size: 136.6 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.4.tar.gz
Algorithm Hash digest
SHA256 67652e0ff8f659bd217faa3bd5c03235b2e9a2a18d99778d1a879140262618a5
MD5 84d9d3ba5b63250d7f2ff3a75afb6ad4
BLAKE2b-256 c84d8eddc1e4ffd8b0f9aa07b0673b164bd43568852f65e8cbaacef8fad99d4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bruno_memory-0.1.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: bruno_memory-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 84.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cec38344579788ebbacbf61f0547f7ce13cddcd872d15fbb88385a938c1981ac
MD5 0e0f9bb638bc033f6ea8a36e22578be8
BLAKE2b-256 e7e1484edffbfdf2a24233a7de6bfd7f78b0aa20490ddf4b5d48d1b6c1f7014d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bruno_memory-0.1.4-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