Build LLM-powered applications using LangChain Stay organized with collections Save and categorize content based on your preferences.
Preview — LangChain
This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.
This page introduces how to build LLM-powered applications usingLangChain. The overviews on thispage link to procedure guides in GitHub.
What is LangChain?
LangChain is an LLM orchestration framework that helps developers buildgenerative AI applications or retrieval-augmented generation (RAG) workflows. Itprovides the structure, tools, and components to streamline complex LLMworkflows.
For more information about LangChain, see theGoogleLangChain page. For more information about the LangChain framework, see theLangChain product documentation.
LangChain components for Cloud SQL for PostgreSQL
Cloud SQL for PostgreSQL offers the following LangChain interfaces:
Learn how to use LangChain with theLangChain Quickstart forCloud SQL for PostgreSQL.
Vector store for Cloud SQL for PostgreSQL
Vector store retrieves and stores documents and metadata from a vector database.Vector store gives an application the ability to perform semantic searches thatinterpret the meaning of a user query. This type of search is a called avector search, and it can find topics that match the query conceptually. Atquery time, vector store retrieves the embedding vectors that aremost similar to the embedding of the search request. In LangChain, a vectorstore takes care of storing embedded data and performing the vector searchfor you.
To work with vector store in Cloud SQL for PostgreSQL, use thePostgresVectorStore
class.
For more information, see theLangChain VectorStores product documentation.
Vector store procedure guide
TheCloud SQL for PostgreSQL guide for vectorstore shows you how to do the following:
- Install the integration package and LangChain
- Create a
PostgresEngine
object and configure a connection pool to yourCloud SQL for PostgreSQL database - Initialize a table
- Create an embedding object using
VertexAIEmbeddings
- Initialize a default
PostgresVectorStore
- Add texts
- Delete texts
- Search for documents
- Search for documents by vector
- Add an index to accelerate vector search queries
- Re-index
- Remove an index
- Create a custom vector store
- Search for documents with a metadata filter
Document loader for Cloud SQL for PostgreSQL
The document loader saves, loads, and deletes a LangChainDocument
objects. For example, you can load data for processing into embeddings andeither store it in vector store or use it as a tool to provide specific contextto chains.
To load documents from document loader in Cloud SQL for PostgreSQL, use thePostgresLoader
class.PostgresLoader
returns a list of documents from atable using the first column for page content and all other columns formetadata. The default table has the first column as page content and the secondcolumn as JSON metadata. Each row becomes a document. Use thePostgresDocumentSaver
class to save and delete documents.
For more information, see theLangChain Documentloaders topic.
Document loader procedure guide
TheCloud SQL for PostgreSQL guide for documentloader shows you how to do the following:
- Install the integration package and LangChain
- Load documents from a table
- Add a filter to the loader
- Customize the connection and authentication
- Customize Document construction by specifying customer content and metadata
- How to use and customize a
PostgresDocumentSaver
to store and deletedocuments
Chat message history for Cloud SQL for PostgreSQL
Question and answer applications require a history of the things said in theconversation to give the application context for answering further questionsfrom the user. The LangChainChatMessageHistory
class lets the applicationsave messages to a database and retrieve them when needed to formulate furtheranswers. A message can be a question, an answer, a statement, a greeting or anyother piece of text that the user or application gives during the conversation.ChatMessageHistory
stores each message and chains messages together for eachconversation.
Cloud SQL for PostgreSQL extends this class withPostgresChatMessageHistory
.
Chat message history procedure guide
TheCloud SQL for PostgreSQL guide for chat messagehistory shows you how to do the following:
- Install LangChain and authenticate to Google Cloud
- Create a
PostgresEngine
object and configure a connection pool to yourCloud SQL for PostgreSQL database - Initialize a table
- Initialize the
PostgresChatMessageHistory
class to add and delete messages - Create a chain for message history using the LangChain Expression Language(LCEL) and Google's Vertex AI chat models
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-14 UTC.