refactor: 客服agent的切片结构调整重构

This commit is contained in:
2026-09-11 17:31:16 +08:00
parent b1b764eac9
commit e561c97a4e
20 changed files with 3309 additions and 230 deletions
+24 -7
View File
@@ -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()