From 54729755570b77366e37efc0febb448d5db5f383 Mon Sep 17 00:00:00 2001 From: Boris Arzentar Date: Thu, 5 Jun 2025 15:07:37 +0200 Subject: [PATCH] fix: use docker qdrant for tests --- .github/workflows/vector_db_tests.yml | 19 +++++++++++++++++-- .../databases/vector/qdrant/QDrantAdapter.py | 8 +++++--- cognee/tests/test_qdrant.py | 6 +++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/vector_db_tests.yml b/.github/workflows/vector_db_tests.yml index 139c869d3..dd94ff298 100644 --- a/.github/workflows/vector_db_tests.yml +++ b/.github/workflows/vector_db_tests.yml @@ -135,6 +135,21 @@ jobs: run: shell: bash + services: + qdrant: + image: qdrant/qdrant:1.14.1 + env: + QDRANT__LOG_LEVEL: ERROR + QDRANT__SERVICE__API_KEY: qdrant_api_key + QDRANT__SERVICE__ENABLE_TLS: 0 + options: >- + --health-cmd "curl 127.0.0.1:6333 || exit 1" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6333:6333 + steps: - name: Check out uses: actions/checkout@master @@ -159,8 +174,8 @@ jobs: EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }} EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }} EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }} - VECTOR_DB_URL: ${{ secrets.QDRANT_API_URL }} - VECTOR_DB_KEY: ${{ secrets.QDRANT_API_KEY }} + VECTOR_DB_URL: 127.0.0.1 + VECTOR_DB_KEY: qdrant_api_key run: poetry run python ./cognee/tests/test_qdrant.py run-postgres-tests: diff --git a/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py b/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py index 4e3e677bf..1532176de 100644 --- a/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py +++ b/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py @@ -1,3 +1,4 @@ +import os from typing import Dict, List, Optional from qdrant_client import AsyncQdrantClient, models @@ -147,14 +148,15 @@ class QDrantAdapter(VectorDBInterface): Returns: -------- - - AsyncQdrantClient: An instance of AsyncQdrantClient configured for database operations. """ + is_prod = os.getenv("ENV").lower() == "prod" + if self.qdrant_path is not None: - return AsyncQdrantClient(path=self.qdrant_path, port=6333) + return AsyncQdrantClient(path=self.qdrant_path, port=6333, https=is_prod) elif self.url is not None: - return AsyncQdrantClient(url=self.url, api_key=self.api_key, port=6333) + return AsyncQdrantClient(url=self.url, api_key=self.api_key, port=6333, https=is_prod) return AsyncQdrantClient(location=":memory:") diff --git a/cognee/tests/test_qdrant.py b/cognee/tests/test_qdrant.py index 0e725f2f2..8d881e68f 100644 --- a/cognee/tests/test_qdrant.py +++ b/cognee/tests/test_qdrant.py @@ -49,7 +49,11 @@ async def main(): from cognee.infrastructure.databases.vector import get_vector_engine vector_engine = get_vector_engine() - random_node = (await vector_engine.search("Entity_name", "Quantum computer"))[0] + search_results = await vector_engine.search("Entity_name", "Quantum computer") + + assert len(search_results) != 0, "The search results list is empty." + + random_node = search_results[0] random_node_name = random_node.payload["text"] search_results = await cognee.search(