AI Memory

Use Couchbase as a vector memory provider for BoxLang AI applications. Store conversation history with semantic search capabilities for intelligent context retrieval in chatbots, agents, and RAG syste

Use Couchbase as a vector memory provider for BoxLang AI applications. Store conversation history with semantic search capabilities for intelligent context retrieval in chatbots, agents, and RAG systems.

Note: This feature requires the BoxLang AI Module (bx-ai) to be installed and Couchbase Server 7.6+ with vector search capabilities.

Overview

The bx-couchbase module integrates with BoxLang AI's memory system, allowing you to use Couchbase as a vector memory backend. This enables:

  • Semantic Search: Find relevant conversations based on meaning, not just keywords

  • Multi-Tenant Isolation: Separate vector storage per user and conversation

  • Scalable Storage: Handle thousands of conversations with Couchbase's performance

  • Persistent Memory: Conversation history survives application restarts

  • Hybrid Search: Combine vector similarity with metadata filtering

Installation

1. Install BoxLang AI Module

boxlang install bx-ai

2. Install Couchbase Module

boxlang install bx-couchbase

3. Configure Couchbase Cache

In your Application.bx:

Basic Usage

Creating Vector Memory

Multi-Tenant Isolation

Isolate conversations per user and conversation:

Configuration

Memory Configuration Options

Multi-Tenant Configuration

Working with Memory

Adding Messages

Retrieving Relevant Context

Getting All Messages

Integration with AI Agents

Simple Agent with Couchbase Memory

Multi-Conversation Support

Hybrid Memory (Recent + Semantic)

Combine windowed memory (recent messages) with vector search (relevant history):

Storage Structure

How Messages are Stored

Each message is stored in Couchbase as:

Multi-Tenant Filtering

All queries automatically filter by userId and conversationId:

Best Practices

1. Use Unique Keys per Conversation

2. Set Appropriate Limits

3. Use Hybrid Memory for Best Results

4. Clear Old Conversations Periodically

Performance Considerations

Connection Pooling

Couchbase connections are pooled automatically by the bx-couchbase module. No additional configuration needed.

Vector Index

For optimal performance, create a vector index in Couchbase:

Batch Operations

When storing multiple messages:

Couchbase Server Requirements

Minimum Version

  • Couchbase Server 7.6+ (for vector search support)

  • Couchbase SDK 3.6+ (included in bx-couchbase module)

Bucket Configuration

Vector Index Setup

Vector indexes are created automatically when first message is added. Manual creation:

Troubleshooting

Memory Not Persisting

Issue: Messages not stored in Couchbase

Solution: Verify cache configuration and connection:

Embedding Errors

Issue: "Embedding provider not configured"

Solution: Ensure bx-ai module is installed and embedding provider is configured:

Vector Search Not Finding Results

Issue: getRelevant() returns empty array

Solutions:

  1. Check embedding dimensions match:

  1. Verify messages are stored:

  1. Check search query:

Complete Examples

RAG Chatbot with Couchbase Memory

Multi-Tenant Customer Support

See Also

Last updated

Was this helpful?