diff --git a/docker-compose-postgres.yml b/docker-compose-postgres.yml index 515e650b..661ff949 100644 --- a/docker-compose-postgres.yml +++ b/docker-compose-postgres.yml @@ -1,5 +1,8 @@ # Docker Compose configuration for Basic Memory with PostgreSQL -# Use this for local development and testing with Postgres backend +# Use this for local development and testing with Postgres backend. +# +# The Postgres backend requires the pgvector extension (semantic search). +# This image bundles pgvector; plain postgres:17 will not work for vector search. # # Usage: # docker-compose -f docker-compose-postgres.yml up -d @@ -7,7 +10,7 @@ services: postgres: - image: postgres:17 + image: pgvector/pgvector:pg17 container_name: basic-memory-postgres environment: # Local development/test credentials - NOT for production diff --git a/docs/semantic-search.md b/docs/semantic-search.md index 1706f8fa..bd9f59ab 100644 --- a/docs/semantic-search.md +++ b/docs/semantic-search.md @@ -263,6 +263,7 @@ The sqlite-vec extension is loaded per-connection. Vector tables are created laz ### Postgres (cloud) - **Vector storage**: [pgvector](https://github.com/pgvector/pgvector) with HNSW indexing +- **Local Docker**: use `docker-compose-postgres.yml` (`pgvector/pgvector:pg17`). Plain `postgres:17` lacks the extension; run `CREATE EXTENSION IF NOT EXISTS vector;` on any external instance before first migration. - **Chunk metadata table**: Created via Alembic migration (`search_vector_chunks` with `BIGSERIAL` primary key) - **Embedding table**: `search_vector_embeddings` created at runtime (dimension-dependent, same pattern as SQLite) - **Index**: HNSW index on the embedding column for fast approximate nearest-neighbour queries diff --git a/tests/README.md b/tests/README.md index 4d6d7b28..980a32b0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,6 +10,8 @@ pytest # Run tests against Postgres only (requires docker-compose) docker-compose -f docker-compose-postgres.yml up -d +BASIC_MEMORY_TEST_POSTGRES=1 \ +POSTGRES_TEST_URL=postgresql+asyncpg://basic_memory_user:dev_password@localhost:5433/basic_memory \ pytest -m postgres # Run tests against BOTH backends @@ -54,7 +56,7 @@ database_url = None # Uses default SQLite path # Postgres config database_backend = DatabaseBackend.POSTGRES -database_url = "postgresql+asyncpg://basic_memory_user:dev_password@localhost:5433/basic_memory_test" +database_url = "postgresql+asyncpg://basic_memory_user:dev_password@localhost:5433/basic_memory" ``` ## Running Postgres Tests @@ -66,18 +68,22 @@ docker-compose -f docker-compose-postgres.yml up -d ``` This starts: -- Postgres 17 on port **5433** (not 5432 to avoid conflicts) -- Test database: `basic_memory_test` +- Postgres 17 with **pgvector** (`pgvector/pgvector:pg17`) on port **5433** (not 5432 to avoid conflicts) +- Database: `basic_memory` - Credentials: `basic_memory_user` / `dev_password` ### 2. Run Postgres Tests ```bash # Run only Postgres tests +BASIC_MEMORY_TEST_POSTGRES=1 \ +POSTGRES_TEST_URL=postgresql+asyncpg://basic_memory_user:dev_password@localhost:5433/basic_memory \ pytest -m postgres # Run specific test with Postgres -pytest tests/test_entity_repository.py::test_create -m postgres +BASIC_MEMORY_TEST_POSTGRES=1 \ +POSTGRES_TEST_URL=postgresql+asyncpg://basic_memory_user:dev_password@localhost:5433/basic_memory \ +pytest tests/repository/test_entity_repository.py::test_create -m postgres # Skip Postgres tests (default behavior) pytest -m "not postgres" @@ -121,7 +127,7 @@ jobs: # Postgres service container services: postgres: - image: postgres:17 + image: pgvector/pgvector:pg17 env: POSTGRES_DB: basic_memory_test POSTGRES_USER: basic_memory_user @@ -169,4 +175,4 @@ docker-compose -f docker-compose-postgres.yml exec postgres pg_isready -U basic_ - [ ] Add `--run-all-backends` CLI flag to run both backends in sequence - [ ] Implement test fixtures for backend-specific features (e.g., Postgres full-text search vs SQLite FTS5) -- [ ] Add performance comparison benchmarks between backends \ No newline at end of file +- [ ] Add performance comparison benchmarks between backends