Feat: Add support for document meta fields update through api (#5120)

### What problem does this PR solve?

add support for update document meta data through  api
### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: wenju.li <wenju.li@deepctr.cn>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
liwenju0 2025-02-19 13:39:31 +08:00 committed by GitHub
parent fab0f07379
commit 3ced290eb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 0 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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

View File

@ -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()