From f09b5b0ea4d4f11f5255fd923db60951cc809538 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Fri, 27 Feb 2026 00:17:39 +0530 Subject: [PATCH] refactor: replace hardcoded embedding dimension with dynamic configuration - Updated the embedding dimension in test configurations to use the value from the application config, enhancing maintainability and consistency across tests. --- surfsense_backend/tests/integration/conftest.py | 3 ++- .../integration/indexing_pipeline/test_index_document.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/surfsense_backend/tests/integration/conftest.py b/surfsense_backend/tests/integration/conftest.py index 119045d29..9dff257df 100644 --- a/surfsense_backend/tests/integration/conftest.py +++ b/surfsense_backend/tests/integration/conftest.py @@ -8,6 +8,7 @@ from sqlalchemy import text from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.pool import NullPool +from app.config import config as app_config from app.db import ( Base, DocumentType, @@ -18,7 +19,7 @@ from app.db import ( ) from app.indexing_pipeline.connector_document import ConnectorDocument -_EMBEDDING_DIM = 1024 # must match the Vector() dimension used in DB column creation +_EMBEDDING_DIM = app_config.embedding_model_instance.dimension _DEFAULT_TEST_DB = ( "postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test" diff --git a/surfsense_backend/tests/integration/indexing_pipeline/test_index_document.py b/surfsense_backend/tests/integration/indexing_pipeline/test_index_document.py index 0065a03e1..2e8ee4d92 100644 --- a/surfsense_backend/tests/integration/indexing_pipeline/test_index_document.py +++ b/surfsense_backend/tests/integration/indexing_pipeline/test_index_document.py @@ -1,9 +1,12 @@ import pytest from sqlalchemy import select +from app.config import config as app_config from app.db import Chunk, Document, DocumentStatus from app.indexing_pipeline.indexing_pipeline_service import IndexingPipelineService +_EMBEDDING_DIM = app_config.embedding_model_instance.dimension + pytestmark = pytest.mark.integration @@ -144,7 +147,7 @@ async def test_embedding_written_to_db( reloaded = result.scalars().first() assert reloaded.embedding is not None - assert len(reloaded.embedding) == 1024 + assert len(reloaded.embedding) == _EMBEDDING_DIM @pytest.mark.usefixtures(