INNER CODE UNIT · Python
index_documents
kaito-project/kaito · presets/ragengine/main.py:311
async def index_documents(request: IndexRequest):
start_time = time.perf_counter()
status = STATUS_FAILURE # Default status
try:
doc_ids = await rag_ops.index(request.index_name, request.documents)
documents = [
Document(doc_id=doc_id, text=doc.text, metadata=doc.metadata)
for doc_id, doc in zip(doc_ids, request.documents, strict=False)
]
status = STATUS_SUCCESS
return documents
except HTTPException as http_exc:
raise http_exc
except Exception as e:
logger.error("Index failed for '%s'", request.index_name, exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
finally: