Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

Pass jwt_token to ensure index creation

Edwin Jose81636b08b50b
diff --git a/src/api/connectors.py b/src/api/connectors.py
index ea2e50eaa..8e5b545ee 100644
--- a/src/api/connectors.py
+++ b/src/api/connectors.py
@@ -197,7 +197,7 @@ async def connector_sync(
if selected_files:
# Explicit files selected (e.g., from file picker) - sync those specific files
from .documents import _ensure_index_exists
- await _ensure_index_exists()
+ await _ensure_index_exists(jwt_token)
task_id = await connector_service.sync_specific_files(
working_connection.connection_id,
user.user_id,
diff --git a/src/api/documents.py b/src/api/documents.py
index a211dc8ad..d7d4b35d4 100644
--- a/src/api/documents.py
+++ b/src/api/documents.py
@@ -99,10 +99,16 @@ async def delete_documents_by_filename_core(
)
-async def _ensure_index_exists():
+async def _ensure_index_exists(jwt_token: str = None):
"""Create the OpenSearch index if it doesn't exist yet."""
from main import init_index
- await init_index()
+ from config.settings import IBM_AUTH_ENABLED, clients as app_clients
+
+ opensearch_client = None
+ if IBM_AUTH_ENABLED and jwt_token:
+ opensearch_client = app_clients.create_user_opensearch_client(jwt_token)
+
+ await init_index(opensearch_client)
async def check_filename_exists(
@@ -144,7 +150,7 @@ async def check_filename_exists(
except Exception as search_err:
if "index_not_found_exception" in str(search_err):
logger.info("Index does not exist, creating it now before upload")
- await _ensure_index_exists()
+ await _ensure_index_exists(jwt_token)
return JSONResponse({"exists": False, "filename": filename}, status_code=200)
raise
diff --git a/src/api/upload.py b/src/api/upload.py
index 33b5903ed..458d6fec5 100644
--- a/src/api/upload.py
+++ b/src/api/upload.py
@@ -95,7 +95,7 @@ async def upload_path(
owner_email = user.email
from api.documents import _ensure_index_exists
- await _ensure_index_exists()
+ await _ensure_index_exists(jwt_token)
task_id = await task_service.create_upload_task(
owner_user_id,
@@ -208,7 +208,7 @@ async def upload_bucket(
task_user_id = user.user_id
from api.documents import _ensure_index_exists
- await _ensure_index_exists()
+ await _ensure_index_exists(jwt_token)
processor = S3FileProcessor(
task_service.document_service,