Update lightrag_server.py
Browse files- lightrag/api/lightrag_server.py +22 -12
lightrag/api/lightrag_server.py
CHANGED
@@ -408,6 +408,13 @@ def parse_args() -> argparse.Namespace:
|
|
408 |
default=get_env_value("SSL_KEYFILE", None),
|
409 |
help="Path to SSL private key file (required if --ssl is enabled)",
|
410 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
args = parser.parse_args()
|
413 |
display_splash_screen(args)
|
@@ -800,18 +807,21 @@ def create_app(args):
|
|
800 |
async def lifespan(app: FastAPI):
|
801 |
"""Lifespan context manager for startup and shutdown events"""
|
802 |
# Startup logic
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
|
|
|
|
|
|
815 |
|
816 |
@app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
|
817 |
async def scan_for_new_documents():
|
|
|
408 |
default=get_env_value("SSL_KEYFILE", None),
|
409 |
help="Path to SSL private key file (required if --ssl is enabled)",
|
410 |
)
|
411 |
+
parser.add_argument(
|
412 |
+
'--auto-scan-at-startup',
|
413 |
+
action='store_true',
|
414 |
+
default=False,
|
415 |
+
help='Enable automatic scanning when the program starts'
|
416 |
+
)
|
417 |
+
|
418 |
|
419 |
args = parser.parse_args()
|
420 |
display_splash_screen(args)
|
|
|
807 |
async def lifespan(app: FastAPI):
|
808 |
"""Lifespan context manager for startup and shutdown events"""
|
809 |
# Startup logic
|
810 |
+
# Now only if this option is active, we can scan. This is better for big databases where there are hundreds of
|
811 |
+
# files. Makes the startup faster
|
812 |
+
if args.auto_scan_at_startup:
|
813 |
+
try:
|
814 |
+
new_files = doc_manager.scan_directory()
|
815 |
+
for file_path in new_files:
|
816 |
+
try:
|
817 |
+
await index_file(file_path)
|
818 |
+
except Exception as e:
|
819 |
+
trace_exception(e)
|
820 |
+
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
821 |
+
|
822 |
+
logging.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
|
823 |
+
except Exception as e:
|
824 |
+
logging.error(f"Error during startup indexing: {str(e)}")
|
825 |
|
826 |
@app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
|
827 |
async def scan_for_new_documents():
|