feat: 使用百炼的嵌入模型服务

This commit is contained in:
martsforever
2025-09-07 01:06:23 +08:00
parent ca658c2006
commit a90bee1b95
3 changed files with 10 additions and 2 deletions
+5
View File
@@ -71,4 +71,9 @@ ai_configs = {
'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', 'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
'key': env.llm_key_bailian, '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,
},
} }
+1 -1
View File
@@ -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"):
""" """
创建自定义嵌入模型实例 创建自定义嵌入模型实例
+4 -1
View File
@@ -1,3 +1,4 @@
import asyncio
from typing import List, Optional from typing import List, Optional
from llama_index.core import Document, VectorStoreIndex from llama_index.core import Document, VectorStoreIndex
@@ -45,7 +46,9 @@ class MilvusService:
) )
from llama_index.core.node_parser import HierarchicalNodeParser from llama_index.core.node_parser import HierarchicalNodeParser
parser = HierarchicalNodeParser.from_defaults(chunk_sizes=[2048, 512, 128]) 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) await vector_index.ainsert_nodes(nodes)
return vector_index return vector_index