Skip to content

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

Python

fix: pass correct jwts to refresh docs (#1687)

Lucas Oliveiraf2766a02f2ac
diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.py
index 1df60bc6e..95b2a943d 100644
--- a/src/api/settings/endpoints.py
+++ b/src/api/settings/endpoints.py
@@ -1533,6 +1533,7 @@ async def refresh_openrag_docs(
session_manager=session_manager,
force=True,
reason="manual",
+ jwt_token=user.jwt_token if getattr(user, "jwt_token", None) else None,
)
return RefreshOpenRAGDocsResponse(
message=(
diff --git a/src/models/processors.py b/src/models/processors.py
index 78ac66a72..84f4d647a 100644
--- a/src/models/processors.py
+++ b/src/models/processors.py
@@ -267,6 +267,10 @@ class TaskProcessor:
slim_doc["chunks"], cs, max(0, co)
)
+ # Filter out chunks with empty or whitespace-only text before generating embeddings.
+ # This ensures the length of chunks matches the length of the embeddings array,
+ # since chunk_texts_for_embeddings also drops empty texts.
+ slim_doc["chunks"] = [c for c in slim_doc["chunks"] if c.get("text") and c["text"].strip()]
texts = [c["text"] for c in slim_doc["chunks"]]
litellm_embedding_model = (
diff --git a/src/services/default_docs_service.py b/src/services/default_docs_service.py
index 6a01a412e..304440abd 100644
--- a/src/services/default_docs_service.py
+++ b/src/services/default_docs_service.py
@@ -366,7 +366,7 @@ async def _ingest_default_documents_url(
)
-async def _delete_existing_default_docs(session_manager, connector_type: str):
+async def _delete_existing_default_docs(session_manager, connector_type: str, jwt_token=None):
"""Delete previously ingested default OpenRAG docs before reingestion."""
from session_manager import AnonymousUser
@@ -377,8 +377,8 @@ async def _delete_existing_default_docs(session_manager, connector_type: str):
return
anonymous_user = AnonymousUser()
- effective_jwt = None
- if session_manager:
+ effective_jwt = jwt_token
+ if not effective_jwt and session_manager:
session_manager.get_user_opensearch_client(anonymous_user.user_id, effective_jwt)
if hasattr(session_manager, "_anonymous_jwt"):
effective_jwt = session_manager._anonymous_jwt
@@ -422,6 +422,7 @@ async def _reingest_default_docs_on_upgrade_if_needed(
task_service,
langflow_file_service,
session_manager,
+ jwt_token=None,
):
"""Reingest default OpenRAG docs once when app version changes."""
config = get_openrag_config()
@@ -444,13 +445,16 @@ async def _reingest_default_docs_on_upgrade_if_needed(
previous_version=previous_version,
current_version=current_version,
)
- await _delete_existing_default_docs(session_manager, connector_type="openrag_docs")
+ await _delete_existing_default_docs(
+ session_manager, connector_type="openrag_docs", jwt_token=jwt_token
+ )
await ingest_openrag_docs_when_ready(
document_service,
models_service,
task_service,
langflow_file_service,
session_manager,
+ jwt_token=jwt_token,
)
config.onboarding.openrag_docs_ingested_version = current_version
if _should_use_url_default_docs_ingest():
@@ -523,6 +527,7 @@ async def refresh_default_openrag_docs(
session_manager,
force: bool = False,
reason: str = "startup",
+ jwt_token=None,
):
"""Refresh OpenRAG docs if remote content changed or when forced."""
await TelemetryClient.send_event(
@@ -602,13 +607,16 @@ async def refresh_default_openrag_docs(
previous_signature=previous_signature,
new_signature=signature,
)
- await _delete_existing_default_docs(session_manager, connector_type="openrag_docs")
+ await _delete_existing_default_docs(
+ session_manager, connector_type="openrag_docs", jwt_token=jwt_token
+ )
await ingest_openrag_docs_when_ready(
document_service,
models_service,
task_service,
langflow_file_service,
session_manager,
+ jwt_token=jwt_token,
)
config.onboarding.openrag_docs_ingested_version = OPENRAG_VERSION
# Keep docs version/signature metadata consistent after a refresh.