Announcing LangChain Postgres open-source Improvements

Introducing open-source improvements to LangChain PostgreSQL

Google Cloud became a major contributor to the library and revealed updates to the core LangChain Postgres package at Google Cloud Next ’25. Its goal of empowering all application developers to create database-backed agentic gen AI solutions using open source technologies is furthered by these enhancements.

An open-source framework called LangChain was created to make it easier to create agentic gen AI systems that use large language models (LLMs). It offers interfaces for linking LLMs to outside data sources, allowing for more potent and context-aware AI applications. LangChain frequently has to communicate with databases in order to efficiently manage and extract information from structured data. Specifically, the langchain-postgres package offers integrations that let LangChain use PostgreSQL databases to perform functions like loading documents, keeping chat history, and serving as a vector storage for embeddings. For LLM-powered apps to leverage current relational data, conduct semantic searches, and create chatbots with memory, this connectivity is essential.

Google Cloud upgrades provide robust connection pooling for enterprise-level scalability, quicker SQL filtering with relational metadata columns, and optimized performance through asynchronous PostgreSQL drivers. Additionally, it has included:

  • Support for vector indexes enables developers to create their own vector database using LangChain
  • Support for adaptable database schemas to create more robust and manageable applications
  • Updated LangChain vector store APIs that follow the least privilege principle and clearly distinguish between database setup and usage for increased security.

What are new improvements

Improved connectivity and security

The way your application interacts with the underlying data architecture must be carefully considered when developing generative AI applications that are both secure and reliable. Through a number of significant enhancements, it has given priority to improved security and effective connection with its contributions to the LangChain Postgres package.

Our attention has been on following the least privilege principle. The rights needed to create a database schema and those needed for regular application use are now clearly separated by the improved API. You can limit the application layer’s ability to alter the underlying database structure by giving it limited permissions thanks to this separation. You may improve your AI applications’ overall security posture and drastically lower the possible attack surface by separating these duties.

Additionally, we reduce the overhead of creating new connections for every query by keeping a pool of current database connections. In addition to resulting in notable enhancements in performance, particularly in high-throughput settings, this also helps to stabilise your application by efficiently controlling resource usage and preventing you from having thousands of unused active PostgreSQL connections.

Better schema design

In order to mimic the data model of purpose-built vector databases, the langchain-postgres package previously only permitted the construction of new schemas with fixed table names and a single json metadata column. However, one advantage of utilising PostgreSQL databases as vector databases is that you may use filters on non-vector columns to enhance the quality of your vector search by utilizing PostgreSQL’s powerful querying capabilities. When querying your vector store, you may combine vector search queries with SQL filters by defining separate metadata columns with our enhancements to the LangChain postgres package.

With just a few lines of code, you can convert your operational workload into an AI workload by utilizing your existing PostgreSQL database schema with the new LangChain PostgreSQL package. This eliminates the need to move your data to a new schema.

from langchain_postgres import PGEngine, PGVectorStore
from langchain_google_vertexai import VertexAIEmbeddings

vectorstore = PGVectorStore.create_sync(
    engine=engine,
    table_name="products",
    embedding_service=VertexAIEmbeddings(model_name="text-embedding-005"),
    metadata_columns=["color", "price"]
)

results = vectorstore.similarity_search("maroon puffer jacket")
# Filter your vector search using metadata fields
results = vectorstore.similarity_search("maroon puffer jacket", filter={"price": {"$lt": 200.0}})

Production-ready features

Google Cloud developed first-class integrations for asynchronous drivers in the LangChain package and implemented vector index management to enable LangChain applications that can grow to production. You can take advantage of non-blocking I/O operations with asynchronous drivers, which can result in notable performance improvements. This enables your application to scale efficiently while reducing resource consumption and increasing responsiveness, enabling it to manage a higher volume of concurrent requests.

Additionally, it has incorporated the capability of directly creating and maintaining vector indexes from within LangChain. This gives you the ability to use an infrastructure-as-code strategy for your vector search, allowing you to use LangChain to specify and implement your complete application stack, from database schema to vector index setup. By utilizing the speed of asynchronous operations and the strength of vector search, this end-to-end integration simplifies the development process and enables the smooth setup and administration of AI-powered applications from LangChain.

Google Cloud previously improved its own LangChain packages for Google Cloud databases. It took those improvements out of its packages, upstreamed them, and released them into the LangChain PostgreSQL package so that developers on any platform could use them. Software libraries must have high-quality database integrations to leverage your data, as databases are becoming more and more essential to Generative AI applications. These databases enable users to ground LLMs, act as knowledge bases for RAG applications, and power high-quality vector search.

Get started

Get a quickstart application and get the langchain-postgres package now! To switch from the previous iteration of the langchain-postgres package to Google’s, follow this guide. Utilise the LangChain package in AlloyDB and Cloud SQL for PostgreSQL to take advantage of GCP-specific features like the ScaNN index in AlloyDB AI. Start using MCP Toolbox to create agentic applications.

RELATED ARTICLES

Page Content

Recent Posts

Index