Skip to main content

langchain-cockroachdb

Tests PyPI version Python 3.10+ Downloads License

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 VECTOR type
  • 🚀 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())

Features

Vector Store

  • Native VECTOR type 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) and AsyncCockroachDBSaver
  • Compatible with LangGraph's compile(checkpointer=...) interface

Reliability and Retries

  • Retries transient CockroachDB errors (40001, 40003, 08xxx, 57P01, 58C00, 58C01, 53300) on every operation
  • Configurable RetryPolicy with 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

📚 Complete Documentation

LangChain Official Integration Docs:

Getting Started:

Guides:

Examples

🔧 Working Examples

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 VECTOR type 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

License

Apache License 2.0 - see LICENSE for details.

Acknowledgments

Built for the CockroachDB and LangChain communities.

Metadata

Release files for langchain-cockroachdb 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-cockroachdb 0.4.1
File Size Uploaded
langchain_cockroachdb-0.4.1.tar.gz 453.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-cockroachdb 0.4.1
File Interpreter ABI Platform
langchain_cockroachdb-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 531.0 kB

Release files / langchain_cockroachdb-0.4.1.tar.gz

Download URL langchain_cockroachdb-0.4.1.tar.gz
Size 453.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4c1f0eba57d689d1c57a6695d16797f8dfa5c1ea7fa3af09dd695ecb0f99a4d9
BLAKE2b-256 checksum
How to use checksums
3a6a2d859845e98b8668ecc770bd53ddb42f03b85f3c7a249b6d72b37dbd51a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 16, 2026.

Transparency log

Release files / langchain_cockroachdb-0.4.1-py3-none-any.whl

Download URL langchain_cockroachdb-0.4.1-py3-none-any.whl
Size 77.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8d5e126b2e6530fbc9b2474f6f158ccb4ec6bb6c7efd9a84900d52decc2c166
BLAKE2b-256 checksum
How to use checksums
2d4cb0758dc9f9eed3aea5cd41e0b1b0f561c77431a8f056314ed0469b114add
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page