From ce3d7df6eb4d8059d323789e81001ecd37141a55 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 17 Dec 2024 23:51:49 +0100 Subject: [PATCH] fix --- api/ollama_lightrag_server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/ollama_lightrag_server.py b/api/ollama_lightrag_server.py index 589cda0e..3ef8ad4c 100644 --- a/api/ollama_lightrag_server.py +++ b/api/ollama_lightrag_server.py @@ -12,6 +12,7 @@ from typing import Optional, List from enum import Enum from pathlib import Path import shutil +import aiofiles def parse_args(): parser = argparse.ArgumentParser( @@ -134,7 +135,6 @@ def create_app(args): ), ), ) - @app.on_event("startup") async def startup_event(): """Index all files in input directory during startup""" @@ -142,9 +142,11 @@ def create_app(args): new_files = doc_manager.scan_directory() for file_path in new_files: try: - with open(file_path, 'r', encoding='utf-8') as f: - content = f.read() - rag.insert(content) + # Use async file reading + async with aiofiles.open(file_path, 'r', encoding='utf-8') as f: + content = await f.read() + # Use the async version of insert directly + await rag.ainsert(content) doc_manager.mark_as_indexed(file_path) logging.info(f"Indexed file: {file_path}") except Exception as e: