parent
e9de960359
commit
a145af2490
@ -0,0 +1,32 @@
|
|||||||
|
from elasticsearch import Elasticsearch
|
||||||
|
|
||||||
|
from Config.Config import ES_CONFIG
|
||||||
|
from Util.EsMappingUtil import create_vector_index, delete_index # 导入工具函数
|
||||||
|
|
||||||
|
# 初始化ES连接
|
||||||
|
es = Elasticsearch(
|
||||||
|
hosts=ES_CONFIG["hosts"],
|
||||||
|
basic_auth=ES_CONFIG["basic_auth"],
|
||||||
|
verify_certs=ES_CONFIG["verify_certs"],
|
||||||
|
ssl_show_warn=ES_CONFIG["ssl_show_warn"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def manage_index(action, index_name="knowledge_base", dims=200):
|
||||||
|
"""管理Elasticsearch索引
|
||||||
|
:param action: 'create'或'delete'
|
||||||
|
:param index_name: 索引名称
|
||||||
|
:param dims: 向量维度(仅创建时有效)
|
||||||
|
"""
|
||||||
|
if action == "create":
|
||||||
|
return create_vector_index(index_name, dims)
|
||||||
|
elif action == "delete":
|
||||||
|
return delete_index(index_name)
|
||||||
|
else:
|
||||||
|
raise ValueError("action参数必须是'create'或'delete'")
|
||||||
|
|
||||||
|
# 使用示例
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 删除索引
|
||||||
|
manage_index("delete")
|
||||||
|
# 创建索引
|
||||||
|
manage_index("create", dims=200)
|
@ -0,0 +1,20 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
from elasticsearch import Elasticsearch
|
||||||
|
|
||||||
|
from Config.Config import ES_CONFIG
|
||||||
|
from T2_Txt2Vec import text_to_embedding
|
||||||
|
from Util.EsMappingUtil import create_vector_index # 导入工具函数
|
||||||
|
|
||||||
|
# 初始化ES连接
|
||||||
|
es = Elasticsearch(
|
||||||
|
hosts=ES_CONFIG["hosts"],
|
||||||
|
basic_auth=ES_CONFIG["basic_auth"],
|
||||||
|
verify_certs=ES_CONFIG["verify_certs"],
|
||||||
|
ssl_show_warn=ES_CONFIG["ssl_show_warn"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# 使用示例
|
||||||
|
if __name__ == "__main__":
|
||||||
|
create_vector_index(dims=200) # 使用工具函数创建索引
|
Binary file not shown.
Loading…
Reference in new issue