-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_milvus.py
More file actions
31 lines (24 loc) · 979 Bytes
/
init_milvus.py
File metadata and controls
31 lines (24 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""初始化Milvus集合脚本"""
import sys
import os
# 添加父目录到路径,确保能导入模块
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from milvus_client import milvus_client
from ollama_service import ollama_service
def init_milvus():
"""初始化Milvus集合"""
print("开始初始化Milvus...")
# 获取一个示例embedding来确定维度
try:
sample_embedding = ollama_service.get_embedding("sample text")
dim = len(sample_embedding)
print(f"✓ Embedding维度: {dim}")
except Exception as e:
print(f"获取embedding失败,使用默认维度1024: {e}")
dim = 1024
# 创建集合
collection_name = "code_review_collection"
milvus_client.create_collection_if_not_exists(collection_name, dim)
print(f"✓ Milvus集合 '{collection_name}' 初始化完成")
if __name__ == "__main__":
init_milvus()