PostgresLoader class.
Overview
Before you begin
In order to use this package, you first need to go through 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 PostgresLoader instance
To use the PostgresLoader class, 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 PostgresLoader, you’ll first need to create a database connection through the PostgresEngine.Load Documents using the table_name argument
The loader returns a list of Documents from the table using the first column as page_content and all other columns as metadata. The default table will have the first column as page_content and the second column as metadata (JSON). Each row becomes a document.Load Documents using a SQL query
The query parameter allows users to specify a custom SQL query which can include filters to load specific documents from a database.Set page content format
The loader returns a list of Documents, with one document per row, with page content in specified string format, i.e. text (space separated concatenation), JSON, YAML, CSV, etc. JSON and YAML formats include headers, while text and CSV do not include field headers.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.