blog-banner

Agent Development with CockroachDB using the LangChain Framework

Last edited on February 26, 2026

0 minute read

    langchain-cockroachdb-integration

    Recently we launched an integration with LangChain, the most popular orchestration framework for developing applications with large language models, to simplify development of production-ready agentic AI applications with CockroachDB. This integration provides out-of-the-box support for CockroachDB as a vector source for any LangChain user using LangChain Python.

    Why use LangChain?Copy Icon

    Developers use LangChain because building real-world applications with large language models quickly gets more complex than a single prompt and response. As soon as an app needs to retrieve data, maintain conversational context, or reason across multiple steps, the amount of custom glue code grows fast. LangChain provides a structured way to orchestrate these workflows, helping developers move from experimental demos to production-oriented systems without reinventing common patterns.

    One of LangChain’s biggest draws is how it simplifies retrieval-augmented generation. Ingesting documents, chunking and embedding them, storing vectors, and retrieving the right context at query time are all well-understood steps—but wiring them together correctly takes time. LangChain offers reusable abstractions for these tasks, making it easier to connect language models to CockroachDB data sources and build applications like internal search, customer support assistants, and knowledge copilots.

    Why use CockroachDB with LangChain?Copy Icon

    Enables horizontal scaleCopy Icon

    The advantage of using CockroachDB with LangChain is that CockroachDB provides massive horizontal scale, ensuring that database architects can design a solution that grows with the success of the application while remaining cost efficient regardless of the size of the application.

    Delivers Postgres compatibility, with simplified global operationsCopy Icon

    Leveraging the power of CockroachDB provides AI agent developers with proven advantages of a distributed SQL solution:

    • ACID guarantees

    • PostgreSQL compatibility

    • Multi-region deployments with low-latency

    • Automatic sharding

    • SERIALIZABLE isolation

    Combines vectors with transactional data to simplify the data architectureCopy Icon

    CockroachDB can also be used as a vector store (compatible with Postgres pgvector) with native VECTOR type and take advantage of the C-SPANN distributed index. The advantage of storing vector data alongside transactional data reduces application complexity, improves performance, and simplifies data operations. Some of the key features available include:

    • Native vector support

    • C-SPANN indexes, optimized for distributed systems

    • Advanced metadata filtering

    • Multi-tenancy with prefix columns

    • Horizontal scalability to meet the demanding requirements of successful agentic applications

    How to Get StartedCopy Icon

    Install the LangChain integration:

    pip install langchain-cockroachdb

    Get the CockroachDB connection string:

    87% of organizations are using the cloud for AI development so we’ll use a free account on CockroachDB Cloud for our development environment:

    1. Sign up at cockroachlabs.cloud

    2. Create a free cluster

    3. Get your connection string, would look something like: cockroachdb://user:pass@host:26257/db?sslmode=verify-full

    Use that connection string in your LangChain configuration to connect to the database.

    For example:

    from langchain_cockroachdb import AsyncCockroachDBVectorStore, CockroachDBEngine from langchain_openai import OpenAIEmbeddings # 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",) # Use it ids = await vectorstore.aadd_texts(["Hello world"]) results = await vectorstore.asimilarity_search("Hi", k=1)

    Now you’re ready to go. If you want to create a chat application as a way to explore this integration, the integration package contains sample code, documented here

    Further Exploration of CockroachDB as a Vector StoreCopy Icon

    We’ve written two other detailed tutorials about using CockroachDB as a vector store.

    1. Augment your AI use case with RAG on CockroachDB

    2. Vehicle Search with SQL and Vector Embeddings

    Finally, learn more about LangChain + CockroachDB by reading the LangChain documentation.

    AI