Initial commit with .gitignore
This commit is contained in:
54
reset_vector.py
Normal file
54
reset_vector.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
重置向量数据库集合脚本
|
||||
"""
|
||||
|
||||
import configparser
|
||||
import time
|
||||
from dashvector import Client
|
||||
|
||||
|
||||
def main():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini', encoding='utf-8')
|
||||
|
||||
print("=" * 50)
|
||||
print("重置 DashVector 集合")
|
||||
print("=" * 50)
|
||||
|
||||
api_key = config.get('dashvector', 'api_key')
|
||||
endpoint = config.get('dashvector', 'endpoint')
|
||||
collection_name = config.get('dashvector', 'collection_name')
|
||||
dimension = config.getint('dashvector', 'vector_dimension')
|
||||
|
||||
client = Client(api_key=api_key, endpoint=endpoint)
|
||||
|
||||
# 删除
|
||||
del_result = client.delete(collection_name)
|
||||
if del_result.code == 0:
|
||||
print(f"已删除集合: {collection_name}")
|
||||
print("等待删除完成...")
|
||||
time.sleep(3)
|
||||
else:
|
||||
print(f"集合不存在,跳过删除")
|
||||
|
||||
# 创建
|
||||
create_result = client.create(collection_name, dimension=dimension)
|
||||
if create_result.code == 0:
|
||||
print(f"已创建集合: {collection_name} (维度={dimension})")
|
||||
else:
|
||||
print(f"创建失败: {create_result.message}")
|
||||
return
|
||||
|
||||
# 验证
|
||||
collections = client.list()
|
||||
if collection_name in collections.output:
|
||||
print(f"验证通过: 集合已在列表中")
|
||||
else:
|
||||
print(f"警告: 集合未出现在列表中,请稍后重试")
|
||||
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user