Skip to content

Commit d4b24b0

Browse files
feat: add pgvector to postgres stack
1 parent be08c56 commit d4b24b0

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/opencodeco/stack/main/in
1717
| `stack mysql`| MySQL & phpMyAdmin (http://localhost:8031) |
1818
| `stack redis` | Redis & RedisInsight (http://localhost:8032) |
1919
| `stack mongo` | MongoDB & Mongo Express (http://localhost:8033) |
20-
| `stack postgres` | PostgreSQL & pgAdmin (http://localhost:8039) |
20+
| `stack postgres` | PostgreSQL with pgvector & pgAdmin (http://localhost:8039) |
2121
| `stack kafka` | Kafka and UI for Apache Kafka (http://localhost:8037) |
2222
| `stack rabbitmq` | RabbitMQ & Management Plugin (http://localhost:8038) |
2323
| `stack aws` | AWS services via LocalStack _(legacy, [see details below](#aws-localstack-vs-ministack))_ (http://localhost:4566) |
2424
| `stack aws-ministack` | AWS services via MiniStack (http://localhost:4567) |
2525
| `stack hyperdx` | HyperDX local (http://localhost:8080) |
2626
| `stack o11y` | OpenTelemetry Collector, Jaeger UI, Prometheus & Grafana (see below) |
2727

28+
`stack postgres` includes [pgvector](https://github.com/pgvector/pgvector). Enable it in each database where it is needed with `CREATE EXTENSION vector;`.
29+
2830
### Observability (o11y)
2931

3032
| Component | Description | Port |

postgres/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM pgvector/pgvector:0.8.5-pg17-bookworm AS pgvector
2+
3+
FROM postgres:17.4
4+
5+
COPY --from=pgvector /usr/lib/postgresql/17/lib/vector.so /usr/lib/postgresql/17/lib/
6+
COPY --from=pgvector /usr/share/postgresql/17/extension/vector* /usr/share/postgresql/17/extension/

postgres/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
services:
22
opencodeco-postgres:
33
container_name: opencodeco-postgres
4-
image: postgres:17.4
4+
build: .
5+
image: opencodeco-postgres:17.4-pgvector
56
restart: always
67
ports:
78
- ${POSTGRES_PORT}:5432

tests/test-postgres.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ assert_contains "create table, insert, and select" "hello" "$result"
2929
db_list=$(docker exec opencodeco-postgres psql -U postgres -tAc "SELECT datname FROM pg_database;" 2>&1)
3030
assert_contains "default postgres database exists" "postgres" "$db_list"
3131

32+
vector_result=$(docker exec opencodeco-postgres psql -v ON_ERROR_STOP=1 -U postgres -tAc "
33+
CREATE EXTENSION IF NOT EXISTS vector;
34+
CREATE TABLE stack_vector_test (id SERIAL PRIMARY KEY, embedding vector(3));
35+
INSERT INTO stack_vector_test (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
36+
SELECT id FROM stack_vector_test ORDER BY embedding <-> '[1,2,3]' LIMIT 1;
37+
DROP TABLE stack_vector_test;
38+
" 2>&1)
39+
assert_eq "pgvector nearest-neighbor query" "1" "$vector_result"
40+
3241
report

0 commit comments

Comments
 (0)