diff --git a/app/config/ai_configs.py b/app/config/ai_configs.py index ccb34c4..13a1306 100644 --- a/app/config/ai_configs.py +++ b/app/config/ai_configs.py @@ -71,4 +71,9 @@ ai_configs = { 'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', 'key': env.llm_key_bailian, }, + 'bailian-embedding': { + 'model': 'text-embedding-v4', + 'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings', + 'key': env.llm_key_bailian, + }, } diff --git a/app/utils/llm_utils.py b/app/utils/llm_utils.py index c0d28b1..a0ea91c 100644 --- a/app/utils/llm_utils.py +++ b/app/utils/llm_utils.py @@ -37,7 +37,7 @@ def create_llama_index_llm(platform_code='huoshan-doubao', temperature=0.5): ) -def create_embeddings(platform_code="huoshan-embedding-240715"): +def create_embeddings(platform_code="bailian-embedding"): """ 创建自定义嵌入模型实例 diff --git a/app/utils/milvus_utils.py b/app/utils/milvus_utils.py index 9aa0be5..1a96f34 100644 --- a/app/utils/milvus_utils.py +++ b/app/utils/milvus_utils.py @@ -1,3 +1,4 @@ +import asyncio from typing import List, Optional from llama_index.core import Document, VectorStoreIndex @@ -45,7 +46,9 @@ class MilvusService: ) from llama_index.core.node_parser import HierarchicalNodeParser parser = HierarchicalNodeParser.from_defaults(chunk_sizes=[2048, 512, 128]) - nodes = await parser.aget_nodes_from_documents(documents) + # nodes = await parser.aget_nodes_from_documents(documents) + # 使用同步方法并包装在 asyncio.to_thread 中 + nodes = await asyncio.to_thread(parser.get_nodes_from_documents,documents) await vector_index.ainsert_nodes(nodes) return vector_index