Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
refactor(api): type-check vector store provider unit tests (#44458)
Eddy ZHANG0ebe43fee21d
diff --git a/api/core/rag/datasource/vdb/vector_integration_test_support.py b/api/core/rag/datasource/vdb/vector_integration_test_support.pyindex 3148b7d5c14..646f7eb3ca8 100644--- a/api/core/rag/datasource/vdb/vector_integration_test_support.py+++ b/api/core/rag/datasource/vdb/vector_integration_test_support.py@@ -1,4 +1,4 @@-"""Shared helpers for vector DB integration tests (used by workspace packages under ``api/packages``).+"""Shared helpers for vector DB provider tests (used by workspace packages under ``api/packages``).:class:`AbstractVectorTest` and helper functions live here so package tests can import``core.rag.datasource.vdb.vector_integration_test_support`` without relying on the@@ -8,7 +8,9 @@ The ``setup_mock_redis`` fixture lives in ``api/packages/conftest.py`` and isauto-discovered by pytest for all package tests."""+import typesimport uuid+from typing import overrideimport pytest@@ -17,6 +19,17 @@ from core.rag.models.document import Documentfrom models.dataset import Dataset+class FakeModule(types.ModuleType):+ """A stand-in SDK module for provider unit tests, whose attributes the test sets one by one.++ Declaring ``__setattr__`` lets the type checker accept those assignments on a module object.+ """++ @override+ def __setattr__(self, name: str, value: object) -> None:+ super().__setattr__(name, value)++def get_example_text() -> str:return "test_text"diff --git a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.pyindex de170fedd59..e699fb27135 100644--- a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py+++ b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py@@ -360,8 +360,8 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):# Simulate table doesn't exist error on delete- def execute_side_effect[**P](*args: P.args, **kwargs: P.kwargs):- if "DELETE" in args[0]:+ def execute_side_effect(sql: str, *_args: object) -> None:+ if "DELETE" in sql:raise MySQLError(errno=1146, msg="Table doesn't exist")mock_cursor.execute.side_effect = execute_side_effect@@ -645,7 +645,7 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):password="test_password",database="test_db",max_connection=5,- distance_function="manhattan", # Unsupported - not in Literal["cosine", "euclidean"]+ distance_function="manhattan", # pyrefly: ignore[bad-argument-type] # not "cosine" or "euclidean")# The error should be related to validationdiff --git a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.pyindex 26bd3853338..d1a86241e29 100644--- a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py+++ b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py@@ -1,6 +1,5 @@import jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock@@ -11,6 +10,7 @@ from dify_vdb_analyticdb.analyticdb_vector_openapi import (AnalyticdbVectorOpenAPIConfig,)+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Document@@ -24,10 +24,15 @@ def _request_class(name: str):return _Request+class _StubClient:+ def __init__(self, config):+ self.config = config++def _install_openapi_stubs(monkeypatch: pytest.MonkeyPatch):- gpdb_package = types.ModuleType("alibabacloud_gpdb20160503")+ gpdb_package = FakeModule("alibabacloud_gpdb20160503")gpdb_package.__path__ = []- gpdb_models = types.ModuleType("alibabacloud_gpdb20160503.models")+ gpdb_models = FakeModule("alibabacloud_gpdb20160503.models")for class_name in ["InitVectorDatabaseRequest","DescribeNamespaceRequest",@@ -42,17 +47,13 @@ def _install_openapi_stubs(monkeypatch: pytest.MonkeyPatch):]:setattr(gpdb_models, class_name, _request_class(class_name))- class _Client:- def __init__(self, config):- self.config = config-- gpdb_client = types.ModuleType("alibabacloud_gpdb20160503.client")- gpdb_client.Client = _Client+ gpdb_client = FakeModule("alibabacloud_gpdb20160503.client")+ gpdb_client.Client = _StubClientgpdb_package.models = gpdb_models- tea_openapi = types.ModuleType("alibabacloud_tea_openapi")+ tea_openapi = FakeModule("alibabacloud_tea_openapi")tea_openapi.__path__ = []- tea_openapi_models = types.ModuleType("alibabacloud_tea_openapi.models")+ tea_openapi_models = FakeModule("alibabacloud_tea_openapi.models")class OpenApiConfig:def __init__(self, **kwargs):@@ -62,9 +63,9 @@ def _install_openapi_stubs(monkeypatch: pytest.MonkeyPatch):tea_openapi_models.Config = OpenApiConfigtea_openapi.models = tea_openapi_models- tea_package = types.ModuleType("Tea")+ tea_package = FakeModule("Tea")tea_package.__path__ = []- tea_exceptions = types.ModuleType("Tea.exceptions")+ tea_exceptions = FakeModule("Tea.exceptions")class TeaError(Exception):def __init__(self, status_code=None, **kwargs):@@ -141,6 +142,7 @@ def test_init_creates_openapi_client_and_runs_initialize(monkeypatch: pytest.Monassert isinstance(vector._client_config, stubs.OpenApiConfig)assert vector._client_config.user_agent == "dify"assert vector._client_config.access_key_id == "ak"+ assert isinstance(vector._client, _StubClient)assert vector._client.config is vector._client_configinitialize_mock.assert_called_once_with()@@ -170,7 +172,8 @@ def test_initialize_runs_when_cache_is_missing(monkeypatch: pytest.MonkeyPatch):lock.__exit__.return_value = Nonemonkeypatch.setattr(openapi_module.redis_client, "lock", MagicMock(return_value=lock))monkeypatch.setattr(openapi_module.redis_client, "get", MagicMock(return_value=None))- monkeypatch.setattr(openapi_module.redis_client, "set", MagicMock())+ redis_set = MagicMock()+ monkeypatch.setattr(openapi_module.redis_client, "set", redis_set)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector.config = _config()@@ -181,7 +184,7 @@ def test_initialize_runs_when_cache_is_missing(monkeypatch: pytest.MonkeyPatch):vector._initialize_vector_database.assert_called_once()vector._create_namespace_if_not_exists.assert_called_once()- openapi_module.redis_client.set.assert_called_once()+ redis_set.assert_called_once()def test_initialize_vector_database_calls_openapi_client(monkeypatch: pytest.MonkeyPatch):@@ -241,7 +244,8 @@ def test_create_collection_if_not_exists_creates_when_missing(monkeypatch: pyteslock.__exit__.return_value = Nonemonkeypatch.setattr(openapi_module.redis_client, "lock", MagicMock(return_value=lock))monkeypatch.setattr(openapi_module.redis_client, "get", MagicMock(return_value=None))- monkeypatch.setattr(openapi_module.redis_client, "set", MagicMock())+ redis_set = MagicMock()+ monkeypatch.setattr(openapi_module.redis_client, "set", redis_set)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector._collection_name = "collection_1"@@ -252,7 +256,7 @@ def test_create_collection_if_not_exists_creates_when_missing(monkeypatch: pytesvector.create_collection_if_not_exists(embedding_dimension=1024)vector._client.create_collection.assert_called_once()- openapi_module.redis_client.set.assert_called_once()+ redis_set.assert_called_once()def test_create_collection_if_not_exists_skips_when_cached(monkeypatch: pytest.MonkeyPatch):@@ -302,7 +306,7 @@ def test_openapi_add_delete_and_search_methods(monkeypatch: pytest.MonkeyPatch):documents = [Document(page_content="doc 1", metadata={"doc_id": "d1", "document_id": "doc-1"}),- SimpleNamespace(page_content="doc 2", metadata=None),+ Document.model_construct(page_content="doc 2", metadata=None),]embeddings = [[0.1, 0.2], [0.2, 0.3]]vector.add_texts(documents, embeddings)diff --git a/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py b/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.pyindex ae97e0180ee..5e5fe6780b5 100644--- a/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py+++ b/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py@@ -1,30 +1,30 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_pymochow_modules():- pymochow = types.ModuleType("pymochow")+ pymochow = FakeModule("pymochow")pymochow.__path__ = []- pymochow_auth = types.ModuleType("pymochow.auth")+ pymochow_auth = FakeModule("pymochow.auth")pymochow_auth.__path__ = []- pymochow_credentials = types.ModuleType("pymochow.auth.bce_credentials")- pymochow_configuration = types.ModuleType("pymochow.configuration")- pymochow_exception = types.ModuleType("pymochow.exception")- pymochow_model = types.ModuleType("pymochow.model")+ pymochow_credentials = FakeModule("pymochow.auth.bce_credentials")+ pymochow_configuration = FakeModule("pymochow.configuration")+ pymochow_exception = FakeModule("pymochow.exception")+ pymochow_model = FakeModule("pymochow.model")pymochow_model.__path__ = []- pymochow_model_database = types.ModuleType("pymochow.model.database")- pymochow_model_enum = types.ModuleType("pymochow.model.enum")- pymochow_model_schema = types.ModuleType("pymochow.model.schema")- pymochow_model_table = types.ModuleType("pymochow.model.table")+ pymochow_model_database = FakeModule("pymochow.model.database")+ pymochow_model_enum = FakeModule("pymochow.model.enum")+ pymochow_model_schema = FakeModule("pymochow.model.schema")+ pymochow_model_table = FakeModule("pymochow.model.table")class _SimpleObject:def __init__[**P](self, *args: P.args, **kwargs: P.kwargs):diff --git a/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py b/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.pyindex d8a3852acad..acb18f606c4 100644--- a/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py+++ b/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py@@ -1,18 +1,18 @@import importlibimport jsonimport sys-import typesfrom collections import UserDictfrom unittest.mock import MagicMock, patchimport pytest+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_chroma_modules():- chroma = types.ModuleType("chromadb")+ chroma = FakeModule("chromadb")chroma.DEFAULT_TENANT = "default_tenant"chroma.DEFAULT_DATABASE = "default_database"diff --git a/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py b/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.pyindex 60c58789dc8..00d3d198e64 100644--- a/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py+++ b/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py@@ -1,19 +1,19 @@import importlibimport queueimport sys-import typesfrom contextlib import contextmanagerfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_clickzetta_module():- clickzetta = types.ModuleType("clickzetta")+ clickzetta = FakeModule("clickzetta")class _FakeCursor:def __init__(self):@@ -422,7 +422,9 @@ def test_write_queue_initialization_worker_and_execute_write(clickzetta_module,clickzetta_module.ClickzettaVector._shutdown = Falseclickzetta_module.ClickzettaVector._init_write_queue()clickzetta_module.ClickzettaVector._init_write_queue()- assert clickzetta_module.ClickzettaVector._write_thread.started == 1+ write_thread = clickzetta_module.ClickzettaVector._write_thread+ assert isinstance(write_thread, _Thread)+ assert write_thread.started == 1result_queue_ok = queue.Queue()result_queue_fail = queue.Queue()@@ -809,7 +811,7 @@ def test_clickzetta_pool_cleanup_and_shutdown_edge_paths(clickzetta_module):pool._pools["missing-lock-key"] = [(MagicMock(), 0.0)]pool._cleanup_expired_connections()pool.shutdown()- assert pool._shutdown is True+ assert pool._shutdown is True # pyrefly: ignore[unnecessary-comparison]def test_clickzetta_pool_cleanup_thread_and_worker_exception_paths(clickzetta_module, monkeypatch: pytest.MonkeyPatch):diff --git a/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py b/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.pyindex e91004a6fab..746077486fe 100644--- a/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py+++ b/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py@@ -1,26 +1,26 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, call, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_couchbase_modules():- couchbase = types.ModuleType("couchbase")- couchbase_auth = types.ModuleType("couchbase.auth")- couchbase_cluster = types.ModuleType("couchbase.cluster")- couchbase_management = types.ModuleType("couchbase.management")- couchbase_management_search = types.ModuleType("couchbase.management.search")- couchbase_options = types.ModuleType("couchbase.options")- couchbase_vector = types.ModuleType("couchbase.vector_search")- couchbase_search = types.ModuleType("couchbase.search")+ couchbase = FakeModule("couchbase")+ couchbase_auth = FakeModule("couchbase.auth")+ couchbase_cluster = FakeModule("couchbase.cluster")+ couchbase_management = FakeModule("couchbase.management")+ couchbase_management_search = FakeModule("couchbase.management.search")+ couchbase_options = FakeModule("couchbase.options")+ couchbase_vector = FakeModule("couchbase.vector_search")+ couchbase_search = FakeModule("couchbase.search")class PasswordAuthenticator:def __init__(self, user, password):diff --git a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.pyindex 8c626673abd..90ea887ee46 100644--- a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py+++ b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py@@ -1,18 +1,18 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom elasticsearch import NotFoundError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom models.dataset import Datasetdef _build_fake_elasticsearch_modules():- elasticsearch = types.ModuleType("elasticsearch")+ elasticsearch = FakeModule("elasticsearch")class ConnectionError(Exception):passdiff --git a/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py b/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.pyindex b899e269749..9c6ba310234 100644--- a/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py+++ b/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py@@ -1,20 +1,19 @@import importlibimport jsonimport sys-import types-from types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_hologres_modules():- holo_module = types.ModuleType("holo_search_sdk")- holo_types_module = types.ModuleType("holo_search_sdk.types")+ holo_module = FakeModule("holo_search_sdk")+ holo_types_module = FakeModule("holo_search_sdk.types")holo_types_module.BaseQuantizationType = strholo_types_module.DistanceType = str@@ -124,7 +123,7 @@ def test_add_texts_batches_and_serializes_metadata(hologres_module):Document(page_content=f"doc-{i}", metadata={"doc_id": f"id-{i}", "document_id": f"document-{i}"})for i in range(100)]- documents.append(SimpleNamespace(page_content="doc-100", metadata=None))+ documents.append(Document(page_content="doc-100"))embeddings = [[float(i)] for i in range(len(documents))]ids = vector.add_texts(documents, embeddings)diff --git a/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py b/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.pyindex ed55d924487..acefb2d9745 100644--- a/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py+++ b/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py@@ -1,19 +1,19 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_elasticsearch_modules():- elasticsearch = types.ModuleType("elasticsearch")+ elasticsearch = FakeModule("elasticsearch")class Elasticsearch:def __init__(self, **kwargs):diff --git a/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py b/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.pyindex 059aabbe176..856b16b44bc 100644--- a/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py+++ b/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py@@ -1,21 +1,21 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_mo_vector_modules():- mo_vector = types.ModuleType("mo_vector")+ mo_vector = FakeModule("mo_vector")mo_vector.__path__ = []- mo_vector_client = types.ModuleType("mo_vector.client")+ mo_vector_client = FakeModule("mo_vector.client")class MoVectorClient:def __init__(self, **kwargs):diff --git a/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py b/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.pyindex 081a0ddca91..4590e8071f9 100644--- a/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py+++ b/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py@@ -1,18 +1,18 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_clickhouse_connect_module():- clickhouse_connect = types.ModuleType("clickhouse_connect")+ clickhouse_connect = FakeModule("clickhouse_connect")class QueryResult:def __init__(self, rows=None, named_rows=None):diff --git a/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py b/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.pyindex ab7c81e39e8..2e00d65feba 100644--- a/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py+++ b/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py@@ -2,7 +2,6 @@ import enumimport importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patch@@ -10,12 +9,13 @@ import pytestfrom pydantic import ValidationErrorfrom sqlalchemy.exc import SQLAlchemyError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_pyobvector_module():- pyobvector = types.ModuleType("pyobvector")+ pyobvector = FakeModule("pyobvector")class VECTOR:def __init__(self, dim):diff --git a/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py b/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.pyindex 85d967152c7..3941297545b 100644--- a/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py+++ b/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py@@ -1,7 +1,6 @@import importlibimport jsonimport sys-import typesfrom contextlib import contextmanagerfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patch@@ -9,15 +8,16 @@ from unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_psycopg2_modules():- psycopg2 = types.ModuleType("psycopg2")+ psycopg2 = FakeModule("psycopg2")psycopg2.__path__ = []- psycopg2_extras = types.ModuleType("psycopg2.extras")- psycopg2_pool = types.ModuleType("psycopg2.pool")+ psycopg2_extras = FakeModule("psycopg2.extras")+ psycopg2_pool = FakeModule("psycopg2.pool")class SimpleConnectionPool:def __init__[**P](self, *args: P.args, **kwargs: P.kwargs):diff --git a/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py b/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.pyindex fd13220420a..436df5525ad 100644--- a/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py+++ b/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py@@ -1,7 +1,6 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchfrom uuid import UUID@@ -10,13 +9,14 @@ import pytestfrom pydantic import ValidationErrorfrom sqlalchemy.types import UserDefinedType+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_pgvecto_modules():- pgvecto_rs = types.ModuleType("pgvecto_rs")- pgvecto_rs_sqlalchemy = types.ModuleType("pgvecto_rs.sqlalchemy")+ pgvecto_rs = FakeModule("pgvecto_rs")+ pgvecto_rs_sqlalchemy = FakeModule("pgvecto_rs.sqlalchemy")class VECTOR(UserDefinedType):def __init__(self, dim):diff --git a/api/providers/vdb/vdb-tablestore/tests/integration_tests/test_tablestore.py b/api/providers/vdb/vdb-tablestore/tests/integration_tests/test_tablestore.pyindex 0885e20636c..557c37e54e3 100644--- a/api/providers/vdb/vdb-tablestore/tests/integration_tests/test_tablestore.py+++ b/api/providers/vdb/vdb-tablestore/tests/integration_tests/test_tablestore.py@@ -33,6 +33,12 @@ class TableStoreVectorTest(AbstractVectorTest):),)+ @property+ def tablestore_vector(self) -> TableStoreVector:+ """The vector under test, typed as TableStoreVector for its private fields."""+ assert isinstance(self.vector, TableStoreVector)+ return self.vector+@overridedef get_ids_by_metadata_field(self):ids = self.vector.get_ids_by_metadata_field(key="doc_id", value=self.example_doc_id)@@ -47,9 +53,9 @@ class TableStoreVectorTest(AbstractVectorTest):embeddings=[self.example_embedding],)while True:- search_response = self.vector._tablestore_client.search(- table_name=self.vector._table_name,- index_name=self.vector._index_name,+ search_response = self.tablestore_vector._tablestore_client.search(+ table_name=self.tablestore_vector._table_name,+ index_name=self.tablestore_vector._index_name,search_query=tablestore.SearchQuery(query=tablestore.MatchAllQuery(), get_total_count=True, limit=0),columns_to_get=tablestore.ColumnsToGet(return_type=tablestore.ColumnReturnType.ALL_FROM_INDEX),)@@ -73,7 +79,7 @@ class TableStoreVectorTest(AbstractVectorTest):docs = self.vector.search_by_full_text(get_example_text(), document_ids_filter=[self.example_doc_id])assert len(docs) == 1assert docs[0].metadata["doc_id"] == self.example_doc_id- if self.vector._config.normalize_full_text_bm25_score:+ if self.tablestore_vector._config.normalize_full_text_bm25_score:assert docs[0].metadata["score"] == approx(0.1214, abs=1e-3)else:assert docs[0].metadata.get("score") is None@@ -82,7 +88,7 @@ class TableStoreVectorTest(AbstractVectorTest):docs = self.vector.search_by_full_text(get_example_text(), document_ids_filter=[self.example_doc_id], score_threshold=0.5)- if self.vector._config.normalize_full_text_bm25_score:+ if self.tablestore_vector._config.normalize_full_text_bm25_score:assert len(docs) == 0else:assert len(docs) == 1diff --git a/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py b/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.pyindex 8f915f03023..dfa4d4657da 100644--- a/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py+++ b/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py@@ -1,19 +1,19 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_tablestore_module():- tablestore = types.ModuleType("tablestore")+ tablestore = FakeModule("tablestore")class _BatchGetRowRequest:def __init__(self):diff --git a/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py b/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.pyindex 4062a873f3a..2acb04af7ad 100644--- a/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py+++ b/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py@@ -1,19 +1,19 @@import importlibimport jsonimport sys-import typesfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_upstash_module():- upstash_module = types.ModuleType("upstash_vector")+ upstash_module = FakeModule("upstash_vector")class Vector:def __init__(self, id, vector, metadata, data):diff --git a/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py b/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.pyindex 0853cbfbc41..1666c804192 100644--- a/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py+++ b/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py@@ -2,7 +2,6 @@ import hashlibimport importlibimport jsonimport sys-import typesfrom contextlib import contextmanagerfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patch@@ -10,16 +9,17 @@ from unittest.mock import MagicMock, patchimport pytestfrom pydantic import ValidationError+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_psycopg2_modules():- psycopg2 = types.ModuleType("psycopg2")+ psycopg2 = FakeModule("psycopg2")psycopg2.__path__ = []- psycopg2_extras = types.ModuleType("psycopg2.extras")- psycopg2_pool = types.ModuleType("psycopg2.pool")- psycopg2_errors = types.ModuleType("psycopg2.errors")+ psycopg2_extras = FakeModule("psycopg2.extras")+ psycopg2_pool = FakeModule("psycopg2.pool")+ psycopg2_errors = FakeModule("psycopg2.errors")class SimpleConnectionPool:def __init__[**P](self, *args: P.args, **kwargs: P.kwargs):diff --git a/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py b/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.pyindex aad93aa3886..ba9a217de7c 100644--- a/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py+++ b/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py@@ -1,21 +1,21 @@import importlibimport jsonimport sys-import typesfrom collections import UserDictfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest+from core.rag.datasource.vdb.vector_integration_test_support import FakeModulefrom core.rag.models.document import Documentfrom models.dataset import Datasetdef _build_fake_vikingdb_modules():- volcengine = types.ModuleType("volcengine")+ volcengine = FakeModule("volcengine")volcengine.__path__ = []- viking_db = types.ModuleType("volcengine.viking_db")+ viking_db = FakeModule("volcengine.viking_db")class Data(UserDict):def __init__(self, payload):diff --git a/api/pyrefly-local-excludes.txt b/api/pyrefly-local-excludes.txtindex e127244b8c3..1e625d6ffe7 100644--- a/api/pyrefly-local-excludes.txt+++ b/api/pyrefly-local-excludes.txt@@ -1,42 +1,20 @@-providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py-providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.pyproviders/vdb/vdb-analyticdb/tests/integration_tests/test_analyticdb.py-providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector.py-providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.pyproviders/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py-providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py-providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py-providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py-providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py-providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.pyproviders/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_vector.py-providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.pyproviders/vdb/vdb-hologres/tests/integration_tests/conftest.py-providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.pyproviders/vdb/vdb-iris/tests/unit_tests/test_iris_vector.pyproviders/vdb/vdb-lindorm/tests/integration_tests/test_lindorm.pyproviders/vdb/vdb-lindorm/tests/unit_tests/test_lindorm_vector.py-providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.pyproviders/vdb/vdb-milvus/tests/unit_tests/test_milvus.py-providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py-providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.pyproviders/vdb/vdb-opengauss/tests/integration_tests/test_opengauss.py-providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.pyproviders/vdb/vdb-opensearch/tests/unit_tests/test_opensearch.pyproviders/vdb/vdb-opensearch/tests/unit_tests/test_opensearch_vector.pyproviders/vdb/vdb-oracle/tests/unit_tests/test_oraclevector.py-providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.pyproviders/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.pyproviders/vdb/vdb-qdrant/tests/unit_tests/test_qdrant_vector.pyproviders/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py-providers/vdb/vdb-tablestore/tests/integration_tests/test_tablestore.py-providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.pyproviders/vdb/vdb-tencent/tests/integration_tests/conftest.pyproviders/vdb/vdb-tidb-on-qdrant/src/dify_vdb_tidb_on_qdrant/tidb_on_qdrant_vector.pyproviders/vdb/vdb-tidb-on-qdrant/src/dify_vdb_tidb_on_qdrant/tidb_service.py-providers/vdb/vdb-tidb-on-qdrant/tests/unit_tests/test_tidb_service.pyproviders/vdb/vdb-tidb-vector/tests/unit_tests/test_tidb_vector.py-providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py-providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py-providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.pyproviders/vdb/vdb-weaviate/tests/unit_tests/test_weaviate_vector.py