feat: Implement AI Knowledge Sync Utilities and RAGFlow Service

- Added `aiknowledge_sync_utils.py` for provider-agnostic synchronization logic for CAIKnowledge entities, supporting both xAI and RAGFlow.
- Introduced lifecycle management for CAIKnowledge entities including states: new, active, paused, and deactivated.
- Implemented change detection using Blake3 hash for efficient document synchronization.
- Created `ragflow_service.py` to handle dataset and document management with RAGFlow API.
- Added daily cron job in `aiknowledge_daily_cron_step.py` to synchronize active CAIKnowledge entities with unclean or failed statuses.
- Developed `aiknowledge_sync_event_step.py` to process synchronization events from webhooks and cron jobs.
This commit is contained in:
bsiggel
2026-03-26 21:38:42 +00:00
parent 439101f35d
commit 9b2fb5ae4a
8 changed files with 1406 additions and 1 deletions

View File

@@ -552,3 +552,34 @@ class XAIService:
normalized = mime_type.lower().strip()
return normalized in supported_types
async def get_collection_by_name(self, name: str) -> Optional[Dict]:
"""
Sucht eine Collection nach Name.
Ruft alle Collections auf (Management API listet sie auf).
GET https://management-api.x.ai/v1/collections
Returns:
Collection dict oder None wenn nicht gefunden.
"""
self._log(f"🔍 Looking up collection by name: {name}")
session = await self._get_session()
url = f"{XAI_MANAGEMENT_URL}/v1/collections"
headers = {"Authorization": f"Bearer {self.management_key}"}
async with session.get(url, headers=headers) as response:
if response.status not in (200,):
raw = await response.text()
self._log(f"⚠️ list collections failed ({response.status}): {raw}", level='warn')
return None
data = await response.json()
collections = data if isinstance(data, list) else data.get('collections', [])
for col in collections:
if col.get('collection_name') == name or col.get('name') == name:
self._log(f"✅ Collection found: {col.get('collection_id') or col.get('id')}")
return col
self._log(f"⚠️ Collection not found by name: {name}", level='warn')
return None