diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index aa3323cf1..b87926335 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -255,6 +255,10 @@ def update_doc(tenant_id, dataset_id, document_id): ) if not DocumentService.update_by_id(document_id, {"name": req["name"]}): return get_error_data_result(message="Database error (Document rename)!") + if "meta_fields" in req: + if not isinstance(req["meta_fields"], dict): + return get_error_data_result(message="meta_fields must be a dictionary") + DocumentService.update_meta_fields(document_id, req["meta_fields"]) informs = File2DocumentService.get_by_document_id(document_id) if informs: diff --git a/api/db/services/document_service.py b/api/db/services/document_service.py index 58cb35124..4e94f9284 100644 --- a/api/db/services/document_service.py +++ b/api/db/services/document_service.py @@ -372,6 +372,10 @@ class DocumentService(CommonService): "progress_msg": "Task is queued...", "process_begin_at": get_format_time() }) + @classmethod + @DB.connection_context() + def update_meta_fields(cls, doc_id, meta_fields): + return cls.update_by_id(doc_id, {"meta_fields": meta_fields}) @classmethod @DB.connection_context() diff --git a/docs/references/python_api_reference.md b/docs/references/python_api_reference.md index f28b39a96..b95c644e5 100644 --- a/docs/references/python_api_reference.md +++ b/docs/references/python_api_reference.md @@ -262,6 +262,7 @@ A dictionary representing the attributes to update, with the following keys: - `"email"`: Email - `"knowledge_graph"`: Knowledge Graph Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens! + - `"meta_fields"`: `dict[str, Any]` The meta fields of the dataset. #### Returns diff --git a/sdk/python/ragflow_sdk/modules/document.py b/sdk/python/ragflow_sdk/modules/document.py index bb3211d24..60a6e064b 100644 --- a/sdk/python/ragflow_sdk/modules/document.py +++ b/sdk/python/ragflow_sdk/modules/document.py @@ -49,6 +49,9 @@ class Document(Base): super().__init__(rag, res_dict) def update(self, update_message: dict): + if "meta_fields" in update_message: + if not isinstance(update_message["meta_fields"], dict): + raise Exception("meta_fields must be a dictionary") res = self.put(f'/datasets/{self.dataset_id}/documents/{self.id}', update_message) res = res.json()