DEV Community

Setup PostgreSQL w/ pgvector in a docker container

This post explains how to set up a local instance of pgvector, a vector database, in a Docker container. Pgvector is a popular option for vector similarity search in Postgres and is often used in RAG (Retrieval Augmented Generation) pipelines. To start, pull the latest pgvector image from the Docker repository, specifying the desired Postgres server version. Run the image, setting the root user password and exposing the default Postgres port. Create a database inside the container using the docker exec command. Connect to the database from your application, installing the required dependencies and setting a DATABASE_URL environment variable. Create a connection to the database using the pg.Pool class and initialize the pgvector extension. Create a new table using the PGVectorStore.initialize method. With the vectorStore set up, you can add content and query for context using the vectorStore.addDocuments and vectorStore.similaritySearch methods. This setup provides a foundation for further exploration of pgvector's capabilities.
favicon
dev.to
dev.to