From 52cee5bd16ac4ef2878ba41b68a81e3f3640f433 Mon Sep 17 00:00:00 2001 From: bsiggel Date: Thu, 26 Mar 2026 12:51:04 +0000 Subject: [PATCH] feat(upload): Enhance document metadata handling with additional fields for better context --- services/xai_service.py | 12 +++++++----- services/xai_upload_utils.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/services/xai_service.py b/services/xai_service.py index 3b84ee0..49d56e9 100644 --- a/services/xai_service.py +++ b/services/xai_service.py @@ -227,11 +227,13 @@ class XAIService: # Standard field definitions für document metadata if field_definitions is None: field_definitions = [ - {"key": "document_name", "inject_into_chunk": True}, - {"key": "description", "inject_into_chunk": True}, - {"key": "created_at", "inject_into_chunk": False}, - {"key": "modified_at", "inject_into_chunk": False}, - {"key": "espocrm_id", "inject_into_chunk": False} + {"key": "document_name", "inject_into_chunk": True}, + {"key": "description", "inject_into_chunk": True}, + {"key": "advoware_art", "inject_into_chunk": True}, + {"key": "advoware_bemerkung", "inject_into_chunk": True}, + {"key": "created_at", "inject_into_chunk": False}, + {"key": "modified_at", "inject_into_chunk": False}, + {"key": "espocrm_id", "inject_into_chunk": False}, ] session = await self._get_session() diff --git a/services/xai_upload_utils.py b/services/xai_upload_utils.py index b336d5e..5808c8b 100644 --- a/services/xai_upload_utils.py +++ b/services/xai_upload_utils.py @@ -63,7 +63,8 @@ class XAIUploadUtils: metadata={ 'espocrm_entity_type': 'CAkten', 'espocrm_entity_id': akte_id, - 'aktennummer': str(akte.get('aktennummer', '')), + 'aktenzeichen': str(akte.get('aktennummer', '')), + 'rubrum': str(akte.get('rubrum', '') or ''), } ) collection_id = col['id'] @@ -157,6 +158,19 @@ class XAIUploadUtils: await xai.add_to_collection(collection_id, new_xai_file_id) self._log.info(f" ✅ Added to collection {collection_id}") + # Set document metadata (injected into chunks for better AI context) + try: + await xai.update_document_metadata(collection_id, new_xai_file_id, { + 'document_name': doc.get('name', filename), + 'description': str(doc.get('beschreibung', '') or ''), + 'advoware_art': str(doc.get('advowareArt', '') or ''), + 'advoware_bemerkung': str(doc.get('advowareBemerkung', '') or ''), + 'espocrm_id': doc['id'], + }) + self._log.info(f" ✅ Dokument-Metadaten gesetzt") + except Exception as meta_err: + self._log.warn(f" ⚠️ Metadaten-Update fehlgeschlagen (non-fatal): {meta_err}") + # Update CDokumente with sync result now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') await espocrm.update_entity('CDokumente', doc_id, {