GCP – Announcing open-source enhancements to LangChain PostgreSQL
At Google Cloud Next ‘25, we announced upgrades to the core LangChain Postgres package and became a major contributor to the library. These improvements underscore our vision that every application developer is a gen AI developer – one that is empowered to build database-backed agentic gen AI applications leveraging open source tools.
LangChain is an open-source framework designed to simplify the development of agentic gen AI applications powered by large language models (LLMs). It provides interfaces for connecting LLMs to external data sources, enabling more context-aware and powerful AI applications. To effectively manage and retrieve information from structured data, LangChain often needs to interact with databases. The langchain-postgres package specifically provides integrations that allow LangChain to connect to and utilize PostgreSQL databases for tasks such as storing chat history, acting as a vector store for embeddings, and loading documents. This integration is crucial for building chatbots with memory, performing semantic searches, and leveraging existing relational data within LLM-powered applications.
Our updates bring optimized performance through asynchronous PostgreSQL drivers, faster SQL filtering via relational metadata columns, and robust connection pooling for enterprise-level scalability. Furthermore, we’ve integrated:
-
Vector index support so that developers can set up their vector database from LangChain
-
Support for flexible database schemas to build more powerful applications that are easier to maintain
-
Enhanced LangChain vector store APIs with a clear separation of database setup and usage, adhering to the principle of least privilege, for improved security.
- aside_block
- <ListValue: [StructValue([(‘title’, ‘$300 in free credit to try Google Cloud AI and ML’), (‘body’, <wagtail.rich_text.RichText object at 0x3e3f950c9250>), (‘btn_text’, ‘Start building for free’), (‘href’, ‘http://console.cloud.google.com/freetrial?redirectPath=/vertex-ai/’), (‘image’, None)])]>
What’s new
Enhanced security and connectivity
Building robust and secure generative AI applications requires careful consideration of how your application interacts with the underlying data infrastructure. With our contributions to the LangChain Postgres package, we’ve prioritized enhanced security and efficient connectivity through several key improvements.
We have focused on adhering to the principle of least privilege. The enhanced API now clearly separates the permissions required for database schema creation from those needed for routine application usage. This separation allows you to grant restrictive permissions to the application layer, limiting its ability to modify the underlying database structure. By isolating these responsibilities, you significantly reduce the potential attack surface and enhance the overall security posture of your AI applications.
Furthermore, by maintaining a pool of active database connections, we minimize the overhead of establishing new connections for each query. This not only leads to significant performance improvements, especially in high-throughput environments, but also contributes to the stability of your application by managing resource utilization effectively, ensuring that you don’t end up with dozens of unused active PostgreSQL connections.
Improved schema design
Previously, the langchain-postgres package only allowed for new schema creation with fixed table names and a single json metadata column, emulating the data model of purpose built vector databases. But one of the benefits of using PostgreSQL databases as a vector database is that you can leverage PostgreSQL’s rich querying capabilities to improve the quality of your vector search by using filters on non-vector columns. With our improvements to the LangChain postgres package, you can define distinct metadata columns so that you are able to combine vector search queries with SQL filters when you query your vector store.
If you have a pre-existing database schema for PostgreSQL, you can now leverage that data with the new LangChain PostgreSQL package without needing to migrate your data to a new schema, allowing you to transform your operational workload to an AI workload with just a few lines of code!
- code_block
- <ListValue: [StructValue([(‘code’, ‘from langchain_postgres import PGEngine, PGVectorStorernfrom langchain_google_vertexai import VertexAIEmbeddingsrnrnvectorstore = PGVectorStore.create_sync(rn engine=engine,rn table_name=”products”,rn embedding_service=VertexAIEmbeddings(model_name=”text-embedding-005″),rn metadata_columns=[“color”, “price”]rn)rnrnresults = vectorstore.similarity_search(“maroon puffer jacket”)rn# Filter your vector search using metadata fieldsrnresults = vectorstore.similarity_search(“maroon puffer jacket”, filter={“price”: {“$lt”: 200.0}})’), (‘language’, ‘lang-py’), (‘caption’, <wagtail.rich_text.RichText object at 0x3e3f950c9700>)])]>
Production-ready features
To support LangChain applications that can scale to production we created first class integrations for asynchronous drivers in the LangChain package and introduced vector index management. Asynchronous drivers allow you to leverage non-blocking I/O operations, leading to significant performance gains. This allows your application to handle a greater volume of concurrent requests with efficiency, scaling effectively while minimizing resource consumption and maximizing responsiveness.
Furthermore, we’ve integrated the ability to create and maintain vector indexes directly from within LangChain. This empowers you to adopt an infrastructure-as-code approach for your vector search, enabling you to define and deploy your entire application stack, from database schema to vector index configuration, using LangChain. This end-to-end integration streamlines the development process, allowing for seamless setup and management of AI-powered applications leveraging the speed of asynchronous operations and the power of vector search all from LangChain.
These are enhancements we previously made to our own LangChain packages for Google Cloud databases, We extracted them from our packages, upstreamed and published those changes into the LangChain PostgreSQL package, allowing developers on any platform to leverage our improvements. As databases have become more and more crucial to Generative AI applications, allowing users to ground LLMs, serving as knowledge bases for RAG applications, and powering high quality vector search, it is increasingly important for software libraries to have high quality integrations with databases so you can capitalize on your data.
Get started
Download the langchain-postgres package today, and get started with a quickstart application! Follow this tutorial to migrate from the prior version of the langchain-postgres to Google’s langchain-postgres package. Use AlloyDB and Cloud SQL for PostgreSQL’s LangChain package to leverage GCP specific features such as AlloyDB AI’s ScaNN index. Get started building agentic applications with MCP Toolbox.
Get started with Google Cloud databases with a free trial for AlloyDB or Cloud SQL.
Read More for the details.