Implement Create/Drop Index/Metadata index in GO (#13791)

### What problem does this PR solve?

Implement Create/Drop Index/Metadata index in GO

New API handling in GO:
POST/kb/index 
DELETE /kb/index
POST /tenant/doc_meta_index
DELETE /tenant/doc_meta_index

CREATE INDEX FOR DATASET 'dataset_name' VECTOR_SIZE 1024;
DROP INDEX FOR DATASET 'dataset_name';
CREATE INDEX DOC_META;
DROP INDEX DOC_META;

### Type of change

- [x] Refactoring
This commit is contained in:
qinling0210
2026-03-26 11:54:10 +08:00
committed by GitHub
parent d19ca71b43
commit ebf36950e4
20 changed files with 1165 additions and 30 deletions

View File

@@ -1080,6 +1080,75 @@ class RAGFlowClient:
else:
print(f"Fail to create chat {chat_name}, code: {res_json['code']}, message: {res_json['message']}")
def create_index(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
dataset_name = command["dataset_name"]
vector_size = command.get("vector_size")
if not vector_size:
print("vector_size is required")
return
# Get dataset ID by name
dataset_id = self._get_dataset_id(dataset_name)
if dataset_id is None:
return
# Build payload
payload = {"kb_id": dataset_id, "vector_size": vector_size}
# Call API
response = self.http_client.request("POST", "/kb/index", json_body=payload,
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json.get("code") == 0:
print(f"Success to create index for dataset: {dataset_name}")
else:
print(f"Fail to create index for dataset {dataset_name}, code: {res_json.get('code')}, message: {res_json.get('message')}")
def drop_index(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
dataset_name = command["dataset_name"]
# Get dataset ID by name
dataset_id = self._get_dataset_id(dataset_name)
if dataset_id is None:
return
# Call API to delete index
payload = {"kb_id": dataset_id}
response = self.http_client.request("DELETE", "/kb/index", json_body=payload,
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json.get("code") == 0:
print(f"Success to drop index for dataset: {dataset_name}")
else:
print(f"Fail to drop index for dataset {dataset_name}, code: {res_json.get('code')}, message: {res_json.get('message')}")
def create_doc_meta_index(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
# Call API to create doc meta index
response = self.http_client.request("POST", "/tenant/doc_meta_index",
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json.get("code") == 0:
print("Success to create doc meta index")
else:
print(f"Fail to create doc meta index, code: {res_json.get('code')}, message: {res_json.get('message')}")
def drop_doc_meta_index(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
# Call API to delete doc meta index
response = self.http_client.request("DELETE", "/tenant/doc_meta_index",
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json.get("code") == 0:
print("Success to drop doc meta index")
else:
print(f"Fail to drop doc meta index, code: {res_json.get('code')}, message: {res_json.get('message')}")
def drop_user_chat(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
@@ -1804,6 +1873,14 @@ def run_command(client: RAGFlowClient, command_dict: dict):
client.create_user_chat(command_dict)
case "drop_user_chat":
client.drop_user_chat(command_dict)
case "create_index":
client.create_index(command_dict)
case "drop_index":
client.drop_index(command_dict)
case "create_doc_meta_index":
client.create_doc_meta_index(command_dict)
case "drop_doc_meta_index":
client.drop_doc_meta_index(command_dict)
case "create_chat_session":
client.create_chat_session(command_dict)
case "drop_chat_session":
@@ -1887,6 +1964,10 @@ LIST METADATA OF DATASETS <dataset>[, <dataset>]*
LIST METADATA SUMMARY OF DATASET <dataset> DOCUMENTS <doc_id>[, <doc_id>]*
GET CHUNK <chunk_id>
LIST CHUNKS OF DOCUMENT <doc_id> [PAGE <page>] [SIZE <size>] [KEYWORDS <keywords>] [AVAILABLE <0|1>]
CREATE INDEX FOR DATASET <dataset> VECTOR_SIZE <vector_size>
DROP INDEX FOR DATASET <dataset>
CREATE INDEX DOC_META
DROP INDEX DOC_META
Meta Commands:
\\?, \\h, \\help Show this help