Postgres + PgVector
1.1K
pgvector with DockerThis guide provides step-by-step instructions to run a Docker container with PostgreSQL and the pgvector extension. It includes commands to verify the extension, create a table, insert data, and perform queries.
Run the Docker Container:
docker run --name pgvector-test -e POSTGRES_PASSWORD=postgres -d azaddjan/pgvector:v0.8.0-postgres17
This command starts a PostgreSQL container with the pgvector extension pre-installed.
Connect to the PostgreSQL Instance:
docker exec -it pgvector-test psql -U postgres
This connects you to the PostgreSQL instance using the psql CLI tool.
Verify the pgvector Extension:
Run the following SQL command to check if the vector extension is available:
SELECT * FROM pg_available_extensions WHERE name = 'vector';
Create a Table with a Vector Column: Create a table with a column to store vectors:
CREATE TABLE items (id serial primary key, embedding vector(3));
Insert Data into the Table: Insert a vector into the table:
INSERT INTO items (embedding) VALUES ('[1, 2, 3]');
Query Data from the Table: Retrieve the data from the table:
SELECT * FROM items;
Exit the PostgreSQL CLI: Use the following command to exit:
\q
Stop and Remove the Docker Container: Stop the container:
docker stop pgvector-test
Remove the container:
docker rm pgvector-test
This guide demonstrates how to set up and test the pgvector extension in a PostgreSQL database running in a Docker container. It covers essential operations such as verifying the extension, creating tables, inserting data, and performing queries. Once done, the container can be stopped and removed to free up resources.
Content type
Image
Digest
sha256:0713a7d9a…
Size
595.6 MB
Last updated
almost 2 years ago
docker pull azaddjan/pgvector