Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
postgres:
# ensure postgres version this stays in sync with prod database
# and with postgres version used in docker compose
image: postgres:16
# Testing with postgres that has the pg vector extension
image: ankane/pgvector
env:
# optional (defaults to `postgres`)
POSTGRES_DB: langchain_test
Expand Down Expand Up @@ -67,7 +68,6 @@ jobs:
name: Python ${{ matrix.python-version }} tests
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
Expand All @@ -91,10 +91,14 @@ jobs:
run: |
echo "Running tests, installing dependencies with poetry..."
poetry install --with test,lint,typing,docs

- name: Run tests
run: make test

env:
POSTGRES_DB: langchain_test
POSTGRES_PASSWORD: langchain
POSTGRES_USER: langchain
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
- name: Ensure the tests did not create any additional files
shell: bash
run: |
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ build-backend = "poetry.core.masonry.api"
# --snapshot-warn-unused Prints a warning on unused snapshots rather than fail the test suite.
addopts = "--strict-markers --strict-config --durations=5"
# Global timeout for all tests. There should be a good reason for a test to
# takemore than 5 seconds.
timeout = 5
# takemore than 30 seconds.
timeout = 30
# Registering custom markers.
# https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markers
markers = [
]
markers = []
asyncio_mode = "auto"

21 changes: 3 additions & 18 deletions tests/unit_tests/test_vectorstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test PGVector functionality."""

import os
from typing import Any, Dict, Generator, List

import pytest
Expand All @@ -21,23 +20,9 @@
TYPE_4_FILTERING_TEST_CASES,
TYPE_5_FILTERING_TEST_CASES,
)
from tests.utils import VECTORSTORE_CONNECTION_STRING

# 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", "psycopg"),
host=os.environ.get("TEST_PGVECTOR_HOST", "localhost"),
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"),
)

CONNECTION_STRING = VECTORSTORE_CONNECTION_STRING
ADA_TOKEN_COUNT = 1536


Expand Down Expand Up @@ -411,7 +396,7 @@ def pgvector() -> Generator[PGVector, None, None]:
store.drop_tables()


@pytest.mark.parametrize("test_filter, expected_ids", TYPE_1_FILTERING_TEST_CASES[:1])
@pytest.mark.parametrize("test_filter, expected_ids", TYPE_1_FILTERING_TEST_CASES)
def test_pgvector_with_with_metadata_filters_1(
pgvector: PGVector,
test_filter: Dict[str, Any],
Expand Down
23 changes: 16 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@
import psycopg
from typing_extensions import AsyncGenerator, Generator

# Env variables match the default settings in the docker-compose file
# located in the root of the repository: [root]/docker-compose.yml
# Non-standard ports are used to avoid conflicts with other local postgres
# instances.
# To spint up the postgres service for testing, run:
# cd [root]/docker-compose.yml
# docker-compose up pgvector
POSTGRES_USER = os.environ.get("POSTGRES_USER", "langchain")
POSTGRES_HOST = os.environ.get("POSTGRES_HOST", "localhost")
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD", "langchain")
POSTGRES_DB = os.environ.get("POSTGRES_DB", "langchain")


# Using a different port for testing than the default 5432
# to avoid conflicts with a running PostgreSQL instance
# This port matches the convention in langchain/docker/docker-compose.yml
# To spin up a PostgreSQL instance for testing, run:
# docker-compose -f docker/docker-compose.yml up -d postgres
POSTGRES_PORT = os.environ.get("POSTGRES_PORT", "6023")
POSTGRES_PORT = os.environ.get("POSTGRES_PORT", "6024")

DSN = (
f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}"
f":{POSTGRES_PORT}/{POSTGRES_DB}"
)

# Connection string used primarily by the vectorstores tests
# it's written to work with SQLAlchemy (takes a driver name)
# It is also running on a postgres instance that has the pgvector extension
VECTORSTORE_CONNECTION_STRING = (
f"postgresql+psycopg://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}"
f":{POSTGRES_PORT}/{POSTGRES_DB}"
)


@asynccontextmanager
async def asyncpg_client() -> AsyncGenerator[psycopg.AsyncConnection, None]:
Expand Down