PostgresVectorStore class.
Overview
Integration details
| Class | Package | PY support | Version |
|---|---|---|---|
| PostgresVectorStore | @langchain/google-cloud-sql-pg | ✅ | 0.0.1 |
Before you begin
In order to use this package, you first need to go throught the following steps:- Select or create a Cloud Platform project.
- Enable billing for your project.
- Enable the Cloud SQL Admin API.
- Setup Authentication.
- Create a CloudSQL instance
- Create a CloudSQL database
- Add a user to the database
Authentication
Authenticate locally to your Google Cloud account using thegcloud auth login command.
Set Your Google Cloud Project
Set your Google Cloud project ID to leverage Google Cloud resources locally:- Run
gcloud config list. - Run
gcloud projects list. - See the support page: Locate the project ID.
Setting up a PostgresVectorStore instance
To use the PostgresVectorStore library, you’ll need to install the@langchain/google-cloud-sql-pg package and then follow the steps bellow.
First, you’ll need to log in to your Google Cloud account and set the following environment variables based on your Google Cloud project; these will be defined based on how you want to configure (fromInstance, fromEngine, fromEngineArgs) your PostgresEngine instance :
Setting up an instance
To instantiate a PostgresVectorStore, you’ll first need to create a database connection through the PostgresEngine, then initialize the vector store table and finally call the.initialize() method to instantiate the vector store.
Manage Vector Store
Add Documents to vector store
To add Documents to the vector store, you would be able to it by passing or not the idsDelete Documents from vector store
You can delete one or more Documents from the vector store by passing the arrays of ids to be deleted:Search for documents
Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.Query directly
Performing a simple similarity search can be done as follows:Query by using the max marginal relevance search
The Maximal marginal relevance optimizes for similarity to the query and diversity among selected documents.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.