@@ -1080,6 +1080,75 @@ def create_user_chat(self, command):
10801080 else :
10811081 print (f"Fail to create chat { chat_name } , code: { res_json ['code' ]} , message: { res_json ['message' ]} " )
10821082
1083+ def create_index (self , command ):
1084+ if self .server_type != "user" :
1085+ print ("This command is only allowed in USER mode" )
1086+ return
1087+ dataset_name = command ["dataset_name" ]
1088+ vector_size = command .get ("vector_size" )
1089+ if not vector_size :
1090+ print ("vector_size is required" )
1091+ return
1092+ # Get dataset ID by name
1093+ dataset_id = self ._get_dataset_id (dataset_name )
1094+ if dataset_id is None :
1095+ return
1096+ # Build payload
1097+ payload = {"kb_id" : dataset_id , "vector_size" : vector_size }
1098+ # Call API
1099+ response = self .http_client .request ("POST" , "/kb/index" , json_body = payload ,
1100+ use_api_base = False , auth_kind = "web" )
1101+ res_json = response .json ()
1102+ if response .status_code == 200 and res_json .get ("code" ) == 0 :
1103+ print (f"Success to create index for dataset: { dataset_name } " )
1104+ else :
1105+ print (f"Fail to create index for dataset { dataset_name } , code: { res_json .get ('code' )} , message: { res_json .get ('message' )} " )
1106+
1107+ def drop_index (self , command ):
1108+ if self .server_type != "user" :
1109+ print ("This command is only allowed in USER mode" )
1110+ return
1111+ dataset_name = command ["dataset_name" ]
1112+ # Get dataset ID by name
1113+ dataset_id = self ._get_dataset_id (dataset_name )
1114+ if dataset_id is None :
1115+ return
1116+ # Call API to delete index
1117+ payload = {"kb_id" : dataset_id }
1118+ response = self .http_client .request ("DELETE" , "/kb/index" , json_body = payload ,
1119+ use_api_base = False , auth_kind = "web" )
1120+ res_json = response .json ()
1121+ if response .status_code == 200 and res_json .get ("code" ) == 0 :
1122+ print (f"Success to drop index for dataset: { dataset_name } " )
1123+ else :
1124+ print (f"Fail to drop index for dataset { dataset_name } , code: { res_json .get ('code' )} , message: { res_json .get ('message' )} " )
1125+
1126+ def create_doc_meta_index (self , command ):
1127+ if self .server_type != "user" :
1128+ print ("This command is only allowed in USER mode" )
1129+ return
1130+ # Call API to create doc meta index
1131+ response = self .http_client .request ("POST" , "/tenant/doc_meta_index" ,
1132+ use_api_base = False , auth_kind = "web" )
1133+ res_json = response .json ()
1134+ if response .status_code == 200 and res_json .get ("code" ) == 0 :
1135+ print ("Success to create doc meta index" )
1136+ else :
1137+ print (f"Fail to create doc meta index, code: { res_json .get ('code' )} , message: { res_json .get ('message' )} " )
1138+
1139+ def drop_doc_meta_index (self , command ):
1140+ if self .server_type != "user" :
1141+ print ("This command is only allowed in USER mode" )
1142+ return
1143+ # Call API to delete doc meta index
1144+ response = self .http_client .request ("DELETE" , "/tenant/doc_meta_index" ,
1145+ use_api_base = False , auth_kind = "web" )
1146+ res_json = response .json ()
1147+ if response .status_code == 200 and res_json .get ("code" ) == 0 :
1148+ print ("Success to drop doc meta index" )
1149+ else :
1150+ print (f"Fail to drop doc meta index, code: { res_json .get ('code' )} , message: { res_json .get ('message' )} " )
1151+
10831152 def drop_user_chat (self , command ):
10841153 if self .server_type != "user" :
10851154 print ("This command is only allowed in USER mode" )
@@ -1804,6 +1873,14 @@ def run_command(client: RAGFlowClient, command_dict: dict):
18041873 client .create_user_chat (command_dict )
18051874 case "drop_user_chat" :
18061875 client .drop_user_chat (command_dict )
1876+ case "create_index" :
1877+ client .create_index (command_dict )
1878+ case "drop_index" :
1879+ client .drop_index (command_dict )
1880+ case "create_doc_meta_index" :
1881+ client .create_doc_meta_index (command_dict )
1882+ case "drop_doc_meta_index" :
1883+ client .drop_doc_meta_index (command_dict )
18071884 case "create_chat_session" :
18081885 client .create_chat_session (command_dict )
18091886 case "drop_chat_session" :
@@ -1887,6 +1964,10 @@ def show_help():
18871964LIST METADATA SUMMARY OF DATASET <dataset> DOCUMENTS <doc_id>[, <doc_id>]*
18881965GET CHUNK <chunk_id>
18891966LIST CHUNKS OF DOCUMENT <doc_id> [PAGE <page>] [SIZE <size>] [KEYWORDS <keywords>] [AVAILABLE <0|1>]
1967+ CREATE INDEX FOR DATASET <dataset> VECTOR_SIZE <vector_size>
1968+ DROP INDEX FOR DATASET <dataset>
1969+ CREATE INDEX DOC_META
1970+ DROP INDEX DOC_META
18901971
18911972Meta Commands:
18921973\\ ?, \\ h, \\ help Show this help
0 commit comments