refactor: 客服agent的切片结构调整重构
This commit is contained in:
@@ -2,7 +2,20 @@ import unittest
|
||||
from unittest.mock import AsyncMock, call
|
||||
from unittest.mock import patch
|
||||
|
||||
from rag.milvus_collections import KNOWLEDGE_COLLECTIONS, ensure_collections
|
||||
from rag.milvus_collections import (
|
||||
EMBEDDING_DIMENSION,
|
||||
KNOWLEDGE_COLLECTIONS,
|
||||
ensure_collections,
|
||||
)
|
||||
|
||||
|
||||
def _existing_client(dim: int) -> AsyncMock:
|
||||
client = AsyncMock()
|
||||
client.has_collection.return_value = True
|
||||
client.describe_collection.return_value = {
|
||||
"fields": [{"name": "vector", "params": {"dim": dim}}]
|
||||
}
|
||||
return client
|
||||
|
||||
|
||||
class MilvusCollectionTests(unittest.IsolatedAsyncioTestCase):
|
||||
@@ -19,14 +32,19 @@ class MilvusCollectionTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(client.create_collection.await_count, len(KNOWLEDGE_COLLECTIONS))
|
||||
|
||||
async def test_reuses_existing_collections(self):
|
||||
client = AsyncMock()
|
||||
client.has_collection.return_value = True
|
||||
client = _existing_client(EMBEDDING_DIMENSION)
|
||||
|
||||
await ensure_collections(client)
|
||||
|
||||
client.create_collection.assert_not_awaited()
|
||||
|
||||
async def test_collection_schema_contains_metadata_and_768_vector(self):
|
||||
async def test_existing_collection_with_wrong_dimension_raises(self):
|
||||
client = _existing_client(EMBEDDING_DIMENSION + 1)
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
await ensure_collections(client)
|
||||
|
||||
async def test_collection_schema_contains_metadata_and_1024_vector(self):
|
||||
client = AsyncMock()
|
||||
client.has_collection.return_value = False
|
||||
|
||||
@@ -36,11 +54,10 @@ class MilvusCollectionTests(unittest.IsolatedAsyncioTestCase):
|
||||
fields = {field["name"] for field in schema.to_dict()["fields"]}
|
||||
self.assertTrue({"chunk_id", "doc_id", "title", "section_title", "text", "strategy", "vector"} <= fields)
|
||||
vector = next(field for field in schema.to_dict()["fields"] if field["name"] == "vector")
|
||||
self.assertEqual(vector["params"]["dim"], 768)
|
||||
self.assertEqual(vector["params"]["dim"], 1024)
|
||||
|
||||
async def test_default_path_uses_configured_milvus_client(self):
|
||||
client = AsyncMock()
|
||||
client.has_collection.return_value = True
|
||||
client = _existing_client(EMBEDDING_DIMENSION)
|
||||
|
||||
with patch("rag.milvus_collections.configured_milvus_client", return_value=client):
|
||||
await ensure_collections()
|
||||
|
||||
Reference in New Issue
Block a user