langchain-cockroachdb
LangChain integration for CockroachDB with native vector support
Quick Start • Features • Documentation • Examples • Contributing
Overview
Build LLM applications with CockroachDB's distributed SQL database and native vector search capabilities. This integration provides:
- 🎯 Native Vector Support - CockroachDB's
VECTORtype - 🚀 C-SPANN Indexes - Distributed vector indexes optimized for scale
- 🔄 Automatic Retries - Retries transient CockroachDB errors (40001, 40003, 08xxx, 57P01, 58C00, 58C01) on every operation
- ⚡ Async & Sync APIs - Choose based on your use case
- 🏗️ Distributed by Design - Built for CockroachDB's architecture
Quick Start
Installation
pip install langchain-cockroachdb
Basic Usage
import asyncio
from langchain_cockroachdb import AsyncCockroachDBVectorStore, CockroachDBEngine
from langchain_openai import OpenAIEmbeddings
async def main():
# Initialize
engine = CockroachDBEngine.from_connection_string(
"cockroachdb://user:pass@host:26257/db"
)
await engine.ainit_vectorstore_table(
table_name="documents",
vector_dimension=1536,
)
vectorstore = AsyncCockroachDBVectorStore(
engine=engine,
embeddings=OpenAIEmbeddings(),
collection_name="documents",
)
# Add documents
await vectorstore.aadd_texts([
"CockroachDB is a distributed SQL database",
"LangChain makes building LLM apps easy",
])
# Search
results = await vectorstore.asimilarity_search(
"Tell me about databases",
k=2
)
for doc in results:
print(doc.page_content)
await engine.aclose()
asyncio.run(main())
Long-Term Memory for LangGraph
CockroachDBStore gives LangGraph agents memory that every thread can read, with semantic search and expiry:
from langchain_cockroachdb import CockroachDBStore
from langchain_openai import OpenAIEmbeddings
with CockroachDBStore.from_conn_string(
"cockroachdb://user:pass@host:26257/db",
pool_config={"max_size": 10},
index={"dims": 1536, "embed": OpenAIEmbeddings(model="text-embedding-3-small")},
ttl={"default_ttl": 60 * 24 * 30}, # minutes
) as store:
store.setup()
store.put(("user", "alice", "memories"), "seat", {"text": "Prefers window seats"})
results = store.search(("user", "alice"), query="Where does Alice like to sit?")
# Pass store=store to create_agent, StateGraph.compile or create_deep_agent
See the Long-Term Memory guide.
Features
Vector Store
- Native
VECTORtype support with C-SPANN indexes - Advanced metadata filtering (
$and,$or,$gt,$in, etc.) - Hybrid search (full-text + vector similarity)
- Multi-tenancy with namespace-based isolation and C-SPANN prefix columns
Chat History
- Persistent conversation storage in CockroachDB
- Session management by thread ID
- Drop-in replacement for other LangChain chat history implementations
LangGraph Checkpointer
- Short-term memory for multi-turn LangGraph agents
- Human-in-the-loop with interrupt/resume support
- Both
CockroachDBSaver(sync) andAsyncCockroachDBSaver - Compatible with LangGraph's
compile(checkpointer=...)interface
LangGraph Long-Term Memory Store
- Memory that every thread can read, for LangGraph agents and Deep Agents
- Both
CockroachDBStore(sync) andAsyncCockroachDBStore, with the API of LangGraph'sPostgresStore - Semantic search on a C-SPANN vector index, with metadata filters
- Expiry through CockroachDB row-level TTL, with no sweeper thread
delete_namespacedeletes a user's memories in one transaction
Reliability and Retries
- Retries transient CockroachDB errors (40001, 40003, 08xxx, 57P01, 58C00, 58C01, 53300) on every operation
- Configurable
RetryPolicywith exponential backoff, jitter and optional hang guards - Idempotent writes (UPSERTs, ON CONFLICT DO NOTHING) for safe retries
- Connection pooling with health checks and pre-ping
- Works with both SERIALIZABLE (default, recommended) and READ COMMITTED isolation
- See the Retries and Resilience guide
Developer Experience
- Async-first design for high concurrency
- Sync wrapper for simple scripts
- Type-safe with full type hints
- Comprehensive test suite (177 tests)
Documentation
LangChain Official Integration Docs:
Getting Started:
Guides:
- Vector Store
- Vector Indexes
- Hybrid Search
- Chat History
- Multi-Tenancy
- LangGraph Checkpointer
- LangGraph Long-Term Memory
- Async vs Sync
- Retries and Resilience
Examples
quickstart.py- Get started in 5 minutessync_usage.py- Synchronous APIvector_indexes.py- Index optimizationhybrid_search.py- FTS + vector searchmetadata_filtering.py- Advanced querieschat_history.py- Persistent conversationscheckpointer.py- LangGraph checkpointerlong_term_memory.py- LangGraph long-term memory storemulti_tenancy.py- Namespace-based multi-tenancyretry_configuration.py- Configuration patterns
Development
Setup
# Clone repository
git clone https://github.com/cockroachdb/langchain-cockroachdb.git
cd langchain-cockroachdb
# Install dependencies
pip install -e ".[dev]"
# Start CockroachDB
docker-compose up -d
# Run tests
make test
Documentation
# Install docs dependencies
pip install -e ".[docs]"
# Serve documentation locally
mkdocs serve
# Open http://127.0.0.1:8000
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Why CockroachDB?
- Distributed SQL - Scale horizontally across regions
- Native Vector Support - First-class
VECTORtype and C-SPANN indexes - Strong Consistency - SERIALIZABLE isolation by default, READ COMMITTED also supported
- Cloud Native - Deploy anywhere (IBM, AWS, GCP, Azure, on-prem)
- PostgreSQL Compatible - Familiar SQL with distributed superpowers
Links
License
Apache License 2.0 - see LICENSE for details.
Acknowledgments
Built for the CockroachDB and LangChain communities.
- CockroachDB - Distributed SQL database
- LangChain - LLM application framework
Metadata
Release files for langchain-cockroachdb 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_cockroachdb-0.5.1.tar.gz | 581.9 kB | With provenance | Details for langchain_cockroachdb-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_cockroachdb-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_cockroachdb-0.5.1-py3-none-any.whl |
Total release size: 703.3 kB
Release files / langchain_cockroachdb-0.5.1.tar.gz
| Download URL | langchain_cockroachdb-0.5.1.tar.gz |
|---|---|
| Size | 581.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a95e706fc4f55c98b996d7172359e745e081f7ecbb01a92e54616a9b32c5386
|
|
BLAKE2b-256 checksum How to use checksums |
09a85f4e8d4f22e92fff7f83195239c56b6e00a454c5bf013bb7b89f46b11e08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / langchain_cockroachdb-0.5.1-py3-none-any.whl
| Download URL | langchain_cockroachdb-0.5.1-py3-none-any.whl |
|---|---|
| Size | 121.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a403fdf637f56e01837f93188772621c7eff79eaf8b4900462ece54fc2c379de
|
|
BLAKE2b-256 checksum How to use checksums |
a7c87f770ebab8add1c58fc998f9733d44e71f716e2ca0dd48d204fb9c3edef8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for langchain-cockroachdb 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for langchain_cockroachdb-0.5.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.