CockroachDB is a distributed SQL database built on a transactional and strongly-consistent key-value store. It scales horizontally, survives disk, machine, rack, and even datacenter failures with minimal latency disruption and no manual intervention.Key features:
- Distributed SQL: Scale out while maintaining ACID guarantees
- Native vector support: Built-in
VECTORtype (v24.2+) and C-SPANN indexes (v25.2+) - PostgreSQL compatible: Drop-in replacement for PostgreSQL applications
- Global replication: Multi-region deployments with low latency
- Automatic sharding: Data automatically distributed across nodes
- SERIALIZABLE isolation: Strongest isolation level by default
Installation and Setup
Install the LangChain integration:Get your CockroachDB connection string
You’ll need a CockroachDB cluster. Choose one option: Option 1: CockroachDB Cloud (Recommended)- Sign up at cockroachlabs.cloud
- Create a free cluster
- Get your connection string:
cockroachdb://user:pass@host:26257/db?sslmode=verify-full
cockroachdb://root@localhost:26257/defaultdb?sslmode=disable
Option 3: Local Binary
Download from cockroachlabs.com/docs/releases
Integrations
Vector Store
CockroachDB can be used as a vector store with nativeVECTOR type and C-SPANN distributed indexes.
Key features:
- Native vector support (v24.2+)
- C-SPANN indexes optimized for distributed systems (v25.2+)
- Advanced metadata filtering
- Multi-tenancy with prefix columns
- Horizontal scalability
Chat Message History
Store conversation history in CockroachDB for persistent, distributed chat applications. Key features:- Distributed storage with automatic replication
- Strong consistency (SERIALIZABLE)
- Session-based organization
- High availability
LangGraph Checkpointer
Persist LangGraph workflow state in CockroachDB for short-term memory, human-in-the-loop interactions, and fault tolerance. Both sync (CockroachDBSaver) and async (AsyncCockroachDBSaver) implementations are available.
- Sync
- Async
See Get your CockroachDB connection string above for connection options including CockroachDB Cloud (recommended for production), Docker, and local binary installs. For local development,
sslmode=disable is acceptable; always use sslmode=verify-full in production.Row-Level TTL (v0.2.1+)
Automatically expire old checkpoint data using CockroachDB’s Row-Level TTL:await checkpointer.aenable_ttl(ttl_interval="7 days", cron="@hourly")
TTL deletion is eventual — expired rows remain queryable until CockroachDB’s background job runs on the specified cron schedule.
Performance optimizations (v0.2.1+)
The checkpointer includes several optimizations for low-latency reads:- Batch fetching:
list()fetches all blobs and writes in 2 batch queries instead of 2 per checkpoint - Raw BYTEA: Uses psycopg3 binary protocol instead of hex-encoding blobs in SQL
- Prepared statements:
from_conn_string()enables server-side query plan caching (prepare_threshold=5)
Multi-tenancy
Isolate vector data by tenant using an opt-in namespace column. When enabled, all CRUD and search operations are scoped to the specified namespace. CockroachDB’s C-SPANN indexes support prefix columns, so namespace filtering uses the vector index directly without a separate scan.Why CockroachDB for AI applications?
Distributed by design
- Horizontal scalability: Add nodes to handle more load
- Multi-region deployments: Serve users globally with low latency
- Automatic rebalancing: Data distributes automatically across nodes
Production-ready reliability
- High availability: Survives node, rack, and datacenter failures
- Zero-downtime upgrades: Rolling updates without downtime
- Backups and restores: Point-in-time recovery
Vector search at scale
- C-SPANN indexes: Distributed approximate nearest neighbor search
- Native vector type: First-class support for embeddings
- Real-time indexing: No rebuild needed for new vectors
- Multi-tenancy: Prefix columns for efficient tenant isolation
PostgreSQL compatibility
- Easy migration: Drop-in replacement for PostgreSQL
- Familiar SQL: Standard PostgreSQL syntax
- Existing tools: Works with PostgreSQL drivers and tools
Resources
- CockroachDB Documentation
- langchain-cockroachdb GitHub
- langchain-cockroachdb PyPI
- CockroachDB Cloud
- CockroachDB University (free courses)
Support
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

