diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c3600a8caf9..41564f7184b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -52,6 +52,28 @@ services: retries: 60 volumes: - postgres_data:/var/lib/postgresql/data + pgvector: + # postgres with the pgvector extension + image: ankane/pgvector + environment: + POSTGRES_DB: langchain + POSTGRES_USER: langchain + POSTGRES_PASSWORD: langchain + ports: + - "6024:5432" + command: | + postgres -c log_statement=all + healthcheck: + test: + [ + "CMD-SHELL", + "psql postgresql://langchain:langchain@localhost/langchain --command 'SELECT 1;' || exit 1", + ] + interval: 5s + retries: 60 + volumes: + - postgres_data_pgvector:/var/lib/postgresql/data volumes: postgres_data: + postgres_data_pgvector: diff --git a/libs/community/tests/integration_tests/vectorstores/test_pgvector.py b/libs/community/tests/integration_tests/vectorstores/test_pgvector.py index db0b9ee7a0c..742546ff31b 100644 --- a/libs/community/tests/integration_tests/vectorstores/test_pgvector.py +++ b/libs/community/tests/integration_tests/vectorstores/test_pgvector.py @@ -9,13 +9,20 @@ from sqlalchemy.orm import Session from langchain_community.vectorstores.pgvector import PGVector from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings +# The connection string matches the default settings in the docker-compose file +# located in the root of the repository: [root]/docker/docker-compose.yml +# Non-standard ports are used to avoid conflicts with other local postgres +# instances. +# To spin up postgres with the pgvector extension: +# cd [root]/docker/docker-compose.yml +# docker compose up pgvector CONNECTION_STRING = PGVector.connection_string_from_db_params( driver=os.environ.get("TEST_PGVECTOR_DRIVER", "psycopg2"), host=os.environ.get("TEST_PGVECTOR_HOST", "localhost"), - port=int(os.environ.get("TEST_PGVECTOR_PORT", "5432")), - database=os.environ.get("TEST_PGVECTOR_DATABASE", "postgres"), - user=os.environ.get("TEST_PGVECTOR_USER", "postgres"), - password=os.environ.get("TEST_PGVECTOR_PASSWORD", "postgres"), + port=int(os.environ.get("TEST_PGVECTOR_PORT", "6024")), + database=os.environ.get("TEST_PGVECTOR_DATABASE", "langchain"), + user=os.environ.get("TEST_PGVECTOR_USER", "langchain"), + password=os.environ.get("TEST_PGVECTOR_PASSWORD", "langchain"), ) ADA_TOKEN_COUNT = 1536