refactor: 客服agent的切片结构调整重构
This commit is contained in:
+3
-1
@@ -3,11 +3,13 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from config.settings import settings
|
||||
from tool.llm import llm
|
||||
|
||||
|
||||
logger = logging.getLogger("rag.embedding")
|
||||
EMBEDDING_DIMENSION = 768
|
||||
# 单一来源:.env 的 LLM_EMBED_DIMENSIONS;Milvus 建表、入库校验、embeddings 请求参数均以此为准
|
||||
EMBEDDING_DIMENSION = settings.llm.embed_dimensions
|
||||
|
||||
|
||||
class EmbeddingError(RuntimeError):
|
||||
|
||||
@@ -4,10 +4,10 @@ from __future__ import annotations
|
||||
from pymilvus import AsyncMilvusClient, DataType
|
||||
|
||||
from config.database.milvus import client as configured_milvus_client
|
||||
from rag.embedding import EMBEDDING_DIMENSION
|
||||
|
||||
|
||||
KNOWLEDGE_COLLECTIONS = ("fin_faq", "fin_fund_doc", "fin_policy")
|
||||
EMBEDDING_DIMENSION = 768
|
||||
|
||||
|
||||
def build_knowledge_schema():
|
||||
@@ -44,3 +44,15 @@ async def ensure_collections(milvus_client: AsyncMilvusClient | None = None) ->
|
||||
schema=schema,
|
||||
index_params=index_params,
|
||||
)
|
||||
continue
|
||||
# 已存在的集合维度必须与当前 embedding 配置一致,否则入库/检索会在运行时失败
|
||||
desc = await client.describe_collection(collection_name)
|
||||
for field in desc.get("fields", []):
|
||||
if field.get("name") != "vector":
|
||||
continue
|
||||
dim = field.get("params", {}).get("dim")
|
||||
if dim is not None and int(dim) != EMBEDDING_DIMENSION:
|
||||
raise RuntimeError(
|
||||
f"Milvus collection {collection_name!r} vector dim={dim}, "
|
||||
f"expected {EMBEDDING_DIMENSION}; drop and recreate it"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user