Skip to main content

Enterprise-grade persistent memory for LangChain agents

Project description

RecallBricks LangChain Integration

Official LangChain integration for RecallBricks Memory Graph.

What is RecallBricks?

RecallBricks provides memory infrastructure that goes beyond vector search by understanding relationships, causality, and patterns - not just similar text.

Perfect for LangChain agents that need:

  • Context across conversations
  • Understanding of cause-and-effect
  • Relationship-aware memory retrieval

Installation

pip install recallbricks-langchain

Quick Start

Memory with Automatic Organization

from langchain.chains.conversation.base import ConversationChain
from langchain_openai import ChatOpenAI
from recallbricks_langchain import RecallBricksMemory

# Initialize memory with organized recall (enabled by default)
memory = RecallBricksMemory(
    agent_id="my-agent",
    api_key="your-recallbricks-api-key",
    organized=True  # Returns category summaries for better context
)

# Use with any LangChain chain
llm = ChatOpenAI()
conversation = ConversationChain(
    llm=llm,
    memory=memory
)

# Your agent now has relationship-aware memory!
response = conversation.run("Tell me about RecallBricks")
# Memories are automatically tagged, categorized, and organized

Retriever for RAG

from recallbricks_langchain import RecallBricksRetriever
from langchain.chains import RetrievalQA

retriever = RecallBricksRetriever(
    api_key="your-api-key",
    k=5,  # Top 5 results
    organized=True
)

qa_chain = RetrievalQA.from_chain_type(
    llm=ChatOpenAI(),
    retriever=retriever
)

answer = qa_chain.run("What is cognitive memory infrastructure?")

Chat Message History

from recallbricks_langchain import RecallBricksChatMessageHistory
from langchain.memory import ConversationBufferMemory

history = RecallBricksChatMessageHistory(
    api_key="your-api-key",
    session_id="user-123-session-1"
)

memory = ConversationBufferMemory(
    chat_memory=history,
    return_messages=True
)

Features

New in v1.2.0

  • Automatic Metadata Extraction: Tags, categories, entities extracted automatically via learn() endpoint
  • Organized Recall: Get category summaries for faster context assembly (3-5x faster LLM reasoning)
  • RecallBricksRetriever: LangChain retriever for RAG applications
  • RecallBricksChatMessageHistory: Persistent chat history with session support

Enterprise Features

  • Drop-in replacement for ConversationBufferMemory
  • Automatic relationship detection - understands causality and patterns
  • Persistent across sessions - memories don't disappear
  • Multi-user support - isolate memory per user
  • Multi-tenant support - project IDs for isolation
  • Production-ready - 99.9% uptime, enterprise security
  • Circuit breaker - fault tolerance for API failures
  • Rate limiting - prevents API abuse
  • Request deduplication - prevents duplicate saves
  • Prometheus metrics - observability built-in
  • Health checks - comprehensive monitoring

Why RecallBricks vs Standard LangChain Memory?

Feature ConversationBufferMemory RecallBricksMemory
Stores conversations
Persists across sessions
Understands relationships
Detects causality
Finds patterns
Explains connections
Auto-extracts metadata
Organized recall

API Reference

RecallBricksMemory

Main memory class for LangChain agents with automatic metadata extraction.

memory = RecallBricksMemory(
    agent_id="my-agent",           # Required: Agent identifier
    api_key="your-key",            # Required: RecallBricks API key
    user_id="user-123",            # Optional: User ID (UUID format)
    project_id="my-project",       # Optional: Project ID for multi-tenant
    organized=True,                # Optional: Use organized recall (default: True)
    source="langchain",            # Optional: Source identifier
    limit=10,                      # Optional: Max memories to retrieve
    return_messages=False,         # Optional: Return as Message objects
)

# Direct API access
memory.learn("User prefers dark mode")  # Auto-extracts tags, category
result = memory.recall("user preferences", organized=True)

RecallBricksRetriever

LangChain retriever for RAG applications with organized recall.

retriever = RecallBricksRetriever(
    api_key="your-key",            # Required: RecallBricks API key
    k=4,                           # Optional: Number of results (default: 4)
    organized=True,                # Optional: Use organized recall (default: True)
    project_id="my-project",       # Optional: Project ID
)

# Standard retriever interface
docs = retriever.get_relevant_documents("search query")

# Get documents with category summaries
result = retriever.get_relevant_documents_with_categories("search query")
docs = result["documents"]
categories = result["categories"]

RecallBricksChatMessageHistory

Persistent chat history with session isolation.

history = RecallBricksChatMessageHistory(
    api_key="your-key",            # Required: RecallBricks API key
    session_id="session-123",      # Required: Unique session identifier
    project_id="my-project",       # Optional: Project ID
)

# Add messages
history.add_user_message("Hello!")
history.add_ai_message("Hi there!")

# Get all messages
messages = history.messages

Advanced Usage

Multi-User Applications

def get_conversation_for_user(user_id: str):
    memory = RecallBricksMemory(
        agent_id="my-agent",
        api_key="your-key",
        user_id=user_id  # Isolates memory per user
    )
    return ConversationChain(llm=llm, memory=memory)

Multi-Tenant Applications

# Use project_id to isolate memory per tenant
memory = RecallBricksMemory(
    agent_id="my-agent",
    api_key="your-key",
    project_id="tenant-abc"  # Isolates memory per project/tenant
)

Direct Learn/Recall Access

memory = RecallBricksMemory(
    agent_id="my-agent",
    api_key="your-key"
)

# Save with automatic metadata extraction
result = memory.learn("The user's favorite color is blue")
print(result["metadata"])  # {"tags": ["preferences"], "category": "Personal", ...}

# Recall with organization
result = memory.recall("user preferences", organized=True)
print(result["categories"])  # {"Personal": {"summary": "...", "count": 5}}

Monitoring & Health Checks

memory = RecallBricksMemory(
    agent_id="my-agent",
    api_key="your-key",
    enable_metrics=True
)

# Get detailed metrics
metrics = memory.get_detailed_metrics()
print(f"Success rate: {metrics['success_rate']}")
print(f"P95 response time: {metrics['response_time_p95']}")

# Export Prometheus metrics
prometheus_output = memory.get_prometheus_metrics()

# Comprehensive health check
health = memory.health_check()
print(f"Status: {health['status']}")

Migration from v1.1

# Old (v1.1) - still works but deprecated
memory.client.save_memory(text="...", tags=["manual"])

# New (v1.2) - automatic metadata extraction
memory.learn(text="...")  # Tags auto-generated!

# Old recall
result = memory.load_memory_variables({"input": "query"})

# New organized recall (default)
result = memory.load_memory_variables({"input": "query"})
# Now includes category summaries for 3-5x faster LLM reasoning

Existing code continues to work. Update to learn() for automatic metadata extraction.

Get Your API Key

  1. Sign up at recallbricks.com
  2. Get your API key from the dashboard
  3. Start building!

Documentation

Examples

Check out the examples/ directory for:

  • basic_usage.py - Simple conversation example
  • with_openai.py - Advanced multi-user scenarios with relationship detection

Development

Installation

# Clone the repository
git clone https://github.com/recallbricks/recallbricks-langchain.git
cd recallbricks-langchain

# Install in development mode
pip install -e .

# Install development dependencies
pip install -r requirements.txt

Running Tests

python -m pytest tests/

Support

License

MIT

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

recallbricks_langchain-2.0.1.tar.gz (76.0 kB view details)

Uploaded Source

Built Distribution

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

recallbricks_langchain-2.0.1-py3-none-any.whl (91.6 kB view details)

Uploaded Python 3

File details

Details for the file recallbricks_langchain-2.0.1.tar.gz.

File metadata

  • Download URL: recallbricks_langchain-2.0.1.tar.gz
  • Upload date:
  • Size: 76.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for recallbricks_langchain-2.0.1.tar.gz
Algorithm Hash digest
SHA256 1ddd1b9e4e78bf013219048cc167d5ece4d36fdc0557bdd35e8073286db837eb
MD5 48883112cb813d6ce00b64005791ff3c
BLAKE2b-256 d5f9691c780ba6407c18c1de36820d96addcad5e3a3599627405d943239c1a76

See more details on using hashes here.

File details

Details for the file recallbricks_langchain-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for recallbricks_langchain-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fccb580b52407a3d6541e2beb6a64b03b069991ab13c7667d1084fe717068f1
MD5 9460ec29903b50fbefda2eae1b1197d8
BLAKE2b-256 979ae4c81447d08f4ac6c79d3b75273743f63aaa692935272d35ca2572b48ca0

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