You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
994 B
27 lines
994 B
from Backup.Milvus.Utils.MilvusCollectionManager import MilvusCollectionManager
|
|
from Config.Config import *
|
|
|
|
# 1. 使用连接池管理 Milvus 连接
|
|
milvus_pool = MilvusConnectionPool(host=MS_HOST, port=MS_PORT, max_connections=MS_MAX_CONNECTIONS)
|
|
|
|
# 2. 从连接池中获取一个连接
|
|
connection = milvus_pool.get_connection()
|
|
|
|
# 3. 初始化集合管理器
|
|
collection_name = MS_COLLECTION_NAME
|
|
collection_manager = MilvusCollectionManager(collection_name)
|
|
|
|
# 4. 创建索引
|
|
index_params = {
|
|
"index_type": "IVF_FLAT", # 使用 IVF_FLAT 索引类型
|
|
"metric_type": "L2", # 使用 L2 距离度量方式
|
|
"params": {"nlist": 128} # 设置 IVF_FLAT 的 nlist 参数
|
|
}
|
|
collection_manager.create_index("embedding", index_params) # 为 embedding 字段创建索引
|
|
print(f"集合 '{collection_name}' 的 'embedding' 字段索引创建成功。")
|
|
|
|
# 5. 释放连接
|
|
milvus_pool.release_connection(connection)
|
|
|
|
# 6. 关闭连接池
|
|
milvus_pool.close() |