2024-06-14 19:25:17 +08:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
from core.rag.datasource.vdb.tencent.tencent_vector import TencentConfig, TencentVector
|
|
|
|
from tests.integration_tests.vdb.__mock.tcvectordb import setup_tcvectordb_mock
|
|
|
|
from tests.integration_tests.vdb.test_vector_store import AbstractVectorTest, get_example_text, setup_mock_redis
|
|
|
|
|
|
|
|
mock_client = MagicMock()
|
|
|
|
mock_client.list_databases.return_value = [{"name": "test"}]
|
|
|
|
|
2024-08-23 23:52:25 +08:00
|
|
|
|
2024-06-14 19:25:17 +08:00
|
|
|
class TencentVectorTest(AbstractVectorTest):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2024-08-23 23:52:25 +08:00
|
|
|
self.vector = TencentVector(
|
|
|
|
"dify",
|
|
|
|
TencentConfig(
|
|
|
|
url="http://127.0.0.1",
|
|
|
|
api_key="dify",
|
|
|
|
timeout=30,
|
|
|
|
username="dify",
|
|
|
|
database="dify",
|
|
|
|
shard=1,
|
|
|
|
replicas=2,
|
|
|
|
),
|
|
|
|
)
|
2024-06-14 19:25:17 +08:00
|
|
|
|
|
|
|
def search_by_vector(self):
|
|
|
|
hits_by_vector = self.vector.search_by_vector(query_vector=self.example_embedding)
|
|
|
|
assert len(hits_by_vector) == 1
|
|
|
|
|
|
|
|
def search_by_full_text(self):
|
|
|
|
hits_by_full_text = self.vector.search_by_full_text(query=get_example_text())
|
|
|
|
assert len(hits_by_full_text) == 0
|
|
|
|
|
|
|
|
|
2024-08-23 23:52:25 +08:00
|
|
|
def test_tencent_vector(setup_mock_redis, setup_tcvectordb_mock):
|
|
|
|
TencentVectorTest().run_all_tests()
|