Skip to content

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

Python

Add require_docling and centralize availability checks

Edwin Josee9dd20321623
diff --git a/src/api/upload.py b/src/api/upload.py
index c0227989f..599856165 100644
--- a/src/api/upload.py
+++ b/src/api/upload.py
@@ -35,13 +35,6 @@ async def upload(request: Request, document_service, session_manager):
)
return JSONResponse(result, status_code=201) # Created
except Exception as e:
- from utils.document_processing import DoclingNotInstalledError
-
- if isinstance(e, DoclingNotInstalledError):
- return JSONResponse(
- {"error": str(e), "detail": "Install openrag[docling] or use Langflow for ingestion."},
- status_code=503,
- )
error_msg = str(e)
if (
"AuthenticationException" in error_msg
diff --git a/src/models/processors.py b/src/models/processors.py
index 6386a52af..3478ee862 100644
--- a/src/models/processors.py
+++ b/src/models/processors.py
@@ -217,16 +217,9 @@ class TaskProcessor:
if original_filename:
slim_doc["filename"] = original_filename
else:
- # Convert and extract using docling for other file types (requires openrag[docling])
- from utils.document_processing import (
- DoclingNotInstalledError,
- is_docling_available,
- )
+ from utils.document_processing import require_docling
- if not is_docling_available():
- raise DoclingNotInstalledError(
- "Local ingestion requires openrag[docling]. Use Langflow ingestion or install the docling extra."
- )
+ require_docling()
result = clients.converter.convert(file_path)
full_doc = result.document.export_to_dict()
slim_doc = extract_relevant(full_doc)
diff --git a/src/services/document_service.py b/src/services/document_service.py
index c9ab21a5f..93133ba11 100644
--- a/src/services/document_service.py
+++ b/src/services/document_service.py
@@ -209,14 +209,9 @@ class DocumentService:
"content_length": len(text_content),
}
else:
- # Create DocumentStream and process with docling (requires openrag[docling])
- from utils.document_processing import is_docling_available
+ from utils.document_processing import require_docling
- if not is_docling_available():
- from utils.document_processing import DoclingNotInstalledError
- raise DoclingNotInstalledError(
- "Docling is not installed. Install openrag[docling] for PDF/image context uploads or use .txt files."
- )
+ require_docling()
from docling_core.types.io import DocumentStream
doc_stream = DocumentStream(name=filename, stream=content)
diff --git a/src/utils/document_processing.py b/src/utils/document_processing.py
index dfc05ebd6..f975478db 100644
--- a/src/utils/document_processing.py
+++ b/src/utils/document_processing.py
@@ -33,8 +33,15 @@ def is_docling_available() -> bool:
return False
+def require_docling(message: str | None = None) -> None:
+ """Raise DoclingNotInstalledError if the docling extra is not installed."""
+ if not is_docling_available():
+ raise DoclingNotInstalledError(message)
+
+
def create_document_converter(ocr_engine: str | None = None):
"""Create a Docling DocumentConverter with OCR disabled unless requested."""
+ require_docling()
if ocr_engine is None:
ocr_engine = os.getenv("DOCLING_OCR_ENGINE")
@@ -109,8 +116,7 @@ def create_document_converter(ocr_engine: str | None = None):
def get_worker_converter():
"""Get or create a DocumentConverter instance for this worker process"""
global _worker_converter
- if not is_docling_available():
- raise DoclingNotInstalledError()
+ require_docling()
if _worker_converter is None:
# Configure GPU settings for this worker
has_gpu_devices, _ = detect_gpu_devices()