Skip to main content
CockroachDBChatMessageHistory stores chat conversation history in CockroachDB’s distributed SQL database. The code lives in the integration package: langchain-cockroachdb.

Overview

CockroachDBChatMessageHistory provides:
  • Distributed storage: Chat history automatically replicated across nodes
  • Strong consistency: SERIALIZABLE transactions prevent message ordering issues
  • High availability: Automatic failover with no data loss
  • Session isolation: Each conversation has a unique session ID
  • PostgreSQL compatibility: Easy migration from PostgreSQL-based systems

Setup

Install

Connection string

Initialization

Create the message history table

Optional: Specify a schema name by using schema parameter (default: “public”)

Initialize for a session

Create a chat history instance for a specific conversation:

Usage

Add messages

Add multiple messages at once

Retrieve messages

Get all messages for the session:

Clear conversation history

Delete all messages for the session:

Sync interface

Use the synchronous API:

API reference

For detailed documentation:

Additional resources