Use this file to discover all available pages before exploring further.
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.
主要特性:
Distributed SQL: Scale out while maintaining ACID guarantees
Native vector support: Built-in VECTOR type (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
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.
Call checkpointer.setup() (or await checkpointer.setup()) the first time you use the CockroachDB checkpointer to create the required tables.
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.
The checkpointer uses raw psycopg3 connections (not SQLAlchemy) for compatibility with LangGraph’s checkpoint interface. The from_conn_string factory accepts cockroachdb:// URLs and converts them automatically.
Automatically expire old checkpoint data using CockroachDB’s Row-Level TTL:
with CockroachDBSaver.from_conn_string(DB_URI) as checkpointer: checkpointer.setup() # Expire checkpoints older than 30 days, clean up daily checkpointer.enable_ttl(ttl_interval="30 days", cron="@daily") # Use the checkpointer normally -- old data is cleaned up automatically graph = builder.compile(checkpointer=checkpointer) # To disable TTL later: # checkpointer.disable_ttl()
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.
from langchain_cockroachdb import AsyncCockroachDBVectorStore, CockroachDBEnginefrom langchain_openai import OpenAIEmbeddingsengine = CockroachDBEngine.from_connection_string(CONNECTION_STRING)# Create the table with a namespace columnawait engine.ainit_vectorstore_table( table_name="documents", vector_dimension=1536, namespace_column="namespace",)# Create a vectorstore scoped to a specific tenantvectorstore = AsyncCockroachDBVectorStore( engine=engine, embeddings=OpenAIEmbeddings(), collection_name="documents", namespace="tenant_a",)# All operations are scoped to tenant_aids = await vectorstore.aadd_texts(["Tenant A document"])results = await vectorstore.asimilarity_search("query", k=5)