LangChain integration for CockroachDB with native vector support
Project description
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 - Handles serialization errors transparently
- ⚡ 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())
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
Reliability
- Automatic retry logic with exponential backoff
- Connection pooling with health checks
- Configurable for different workloads
- Works with both SERIALIZABLE (default, recommended) and READ COMMITTED isolation
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
- Async vs Sync
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 checkpointermulti_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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_cockroachdb-0.2.0.tar.gz.
File metadata
- Download URL: langchain_cockroachdb-0.2.0.tar.gz
- Upload date:
- Size: 327.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65c24b20d9c21edcf0a7f1ed51ed3ba92650a06378975e41eedaf2a3252e1b4a
|
|
| MD5 |
f9f9b1d30820da94c8406cb36711878a
|
|
| BLAKE2b-256 |
13f36125c843b4f60a46fb2594400b57ef9bbffbf7e6722ce911b6863c60cca7
|
Provenance
The following attestation bundles were made for langchain_cockroachdb-0.2.0.tar.gz:
Publisher:
release.yml on cockroachdb/langchain-cockroachdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_cockroachdb-0.2.0.tar.gz -
Subject digest:
65c24b20d9c21edcf0a7f1ed51ed3ba92650a06378975e41eedaf2a3252e1b4a - Sigstore transparency entry: 972512309
- Sigstore integration time:
-
Permalink:
cockroachdb/langchain-cockroachdb@45fbf1decfd095b3e1b699d24dd54ffb3c39994d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cockroachdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@45fbf1decfd095b3e1b699d24dd54ffb3c39994d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file langchain_cockroachdb-0.2.0-py3-none-any.whl.
File metadata
- Download URL: langchain_cockroachdb-0.2.0-py3-none-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd75e8495aaa0861074d7efa1794767f4fd7dadf67a48e87ac51e65dd8318188
|
|
| MD5 |
40a44ed9aa3b6372010531548fe763be
|
|
| BLAKE2b-256 |
3cc64410a29d45ff50d7c8b8a5bbe604d5c563bf052419eff5f8f47a2fa530dc
|
Provenance
The following attestation bundles were made for langchain_cockroachdb-0.2.0-py3-none-any.whl:
Publisher:
release.yml on cockroachdb/langchain-cockroachdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_cockroachdb-0.2.0-py3-none-any.whl -
Subject digest:
cd75e8495aaa0861074d7efa1794767f4fd7dadf67a48e87ac51e65dd8318188 - Sigstore transparency entry: 972512311
- Sigstore integration time:
-
Permalink:
cockroachdb/langchain-cockroachdb@45fbf1decfd095b3e1b699d24dd54ffb3c39994d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cockroachdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@45fbf1decfd095b3e1b699d24dd54ffb3c39994d -
Trigger Event:
workflow_dispatch
-
Statement type: