Skip to main content

LangChain integration for CockroachDB with native vector support

Project description

langchain-cockroachdb

Tests PyPI version Python 3.10+ Downloads License

LangChain integration for CockroachDB with native vector support

Quick StartFeaturesDocumentationExamplesContributing


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

  • 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

📚 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

Links

License

Apache License 2.0 - see LICENSE for details.

Acknowledgments

Built for the CockroachDB and LangChain communities.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_cockroachdb-0.2.1.tar.gz (335.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_cockroachdb-0.2.1-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain_cockroachdb-0.2.1.tar.gz.

File metadata

  • Download URL: langchain_cockroachdb-0.2.1.tar.gz
  • Upload date:
  • Size: 335.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_cockroachdb-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7663cad7acd389515f85fdcf1cdac01bd66e439c5b8487af99efe60ab1a1d844
MD5 3cda2d313a640f9f2ea064bd99c30bd6
BLAKE2b-256 d490dace8998416cb72cc33a540e5e25093fd5da5b68009fa9d3f712898317ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_cockroachdb-0.2.1.tar.gz:

Publisher: release.yml on cockroachdb/langchain-cockroachdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_cockroachdb-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_cockroachdb-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e40a02f83a549e04cf1915bd834f52c36229480c52875688b9a1d4e9cc3984e0
MD5 bea73fba53cb921cc22a2961e0036ce4
BLAKE2b-256 2bb9e31f9cd4c7445c66ba66b7011bd84fa981878243343aa3929230718648ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_cockroachdb-0.2.1-py3-none-any.whl:

Publisher: release.yml on cockroachdb/langchain-cockroachdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page