feat(upload): Enhance document metadata handling with additional fields for better context

This commit is contained in:
bsiggel
2026-03-26 12:51:04 +00:00
parent b320f01255
commit 52cee5bd16
2 changed files with 22 additions and 6 deletions

View File

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

View File

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