PGVectorStore
PGVectorStore
is an implementation of a LangChain vectorstore using postgres
as the backend.
This notebook goes over how to use the PGVectorStore
API.
The code lives in an integration package called: langchain-postgres.
Setup
This package requires a PostgreSQL database with the pgvector
extension.
You can run the following command to spin up a container for a pgvector
enabled Postgres instance:
docker run --name pgvector-container -e POSTGRES_USER=langchain -e POSTGRES_PASSWORD=langchain -e POSTGRES_DB=langchain -p 6024:5432 -d pgvector/pgvector:pg16
Install
Install the integration library, langchain-postgres
.
%pip install --upgrade --quiet langchain-postgres
# This notebook also requires the following dependencies
%pip install --upgrade --quiet langchain-core langchain-cohere sqlalchemy
Set your Postgres values
Set your Postgres values to test the functionality in this notebook against a Postgres instance.
# @title Set your values or use the defaults to connect to Docker { display-mode: "form" }
POSTGRES_USER = "langchain" # @param {type: "string"}
POSTGRES_PASSWORD = "langchain" # @param {type: "string"}
POSTGRES_HOST = "localhost" # @param {type: "string"}
POSTGRES_PORT = "6024" # @param {type: "string"}
POSTGRES_DB = "langchain" # @param {type: "string"}
TABLE_NAME = "vectorstore" # @param {type: "string"}
VECTOR_SIZE = 1024 # @param {type: "int"}