Implement InsertDataset and InsertMetadata in GO (#13883)

### What problem does this PR solve?

Implement InsertDataset and InsertMetadata in GO

new internal cli for go:

INSERT DATASET FROM FILE "file_name"
INSERT METADATA FROM FILE "file_name"

### Type of change

- [x] Refactoring
This commit is contained in:
qinling0210
2026-04-01 16:16:25 +08:00
committed by GitHub
parent b1d28b5898
commit bb4a06f759
18 changed files with 915 additions and 8 deletions

View File

@@ -97,6 +97,8 @@ sql_command: login_user
| search_on_datasets
| get_chunk
| list_chunks
| insert_dataset_from_file
| insert_metadata_from_file
| create_chat_session
| drop_chat_session
| list_chat_sessions
@@ -207,10 +209,12 @@ DOC_META: "DOC_META"i
CHUNK: "CHUNK"i
CHUNKS: "CHUNKS"i
GET: "GET"i
INSERT: "INSERT"i
PAGE: "PAGE"i
SIZE: "SIZE"i
KEYWORDS: "KEYWORDS"i
AVAILABLE: "AVAILABLE"i
FILE: "FILE"i
login_user: LOGIN USER quoted_string ";"
list_services: LIST SERVICES ";"
@@ -349,6 +353,10 @@ parse_dataset_docs: PARSE quoted_string OF DATASET quoted_string ";"
parse_dataset_sync: PARSE DATASET quoted_string SYNC ";"
parse_dataset_async: PARSE DATASET quoted_string ASYNC ";"
// Internal CLI for GO
insert_dataset_from_file: INSERT DATASET FROM FILE quoted_string ";"
insert_metadata_from_file: INSERT METADATA FROM FILE quoted_string ";"
identifier_list: identifier ("," identifier)*
identifier: WORD
@@ -750,6 +758,14 @@ class RAGFlowCLITransformer(Transformer):
chunk_id = items[2].children[0].strip("'\"")
return {"type": "get_chunk", "chunk_id": chunk_id}
def insert_dataset_from_file(self, items):
file_path = items[4].children[0].strip("'\"")
return {"type": "insert_dataset_from_file", "file_path": file_path}
def insert_metadata_from_file(self, items):
file_path = items[4].children[0].strip("'\"")
return {"type": "insert_metadata_from_file", "file_path": file_path}
def list_chunks(self, items):
doc_id = items[4].children[0].strip("'\"")
result = {"type": "list_chunks", "doc_id": doc_id}

View File

@@ -1520,6 +1520,48 @@ class RAGFlowClient:
else:
print(f"Fail to get chunk, code: {res_json['code']}, message: {res_json['message']}")
# Internal
def insert_dataset_from_file(self, command_dict):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
file_path = command_dict["file_path"]
payload = {"file_path": file_path}
response = self.http_client.request("POST", "/kb/insert_from_file", json_body=payload,
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200:
if res_json["code"] == 0:
print(f"Success to insert dataset from file: {file_path}")
if res_json.get("data"):
self._print_key_value(res_json["data"])
else:
print(f"Fail to insert dataset from file, code: {res_json['code']}, message: {res_json['message']}")
else:
print(f"Fail to insert dataset from file, code: {res_json['code']}, message: {res_json['message']}")
# Internal
def insert_metadata_from_file(self, command_dict):
if self.server_type != "user":
print("This command is only allowed in USER mode")
return
file_path = command_dict["file_path"]
payload = {"file_path": file_path}
response = self.http_client.request("POST", "/tenant/insert_metadata_from_file", json_body=payload,
use_api_base=False, auth_kind="web")
res_json = response.json()
if response.status_code == 200:
if res_json["code"] == 0:
print(f"Success to insert metadata from file: {file_path}")
if res_json.get("data"):
self._print_key_value(res_json["data"])
else:
print(f"Fail to insert metadata from file, code: {res_json['code']}, message: {res_json['message']}")
else:
print(f"Fail to insert metadata from file, code: {res_json['code']}, message: {res_json['message']}")
def list_chunks(self, command_dict):
if self.server_type != "user":
print("This command is only allowed in USER mode")
@@ -1903,6 +1945,10 @@ def run_command(client: RAGFlowClient, command_dict: dict):
return client.search_on_datasets(command_dict)
case "get_chunk":
return client.get_chunk(command_dict)
case "insert_dataset_from_file":
return client.insert_dataset_from_file(command_dict)
case "insert_metadata_from_file":
return client.insert_metadata_from_file(command_dict)
case "list_chunks":
return client.list_chunks(command_dict)
case "meta":