Skip to content

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

Python

feat: process documents directly on Backend and passing task id to Langflow (#1526)

Lucas Oliveira44def80f8cf3
diff --git a/docker-compose.yml b/docker-compose.yml
index b1f138540..b409e693f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -104,6 +104,7 @@ services:
- INGESTION_TIMEOUT=${INGESTION_TIMEOUT:-3600}
- UPLOAD_BATCH_SIZE=${UPLOAD_BATCH_SIZE:-25}
- MAX_WORKERS=${MAX_WORKERS:-4}
+ - DOCLING_SERVE_URL=${DOCLING_SERVE_URL:-http://host.docker.internal:5001}
volumes:
- ${OPENRAG_DOCUMENTS_PATH:-./openrag-documents}:/app/openrag-documents:U,z
- ${OPENRAG_KEYS_PATH:-./keys}:/app/keys:U,z
@@ -173,11 +174,12 @@ services:
- OPENSEARCH_URL=https://${LANGFLOW_OPENSEARCH_HOST:-${OPENSEARCH_HOST:-opensearch}}:${LANGFLOW_OPENSEARCH_PORT:-${OPENSEARCH_PORT:-9200}}
- OPENSEARCH_INDEX_NAME=${OPENSEARCH_INDEX_NAME:-documents}
- DOCLING_SERVE_URL=${DOCLING_SERVE_URL:-http://host.docker.internal:5001}
+ - DOCLING_TASK_ID=None
- FILENAME=None
- MIMETYPE=None
- FILESIZE=0
- SELECTED_EMBEDDING_MODEL=${SELECTED_EMBEDDING_MODEL:-text-embedding-3-small}
- - LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,DOCLING_SERVE_URL,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENSEARCH_INDEX_NAME
+ - LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,DOCLING_SERVE_URL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENSEARCH_INDEX_NAME
- LANGFLOW_LOG_LEVEL=DEBUG
- LANGFLOW_WORKERS=${LANGFLOW_WORKERS:-1}
- LANGFLOW_AUTO_LOGIN=${LANGFLOW_AUTO_LOGIN}
diff --git a/flows/ingestion_flow.json b/flows/ingestion_flow.json
index 0ef50b777..0ddb6b82c 100644
--- a/flows/ingestion_flow.json
+++ b/flows/ingestion_flow.json
@@ -10,7 +10,7 @@
"id": "DoclingRemote-Dp3PX",
"name": "dataframe",
"output_types": [
- "DataFrame"
+ "Table"
]
},
"targetHandle": {
@@ -25,10 +25,10 @@
"type": "other"
}
},
- "id": "reactflow__edge-DoclingRemote-Dp3PX{œdataTypeœ:œDoclingRemoteœ,œidœ:œDoclingRemote-Dp3PXœ,œnameœ:œdataframeœ,œoutput_typesœ:[œDataFrameœ]}-ExportDoclingDocument-zZdRg{œfieldNameœ:œdata_inputsœ,œidœ:œExportDoclingDocument-zZdRgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
+ "id": "reactflow__edge-DoclingRemote-Dp3PX{œdataTypeœ:œDoclingRemoteœ,œidœ:œDoclingRemote-Dp3PXœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-ExportDoclingDocument-zZdRg{œfieldNameœ:œdata_inputsœ,œidœ:œExportDoclingDocument-zZdRgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
"selected": false,
"source": "DoclingRemote-Dp3PX",
- "sourceHandle": "{œdataTypeœ:œDoclingRemoteœ,œidœ:œDoclingRemote-Dp3PXœ,œnameœ:œdataframeœ,œoutput_typesœ:[œDataFrameœ]}",
+ "sourceHandle": "{œdataTypeœ:œDoclingRemoteœ,œidœ:œDoclingRemote-Dp3PXœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",
"target": "ExportDoclingDocument-zZdRg",
"targetHandle": "{œfieldNameœ:œdata_inputsœ,œidœ:œExportDoclingDocument-zZdRgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"
},
@@ -828,7 +828,7 @@
],
"frozen": false,
"icon": "braces",
- "last_updated": "2026-04-15T17:08:23.611Z",
+ "last_updated": "2026-05-05T13:33:37.431Z",
"legacy": false,
"lf_version": "1.7.0.dev21",
"metadata": {},
@@ -878,7 +878,7 @@
"value": "5488df7c-b93f-4f87-a446-b67028bc0813"
},
"_frontend_node_folder_id": {
- "value": "e37c04f4-bd18-4083-8f6f-6ee172319d91"
+ "value": "48713154-dcea-4b42-b772-268029c455d7"
},
"_type": "Component",
"code": {
@@ -1310,7 +1310,7 @@
"id": "DoclingRemote-Dp3PX",
"node": {
"base_classes": [
- "DataFrame"
+ "Table"
],
"beta": false,
"conditional_paths": [],
@@ -1318,7 +1318,7 @@
"description": "Uses Docling to process input documents connecting to your instance of Docling Serve.",
"display_name": "Docling Serve",
"documentation": "https://docling-project.github.io/docling/",
- "edited": false,
+ "edited": true,
"field_order": [
"path",
"file_path",
@@ -1328,6 +1328,7 @@
"ignore_unsupported_extensions",
"ignore_unspecified_files",
"api_url",
+ "task_id",
"max_concurrency",
"max_poll_timeout",
"api_headers",
@@ -1337,7 +1338,7 @@
"icon": "Docling",
"legacy": false,
"metadata": {
- "code_hash": "409d771a961e",
+ "code_hash": "72fcef05e057",
"dependencies": {
"dependencies": [
{
@@ -1346,15 +1347,15 @@
},
{
"name": "docling_core",
- "version": "2.60.1"
+ "version": "2.73.0"
},
{
"name": "pydantic",
- "version": "2.11.10"
+ "version": "2.12.5"
},
{
"name": "lfx",
- "version": null
+ "version": "0.4.0"
}
],
"total_dependencies": 4
@@ -1375,10 +1376,10 @@
"name": "dataframe",
"options": null,
"required_inputs": null,
- "selected": "DataFrame",
+ "selected": "Table",
"tool_mode": true,
"types": [
- "DataFrame"
+ "Table"
],
"value": "__UNDEFINED__"
}
@@ -1447,17 +1448,16 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "import base64\nimport time\nfrom concurrent.futures import Future, ThreadPoolExecutor\nfrom pathlib import Path\nfrom typing import Any\n\nimport httpx\nfrom docling_core.types.doc import DoclingDocument\nfrom pydantic import ValidationError\n\nfrom lfx.base.data import BaseFileComponent\nfrom lfx.inputs import IntInput, NestedDictInput, StrInput\nfrom lfx.inputs.inputs import FloatInput\nfrom lfx.schema import Data\nfrom lfx.utils.util import transform_localhost_url\n\n\nclass DoclingRemoteComponent(BaseFileComponent):\n display_name = \"Docling Serve\"\n description = \"Uses Docling to process input documents connecting to your instance of Docling Serve.\"\n documentation = \"https://docling-project.github.io/docling/\"\n trace_type = \"tool\"\n icon = \"Docling\"\n name = \"DoclingRemote\"\n\n MAX_500_RETRIES = 5\n\n # https://docling-project.github.io/docling/usage/supported_formats/\n VALID_EXTENSIONS = [\n \"adoc\",\n \"asciidoc\",\n \"asc\",\n \"bmp\",\n \"csv\",\n \"dotx\",\n \"dotm\",\n \"docm\",\n \"docx\",\n \"htm\",\n \"html\",\n \"jpeg\",\n \"jpg\",\n \"json\",\n \"md\",\n \"pdf\",\n \"png\",\n \"potx\",\n \"ppsx\",\n \"pptm\",\n \"potm\",\n \"ppsm\",\n \"pptx\",\n \"tiff\",\n \"txt\",\n \"xls\",\n \"xlsx\",\n \"xhtml\",\n \"xml\",\n \"webp\",\n ]\n\n inputs = [\n *BaseFileComponent.get_base_inputs(),\n StrInput(\n name=\"api_url\",\n display_name=\"Server address\",\n info=\"URL of the Docling Serve instance.\",\n required=True,\n ),\n IntInput(\n name=\"max_concurrency\",\n display_name=\"Concurrency\",\n info=\"Maximum number of concurrent requests for the server.\",\n advanced=True,\n value=2,\n input_types=[\"Message\"],\n ),\n FloatInput(\n name=\"max_poll_timeout\",\n display_name=\"Maximum poll time\",\n info=\"Maximum waiting time for the document conversion to complete.\",\n advanced=True,\n value=3600,\n input_types=[\"Message\"],\n ),\n NestedDictInput(\n name=\"api_headers\",\n display_name=\"HTTP headers\",\n advanced=True,\n required=False,\n info=(\"Optional dictionary of additional headers required for connecting to Docling Serve.\"),\n input_types=[\"Message\"],\n ),\n NestedDictInput(\n name=\"docling_serve_opts\",\n display_name=\"Docling options\",\n advanced=True,\n required=False,\n info=(\n \"Optional dictionary of additional options. \"\n \"See https://github.com/docling-project/docling-serve/blob/main/docs/usage.md for more information.\"\n ),\n input_types=[\"Message\"],\n ),\n ]\n\n outputs = [\n *BaseFileComponent.get_base_outputs(),\n ]\n\n def process_files(self, file_list: list[BaseFileComponent.BaseFile]) -> list[BaseFileComponent.BaseFile]:\n # Transform localhost URLs to container-accessible hosts when running in a container\n transformed_url = transform_localhost_url(self.api_url)\n base_url = f\"{transformed_url}/v1\"\n\n def _convert_document(client: httpx.Client, file_path: Path, options: dict[str, Any]) -> Data | None:\n encoded_doc = base64.b64encode(file_path.read_bytes()).decode()\n payload = {\n \"options\": options,\n \"sources\": [{\"kind\": \"file\", \"base64_string\": encoded_doc, \"filename\": file_path.name}],\n }\n\n response = client.post(f\"{base_url}/convert/source/async\", json=payload)\n response.raise_for_status()\n task = response.json()\n\n http_failures = 0\n retry_status_start = 500\n retry_status_end = 600\n start_wait_time = time.monotonic()\n while task[\"task_status\"] not in (\"success\", \"failure\"):\n # Check if processing exceeds the maximum poll timeout\n processing_time = time.monotonic() - start_wait_time\n if processing_time >= self.max_poll_timeout:\n msg = (\n f\"Processing time {processing_time=} exceeds the maximum poll timeout {self.max_poll_timeout=}.\"\n \"Please increase the max_poll_timeout parameter or review why the processing \"\n \"takes long on the server.\"\n )\n self.log(msg)\n raise RuntimeError(msg)\n\n # Call for a new status update\n time.sleep(2)\n response = client.get(f\"{base_url}/status/poll/{task['task_id']}\")\n\n # Check if the status call gets into 5xx errors and retry\n if retry_status_start <= response.status_code < retry_status_end:\n http_failures += 1\n if http_failures > self.MAX_500_RETRIES:\n self.log(f\"The status requests got a http response {response.status_code} too many times.\")\n return None\n continue\n\n # Update task status\n task = response.json()\n\n result_resp = client.get(f\"{base_url}/result/{task['task_id']}\")\n result_resp.raise_for_status()\n result = result_resp.json()\n\n if \"json_content\" not in result[\"document\"] or result[\"document\"][\"json_content\"] is None:\n self.log(\"No JSON DoclingDocument found in the result.\")\n return None\n\n try:\n doc = DoclingDocument.model_validate(result[\"document\"][\"json_content\"])\n return Data(data={\"doc\": doc, \"file_path\": str(file_path)})\n except ValidationError as e:\n self.log(f\"Error validating the document. {e}\")\n return None\n\n docling_options = {\n \"to_formats\": [\"json\"],\n \"image_export_mode\": \"placeholder\",\n **(self.docling_serve_opts or {}),\n }\n\n processed_data: list[Data | None] = []\n with (\n httpx.Client(headers=self.api_headers) as client,\n ThreadPoolExecutor(max_workers=self.max_concurrency) as executor,\n ):\n futures: list[tuple[int, Future]] = []\n for i, file in enumerate(file_list):\n if file.path is None:\n processed_data.append(None)\n continue\n\n futures.append((i, executor.submit(_convert_document, client, file.path, docling_options)))\n\n for _index, future in futures:\n try:\n result_data = future.result()\n processed_data.append(result_data)\n except (httpx.HTTPStatusError, httpx.RequestError, KeyError, ValueError) as exc:\n self.log(f\"Docling remote processing failed: {exc}\")\n raise\n\n return self.rollup_data(file_list, processed_data)\n"
+ "value": "import base64\nimport time\nfrom concurrent.futures import Future, ThreadPoolExecutor\nfrom pathlib import Path\nfrom typing import Any\n\nimport httpx\nfrom docling_core.types.doc import DoclingDocument\nfrom pydantic import ValidationError\n\nfrom lfx.base.data import BaseFileComponent\nfrom lfx.inputs import IntInput, NestedDictInput, StrInput\nfrom lfx.inputs.inputs import FloatInput\nfrom lfx.schema import Data\nfrom lfx.utils.util import transform_localhost_url\n\n\nclass DoclingRemoteComponent(BaseFileComponent):\n display_name = \"Docling Serve\"\n description = \"Uses Docling to process input documents connecting to your instance of Docling Serve.\"\n documentation = \"https://docling-project.github.io/docling/\"\n trace_type = \"tool\"\n icon = \"Docling\"\n name = \"DoclingRemote\"\n\n MAX_500_RETRIES = 5\n\n # https://docling-project.github.io/docling/usage/supported_formats/\n VALID_EXTENSIONS = [\n \"adoc\",\n \"asciidoc\",\n \"asc\",\n \"bmp\",\n \"csv\",\n \"dotx\",\n \"dotm\",\n \"docm\",\n \"docx\",\n \"htm\",\n \"html\",\n \"jpeg\",\n \"jpg\",\n \"json\",\n \"md\",\n \"pdf\",\n \"png\",\n \"potx\",\n \"ppsx\",\n \"pptm\",\n \"potm\",\n \"ppsm\",\n \"pptx\",\n \"tiff\",\n \"txt\",\n \"xls\",\n \"xlsx\",\n \"xhtml\",\n \"xml\",\n \"webp\",\n ]\n\n inputs = [\n *BaseFileComponent.get_base_inputs(),\n StrInput(\n name=\"api_url\",\n display_name=\"Server address\",\n info=\"URL of the Docling Serve instance.\",\n required=True,\n ),\n StrInput(\n name=\"task_id\",\n display_name=\"Task ID\",\n info=(\n \"Optional task ID from a previous Docling Serve upload. \"\n \"If provided, file input is ignored and the component polls for this task's results.\"\n ),\n required=False,\n ),\n IntInput(\n name=\"max_concurrency\",\n display_name=\"Concurrency\",\n info=\"Maximum number of concurrent requests for the server.\",\n advanced=True,\n value=2,\n input_types=[\"Message\"],\n ),\n FloatInput(\n name=\"max_poll_timeout\",\n display_name=\"Maximum poll time\",\n info=\"Maximum waiting time for the document conversion to complete.\",\n advanced=True,\n value=3600,\n input_types=[\"Message\"],\n ),\n NestedDictInput(\n name=\"api_headers\",\n display_name=\"HTTP headers\",\n advanced=True,\n required=False,\n info=(\"Optional dictionary of additional headers required for connecting to Docling Serve.\"),\n input_types=[\"Message\"],\n ),\n NestedDictInput(\n name=\"docling_serve_opts\",\n display_name=\"Docling options\",\n advanced=True,\n required=False,\n info=(\n \"Optional dictionary of additional options. \"\n \"See https://github.com/docling-project/docling-serve/blob/main/docs/usage.md for more information.\"\n ),\n input_types=[\"Message\"],\n ),\n ]\n\n outputs = [\n *BaseFileComponent.get_base_outputs(),\n ]\n\n def _poll_and_fetch_result(\n self, client: httpx.Client, base_url: str, task_id: str, file_path: str | None = None\n ) -> Data | None:\n \"\"\"Poll for task completion and fetch the result.\n\n Args:\n client: The HTTP client to use for requests.\n base_url: The base URL of the Docling Serve API.\n task_id: The task ID to poll for.\n file_path: Optional file path to include in the result data.\n\n Returns:\n Data object with the DoclingDocument, or None if processing failed.\n \"\"\"\n http_failures = 0\n retry_status_start = 500\n retry_status_end = 600\n start_wait_time = time.monotonic()\n\n response = client.get(f\"{base_url}/status/poll/{task_id}\")\n response.raise_for_status()\n task = response.json()\n\n while task[\"task_status\"] not in (\"success\", \"failure\"):\n processing_time = time.monotonic() - start_wait_time\n if processing_time >= self.max_poll_timeout:\n msg = (\n f\"Processing time {processing_time=} exceeds the maximum poll timeout {self.max_poll_timeout=}.\"\n \"Please increase the max_poll_timeout parameter or review why the processing \"\n \"takes long on the server.\"\n )\n self.log(msg)\n raise RuntimeError(msg)\n\n time.sleep(2)\n response = client.get(f\"{base_url}/status/poll/{task_id}\")\n\n if retry_status_start <= response.status_code < retry_status_end:\n http_failures += 1\n if http_failures > self.MAX_500_RETRIES:\n self.log(f\"The status requests got a http response {response.status_code} too many times.\")\n return None\n continue\n\n task = response.json()\n\n result_resp = client.get(f\"{base_url}/result/{task_id}\")\n result_resp.raise_for_status()\n result = result_resp.json()\n\n if \"json_content\" not in result[\"document\"] or result[\"document\"][\"json_content\"] is None:\n self.log(\"No JSON DoclingDocument found in the result.\")\n return None\n\n try:\n doc = DoclingDocument.model_validate(result[\"document\"][\"json_content\"])\n data_dict: dict[str, Any] = {\"doc\": doc}\n if file_path:\n data_dict[\"file_path\"] = file_path\n return Data(data=data_dict)\n except ValidationError as e:\n self.log(f\"Error validating the document. {e}\")\n return None\n\n def _process_task_id(self) -> list[Data]:\n \"\"\"Process an existing task by polling for status and retrieving results.\n\n Returns:\n List containing the result Data object, or empty list if processing failed.\n \"\"\"\n transformed_url = transform_localhost_url(self.api_url)\n base_url = f\"{transformed_url}/v1\"\n\n with httpx.Client(headers=self.api_headers) as client:\n result = self._poll_and_fetch_result(client, base_url, self.task_id)\n return [result] if result else []\n\n def load_files_base(self) -> list[Data]:\n \"\"\"Load and process files, or poll an existing task if task_id is provided.\n\n Returns:\n list[Data]: Parsed data from the processed files or task.\n \"\"\"\n if self.task_id:\n return self._process_task_id()\n return super().load_files_base()\n\n def process_files(self, file_list: list[BaseFileComponent.BaseFile]) -> list[BaseFileComponent.BaseFile]:\n transformed_url = transform_localhost_url(self.api_url)\n base_url = f\"{transformed_url}/v1\"\n\n def _convert_document(client: httpx.Client, file_path: Path, options: dict[str, Any]) -> Data | None:\n encoded_doc = base64.b64encode(file_path.read_bytes()).decode()\n payload = {\n \"options\": options,\n \"sources\": [{\"kind\": \"file\", \"base64_string\": encoded_doc, \"filename\": file_path.name}],\n }\n\n response = client.post(f\"{base_url}/convert/source/async\", json=payload)\n response.raise_for_status()\n task = response.json()\n\n return self._poll_and_fetch_result(client, base_url, task[\"task_id\"], str(file_path))\n\n docling_options = {\n \"to_formats\": [\"json\"],\n \"image_export_mode\": \"placeholder\",\n **(self.docling_serve_opts or {}),\n }\n\n processed_data: list[Data | None] = []\n with (\n httpx.Client(headers=self.api_headers) as client,\n ThreadPoolExecutor(max_workers=self.max_concurrency) as executor,\n ):\n futures: list[tuple[int, Future]] = []\n for i, file in enumerate(file_list):\n if file.path is None:\n processed_data.append(None)\n continue\n\n futures.append((i, executor.submit(_convert_document, client, file.path, docling_options)))\n\n for _index, future in futures:\n try:\n result_data = future.result()\n processed_data.append(result_data)\n except (httpx.HTTPStatusError, httpx.RequestError, KeyError, ValueError) as exc:\n self.log(f\"Docling remote processing failed: {exc}\")\n raise\n\n return self.rollup_data(file_list, processed_data)\n"
},
"delete_server_file_after_processing": {
"_input_type": "BoolInput",
"advanced": true,
"display_name": "Delete Server File After Processing",
"dynamic": false,
- "info": "If true, the File Path will be deleted after processing, if it is hosted on the Server.",
+ "info": "If true, the Server File Path will be deleted after processing.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
"name": "delete_server_file_after_processing",
"override_skip": false,
"placeholder": "",
@@ -1508,11 +1508,12 @@
"file_path": {
"_input_type": "HandleInput",
"advanced": true,
- "display_name": "File Path",
+ "display_name": "Server File Path",
"dynamic": false,
- "info": "Data object (or list of Data objects) with a 'file_path' property pointing to a file or a Message object with a path to the file or list of paths to the file. The file can be hosted on the server or on Langflow's file system. Supercedes 'Path' but supports same file types.",
+ "info": "Data object with a 'file_path' property pointing to server file or a Message object with a path to the file. Supercedes 'Path' but supports same file types.",
"input_types": [
"Data",
+ "JSON",
"Message"
],
"list": true,
@@ -1713,6 +1714,27 @@
"track_in_telemetry": true,
"type": "bool",
"value": false
+ },
+ "task_id": {
+ "_input_type": "StrInput",
+ "advanced": false,
+ "display_name": "Task ID",
+ "dynamic": false,
+ "info": "Optional task ID from a previous Docling Serve upload. If provided, file input is ignored and the component polls for this task's results.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "task_id",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "DOCLING_TASK_ID"
}
},
"tool_mode": false
@@ -1723,14 +1745,14 @@
"dragging": false,
"id": "DoclingRemote-Dp3PX",
"measured": {
- "height": 52,
- "width": 192
+ "height": 397,
+ "width": 320
},
"position": {
- "x": -18.22506037537059,
- "y": 1767.7398128168159
+ "x": -158.35302959149863,
+ "y": 1766.5193585649456
},
- "selected": false,
+ "selected": true,
"type": "genericNode"
},
{
@@ -4619,7 +4641,7 @@
"value": "5488df7c-b93f-4f87-a446-b67028bc0813"
},
"_frontend_node_folder_id": {
- "value": "e37c04f4-bd18-4083-8f6f-6ee172319d91"
+ "value": "48713154-dcea-4b42-b772-268029c455d7"
},
"_type": "Component",
"api_base": {
@@ -4888,6 +4910,96 @@
},
"name": "text-embedding-ada-002",
"provider": "OpenAI"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/granite-embedding-278m-multilingual",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-125m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-30m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "intfloat/multilingual-e5-large",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "sentence-transformers/all-minilm-l6-v2",
+ "provider": "IBM WatsonX"
}
],
"override_skip": false,
@@ -6371,7 +6483,7 @@
"value": "5488df7c-b93f-4f87-a446-b67028bc0813"
},
"_frontend_node_folder_id": {
- "value": "e37c04f4-bd18-4083-8f6f-6ee172319d91"
+ "value": "48713154-dcea-4b42-b772-268029c455d7"
},
"_type": "Component",
"api_base": {
@@ -6640,6 +6752,96 @@
},
"name": "text-embedding-ada-002",
"provider": "OpenAI"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/granite-embedding-278m-multilingual",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-125m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-30m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "intfloat/multilingual-e5-large",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "sentence-transformers/all-minilm-l6-v2",
+ "provider": "IBM WatsonX"
}
],
"override_skip": false,
@@ -6820,7 +7022,7 @@
"x": 1313.5212863870001,
"y": 1858.0159458799487
},
- "selected": true,
+ "selected": false,
"type": "genericNode"
},
{
@@ -6899,7 +7101,7 @@
"value": "5488df7c-b93f-4f87-a446-b67028bc0813"
},
"_frontend_node_folder_id": {
- "value": "e37c04f4-bd18-4083-8f6f-6ee172319d91"
+ "value": "48713154-dcea-4b42-b772-268029c455d7"
},
"_type": "Component",
"api_base": {
@@ -7167,6 +7369,96 @@
},
"name": "text-embedding-ada-002",
"provider": "OpenAI"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/granite-embedding-278m-multilingual",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-125m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "ibm/slate-30m-english-rtrvr-v2",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "intfloat/multilingual-e5-large",
+ "provider": "IBM WatsonX"
+ },
+ {
+ "category": "IBM WatsonX",
+ "icon": "WatsonxAI",
+ "metadata": {
+ "embedding_class": "WatsonxEmbeddings",
+ "model_type": "embeddings",
+ "param_mapping": {
+ "api_key": "apikey",
+ "model_id": "model_id",
+ "project_id": "project_id",
+ "request_timeout": "request_timeout",
+ "space_id": "space_id",
+ "url": "url"
+ }
+ },
+ "name": "sentence-transformers/all-minilm-l6-v2",
+ "provider": "IBM WatsonX"
}
],
"override_skip": false,
@@ -7351,9 +7643,9 @@
}
],
"viewport": {
- "x": -242.06812754438226,
- "y": -952.9999906063429,
- "zoom": 0.6625692775925841
+ "x": 267.6557208461858,
+ "y": -373.3174538705754,
+ "zoom": 0.475706358533402
}
},
"description": "Load your data for chat context with Retrieval Augmented Generation.",
diff --git a/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml b/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
index c7ffda957..537178739 100644
--- a/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
+++ b/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
@@ -150,6 +150,7 @@ stringData:
ALLOWED_USERS={{ .Values.langflow.flowDefaults.allowedUsers | quote }}
ALLOWED_GROUPS={{ .Values.langflow.flowDefaults.allowedGroups | quote }}
OPENRAG-QUERY-FILTER={{ .Values.langflow.openragQueryFilter | quote }}
+ DOCLING_TASK_ID={{ .Values.langflow.flowDefaults.doclingTaskId | quote }}
FILENAME={{ .Values.langflow.flowDefaults.filename | quote }}
MIMETYPE={{ .Values.langflow.flowDefaults.mimetype | quote }}
FILESIZE={{ .Values.langflow.flowDefaults.filesize | quote }}
diff --git a/kubernetes/helm/openrag/values.yaml b/kubernetes/helm/openrag/values.yaml
index a1fc3b221..088005cfa 100644
--- a/kubernetes/helm/openrag/values.yaml
+++ b/kubernetes/helm/openrag/values.yaml
@@ -140,6 +140,7 @@ langflow:
sourceUrl: ""
allowedUsers: "[]"
allowedGroups: "[]"
+ doclingTaskId: "None"
filename: "None"
mimetype: "None"
filesize: "0"
@@ -171,7 +172,7 @@ langflow:
host: "https://cloud.langfuse.com"
# Variables to expose to flows
- variablesToGetFromEnvironment: "JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL"
+ variablesToGetFromEnvironment: "JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL"
# Probes
livenessProbe:
diff --git a/kubernetes/operator/internal/controller/env.go b/kubernetes/operator/internal/controller/env.go
index 7222c4581..70cf7c7aa 100644
--- a/kubernetes/operator/internal/controller/env.go
+++ b/kubernetes/operator/internal/controller/env.go
@@ -31,7 +31,7 @@ func NewEnvVarManager() *EnvVarManager {
"LANGFLOW_DATABASE_URL": "sqlite:////app/data/langflow.db",
// Variables to expose to Langflow components
- "LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT": "JWT,OPENRAG_QUERY_FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_API_KEY,WATSONX_ENDPOINT,WATSONX_PROJECT_ID,OLLAMA_BASE_URL",
+ "LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT": "JWT,OPENRAG_QUERY_FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_API_KEY,WATSONX_ENDPOINT,WATSONX_PROJECT_ID,OLLAMA_BASE_URL",
// Authentication and user management
"LANGFLOW_SKIP_AUTH_AUTO_LOGIN": "true",
@@ -56,6 +56,7 @@ func NewEnvVarManager() *EnvVarManager {
"OWNER": "None",
"OWNER_NAME": "None",
"OWNER_EMAIL": "None",
+ "DOCLING_TASK_ID": "None",
"CONNECTOR_TYPE": "system",
"CONNECTOR_TYPE_URL": "url",
"DOCUMENT_ID": "",
diff --git a/kubernetes/operator/internal/controller/env_example_test.go b/kubernetes/operator/internal/controller/env_example_test.go
index 1ec0dd4ae..dc76aeb45 100644
--- a/kubernetes/operator/internal/controller/env_example_test.go
+++ b/kubernetes/operator/internal/controller/env_example_test.go
@@ -43,7 +43,7 @@ func Example_envVarPriority() {
// LANGFLOW_WORKERS: 8 (from operator env)
// LANGFLOW_LOG_LEVEL: ERROR (from CR spec)
//
- // .env file would contain 1209 bytes
+ // .env file would contain 1246 bytes
}
// Example showing how different components use different prefixes
diff --git a/kubernetes/operator/internal/controller/openrag_controller.go b/kubernetes/operator/internal/controller/openrag_controller.go
index 5843041cd..9cfec3cec 100644
--- a/kubernetes/operator/internal/controller/openrag_controller.go
+++ b/kubernetes/operator/internal/controller/openrag_controller.go
@@ -508,6 +508,19 @@ func (r *OpenRAGReconciler) buildLangflowEnv(o *openragv1alpha1.OpenRAG, secretK
}
}
+ // Docling configuration from CR spec
+ if d := o.Spec.Docling; d != nil {
+ scheme := d.Scheme
+ if scheme == "" {
+ scheme = "http"
+ }
+ port := d.Port
+ if port == 0 {
+ port = 5001
+ }
+ envVars["DOCLING_SERVE_URL"] = fmt.Sprintf("%s://%s:%d", scheme, d.Host, port)
+ }
+
// Convert map to .env file format
return r.EnvVarManager.BuildEnvFileContent(envVars)
}
diff --git a/src/api/docling.py b/src/api/docling.py
index 0b3fed11a..25d6114a8 100644
--- a/src/api/docling.py
+++ b/src/api/docling.py
@@ -9,83 +9,15 @@ import httpx
from fastapi import Request
from fastapi.responses import JSONResponse
-from utils.container_utils import (
- detect_container_environment,
- get_container_host,
- guess_host_ip_for_containers,
-)
+from config.settings import DOCLING_SERVE_URL, DOCLING_HOST_IP
from utils.logging_config import get_logger
logger = get_logger(__name__)
-def _get_gateway_ip_from_route() -> str | None:
- """Return the default gateway IP visible from the current network namespace."""
- try:
- with Path("/proc/net/route").open() as route_table:
- next(route_table) # Skip header
- for line in route_table:
- fields = line.strip().split()
- min_fields = 3 # interface, destination, gateway
- if len(fields) >= min_fields and fields[1] == "00000000":
- gateway_hex = fields[2]
- gw_int = int(gateway_hex, 16)
- gateway_ip = socket.inet_ntoa(struct.pack("<L", gw_int))
- return gateway_ip
- except (FileNotFoundError, PermissionError, IndexError, ValueError) as err:
- logger.warning("Could not read routing table: %s", err)
-
- return None
-
-
-def determine_docling_host() -> str:
- """Determine the host address used for docling health checks.
-
- Works for containers, Docker Desktop hosts, and plain Linux hosts / CI runners.
- """
- container_type = detect_container_environment()
-
- # Container-specific env var (e.g. HOST_DOCKER_INTERNAL set explicitly)
- if container_type:
- container_host = get_container_host()
- if container_host:
- logger.info("Using container-aware host '%s'", container_host)
- return container_host
-
- # Try well-known hostnames (resolves on Docker Desktop even outside a
- # container, and inside Docker/Podman containers with host networking)
- for hostname in ["host.docker.internal", "host.containers.internal"]:
- try:
- socket.getaddrinfo(hostname, None)
- logger.info("Using %s for docling-serve", hostname)
- return hostname
- except socket.gaierror:
- logger.debug("%s not available", hostname)
-
- # Container-only fallbacks: gateway IP or bridge IP
- if container_type:
- gateway_ip = _get_gateway_ip_from_route()
- if gateway_ip:
- logger.info("Detected host gateway IP: %s", gateway_ip)
- return gateway_ip
-
- fallback_ip = guess_host_ip_for_containers(logger=logger)
- logger.info("Falling back to container bridge host %s", fallback_ip)
- return fallback_ip
-
- logger.info("Using localhost for docling-serve")
- return "localhost"
-
-
-# Use explicit URL if provided, otherwise auto-detect host
-_docling_url_override = os.getenv("DOCLING_SERVE_URL")
-if _docling_url_override:
- DOCLING_SERVICE_URL = _docling_url_override.rstrip("/")
- HOST_IP = _docling_url_override # For display in health responses
- logger.info("Using DOCLING_SERVE_URL override: %s", DOCLING_SERVICE_URL)
-else:
- HOST_IP = determine_docling_host()
- DOCLING_SERVICE_URL = f"http://{HOST_IP}:5001"
+# Use values resolved from config boundary
+DOCLING_SERVICE_URL = DOCLING_SERVE_URL
+HOST_IP = DOCLING_HOST_IP
async def health(request: Request) -> JSONResponse:
diff --git a/src/api/langflow_files.py b/src/api/langflow_files.py
index ebd3d1dcb..b3b80c4bb 100644
--- a/src/api/langflow_files.py
+++ b/src/api/langflow_files.py
@@ -135,7 +135,6 @@ async def upload_and_ingest_user_file(
session_id: Optional[str] = Form(None),
settings_json: Optional[str] = Form(None, alias="settings"),
tweaks_json: Optional[str] = Form(None, alias="tweaks"),
- delete_after_ingest: str = Form("true"),
langflow_file_service=Depends(get_langflow_file_service),
session_manager=Depends(get_session_manager),
task_service=Depends(get_task_service),
@@ -180,7 +179,6 @@ async def upload_and_ingest_user_file(
session_id=session_id,
tweaks=tweaks,
settings=settings,
- delete_after_ingest=delete_after_ingest.lower() == "true",
)
return JSONResponse(
diff --git a/src/api/router.py b/src/api/router.py
index cbd12f3c9..6e219aa4f 100644
--- a/src/api/router.py
+++ b/src/api/router.py
@@ -27,7 +27,6 @@ async def upload_ingest_router(
session_id: Optional[str] = Form(None),
settings_json: Optional[str] = Form(None, alias="settings"),
tweaks_json: Optional[str] = Form(None, alias="tweaks"),
- delete_after_ingest: str = Form("true"),
replace_duplicates: str = Form("true"),
create_filter: str = Form("false"),
document_service=Depends(get_document_service),
@@ -64,7 +63,6 @@ async def upload_ingest_router(
session_id=session_id,
settings_json=settings_json,
tweaks_json=tweaks_json,
- delete_after_ingest=delete_after_ingest.lower() == "true",
replace_duplicates=replace_duplicates.lower() == "true",
create_filter=create_filter.lower() == "true",
langflow_file_service=langflow_file_service,
@@ -79,7 +77,6 @@ async def _langflow_upload_ingest_task(
session_id,
settings_json,
tweaks_json,
- delete_after_ingest: bool,
replace_duplicates: bool,
create_filter: bool,
langflow_file_service,
@@ -141,7 +138,6 @@ async def _langflow_upload_ingest_task(
session_id=session_id,
tweaks=tweaks,
settings=settings,
- delete_after_ingest=delete_after_ingest,
replace_duplicates=replace_duplicates,
)
diff --git a/src/api/settings.py b/src/api/settings.py
index f6ba3595c..68436b88c 100644
--- a/src/api/settings.py
+++ b/src/api/settings.py
@@ -38,6 +38,7 @@ from dependencies import (
get_knowledge_filter_service,
get_chat_service,
)
+from services.docling_service import DoclingConfig, get_docling_preset_configs
from session_manager import User
logger = get_logger(__name__)
@@ -197,19 +198,12 @@ class RefreshOpenRAGDocsResponse(BaseModel):
message: str
refreshed: bool
-class DoclingConfig(BaseModel):
- do_ocr: bool
- ocr_engine: str
- do_table_structure: bool
- do_picture_classification: bool
- do_picture_description: bool
- picture_description_local: Optional[dict] = None
-
class DoclingPresetResponse(BaseModel):
message: str
settings: dict
preset_config: DoclingConfig
+
class OnboardingStateResponse(BaseModel):
message: str
updated_fields: List[str]
@@ -229,31 +223,6 @@ class RollbackBody(BaseModel):
# Docling preset configurations
-def get_docling_preset_configs(
- table_structure=False, ocr=False, picture_descriptions=False
-):
- """Get docling preset configurations based on toggle settings
-
- Args:
- table_structure: Enable table structure parsing (default: False)
- ocr: Enable OCR for text extraction from images (default: False)
- picture_descriptions: Enable picture descriptions/captions (default: False)
- """
- is_macos = platform.system() == "Darwin"
-
- config = {
- "do_ocr": ocr,
- "ocr_engine": "ocrmac" if is_macos else "easyocr",
- "do_table_structure": table_structure,
- "do_picture_classification": picture_descriptions,
- "do_picture_description": picture_descriptions,
- "picture_description_local": {
- "repo_id": "HuggingFaceTB/SmolVLM-256M-Instruct",
- "prompt": "Describe this image in a few sentences.",
- },
- }
-
- return config
async def get_settings(
diff --git a/src/api/upload.py b/src/api/upload.py
index 460a69492..4633f08bd 100644
--- a/src/api/upload.py
+++ b/src/api/upload.py
@@ -1,3 +1,4 @@
+from dependencies import get_docling_service
from dependencies import get_models_service
import os
from typing import Optional
@@ -169,6 +170,7 @@ async def upload_bucket(
body: UploadBucketBody,
task_service=Depends(get_task_service),
models_service=Depends(get_models_service),
+ docling_service=Depends(get_docling_service),
session_manager=Depends(get_session_manager),
user: User = Depends(get_current_user),
):
@@ -215,6 +217,7 @@ async def upload_bucket(
task_service.document_service,
bucket,
models_service=models_service,
+ docling_service=docling_service,
s3_client=s3_client,
owner_user_id=owner_user_id,
jwt_token=jwt_token,
diff --git a/src/api/v1/documents.py b/src/api/v1/documents.py
index ecb4eceec..5fd3027de 100644
--- a/src/api/v1/documents.py
+++ b/src/api/v1/documents.py
@@ -34,7 +34,6 @@ async def ingest_endpoint(
session_id: Optional[str] = Form(None),
settings: Optional[str] = Form(None),
tweaks: Optional[str] = Form(None),
- delete_after_ingest: str = Form("true"),
replace_duplicates: str = Form("true"),
create_filter: str = Form("false"),
document_service=Depends(get_document_service),
@@ -55,7 +54,6 @@ async def ingest_endpoint(
session_id=session_id,
settings_json=settings,
tweaks_json=tweaks,
- delete_after_ingest=delete_after_ingest,
replace_duplicates=replace_duplicates,
create_filter=create_filter,
document_service=document_service,
diff --git a/src/config/settings.py b/src/config/settings.py
index 75a97b2d5..89b19a24d 100644
--- a/src/config/settings.py
+++ b/src/config/settings.py
@@ -13,7 +13,7 @@ from opensearchpy import AsyncOpenSearch
from opensearchpy._async.http_aiohttp import AIOHttpConnection
from config.embedding_constants import OPENAI_DEFAULT_EMBEDDING_MODEL
-from utils.container_utils import get_container_host
+from utils.container_utils import get_container_host, determine_docling_host
from utils.embedding_fields import build_knn_vector_field
from utils.logging_config import get_logger
# Import configuration manager
@@ -69,6 +69,21 @@ DOCLING_OCR_ENGINE = os.getenv("DOCLING_OCR_ENGINE")
SEGMENT_WRITE_KEY = os.getenv("SEGMENT_WRITE_KEY", "")
ENVIRONMENT = os.getenv("ENVIRONMENT", "")
+# Docling service URL configuration
+# Priority:
+# 1. DOCLING_SERVE_URL environment variable
+# 2. Auto-detected host (container gateway, host.docker.internal, or localhost)
+_docling_url_override = os.getenv("DOCLING_SERVE_URL")
+if _docling_url_override:
+ DOCLING_SERVE_URL = _docling_url_override.rstrip("/")
+ # For health display / logging
+ DOCLING_HOST_IP = _docling_url_override
+ logger.info("Using DOCLING_SERVE_URL override: %s", DOCLING_SERVE_URL)
+else:
+ DOCLING_HOST_IP = determine_docling_host()
+ DOCLING_SERVE_URL = f"http://{DOCLING_HOST_IP}:5001"
+ logger.info("Auto-detected Docling host: %s (URL: %s)", DOCLING_HOST_IP, DOCLING_SERVE_URL)
+
IBM_AUTH_ENABLED = os.getenv("IBM_AUTH_ENABLED", "false").lower() in ("true", "1", "yes")
# Ingestion configuration
@@ -324,6 +339,7 @@ class AppClients:
self._patched_async_client = None # Private attribute - single client for all providers
self._client_init_lock = threading.Lock() # Lock for thread-safe initialization
self.docling_http_client = None
+ self._docling_service = None
async def initialize(self):
os_auth = None if IBM_AUTH_ENABLED else (OPENSEARCH_USERNAME, OPENSEARCH_PASSWORD)
@@ -360,6 +376,10 @@ class AppClients:
)
)
+ # Eagerly initialize DoclingService to ensure thread-safety
+ from services.docling_service import DoclingService
+ self._docling_service = DoclingService(httpx_client=self.docling_http_client)
+
# Initialize Langflow HTTP client with extended timeouts for large documents
# Must be created before wait_for_langflow / get_langflow_api_key
# Use explicit timeout configuration to handle large PDF ingestion (300+ pages)
@@ -600,6 +620,23 @@ class AppClients:
finally:
self._patched_async_client = None
+ @property
+ def docling_service(self):
+ """Property that ensures DoclingService is initialized."""
+ # Quick check without lock
+ if self._docling_service is not None:
+ return self._docling_service
+
+ # Use lock to ensure only one thread initializes
+ with self._client_init_lock:
+ # Double-check after acquiring lock
+ if self._docling_service is not None:
+ return self._docling_service
+
+ from services.docling_service import DoclingService
+ self._docling_service = DoclingService(httpx_client=self.docling_http_client)
+ return self._docling_service
+
async def cleanup(self):
"""Cleanup resources - should be called on application shutdown"""
# Close AsyncOpenAI client if it was created
diff --git a/src/connectors/langflow_connector_service.py b/src/connectors/langflow_connector_service.py
index efe00c1d0..45e7d6314 100644
--- a/src/connectors/langflow_connector_service.py
+++ b/src/connectors/langflow_connector_service.py
@@ -19,13 +19,16 @@ class LangflowConnectorService:
self,
task_service=None,
session_manager=None,
+ flows_service=None,
+ docling_service=None,
):
self.task_service = task_service
self.session_manager = session_manager
+ self.docling_service = docling_service
self.connection_manager = ConnectionManager()
-
- # Initialize LangflowFileService for processing connector documents
- self.langflow_service = LangflowFileService()
+ self.langflow_service = LangflowFileService(
+ flows_service=flows_service, docling_service=docling_service
+ )
async def initialize(self):
"""Initialize the service by loading existing connections"""
diff --git a/src/connectors/service.py b/src/connectors/service.py
index df3a2e3f5..482a9aa54 100644
--- a/src/connectors/service.py
+++ b/src/connectors/service.py
@@ -22,6 +22,7 @@ class ConnectorService:
session_manager=None,
models_service=None,
document_service=None,
+ docling_service=None,
):
self.clients = patched_async_client
self.embed_model = embed_model
@@ -31,6 +32,7 @@ class ConnectorService:
self.connection_manager = ConnectionManager()
self.models_service = models_service
self.document_service = document_service
+ self.docling_service = docling_service
async def initialize(self):
"""Initialize the service by loading existing connections"""
@@ -66,7 +68,11 @@ class ConnectorService:
# Process using consolidated processing pipeline
from models.processors import TaskProcessor
- processor = TaskProcessor(document_service=self.document_service, models_service=self.models_service)
+ processor = TaskProcessor(
+ document_service=self.document_service,
+ models_service=self.models_service,
+ docling_service=self.docling_service,
+ )
result = await processor.process_document_standard(
file_path=tmp_path,
file_hash=document.id, # Use connector document ID as hash
diff --git a/src/dependencies.py b/src/dependencies.py
index 2b0e60b95..b407e5a54 100644
--- a/src/dependencies.py
+++ b/src/dependencies.py
@@ -87,6 +87,10 @@ def get_flows_service(services: dict = Depends(get_services)):
return services["flows_service"]
+def get_docling_service(services: dict = Depends(get_services)):
+ return services["docling_service"]
+
+
# ─────────────────────────────────────────────
# IBM AMS authentication helper
# ─────────────────────────────────────────────
diff --git a/src/main.py b/src/main.py
index 2a189b86f..5afeda272 100644
--- a/src/main.py
+++ b/src/main.py
@@ -602,7 +602,6 @@ async def _ingest_default_documents_langflow(
session_id=None, # No session for default documents
tweaks=default_tweaks,
settings=None, # Use default ingestion settings
- delete_after_ingest=True, # Clean up after ingestion
replace_duplicates=True,
connector_type=connector_type,
existing_task_id=existing_task_id,
@@ -1377,21 +1376,35 @@ async def initialize_services():
# Initialize services
models_service = ModelsService()
- document_service = DocumentService(session_manager=session_manager, models_service=models_service)
+ document_service = DocumentService(
+ session_manager=session_manager,
+ models_service=models_service,
+ docling_service=clients.docling_service,
+ )
search_service = SearchService(session_manager, models_service)
register_search_service(search_service)
- task_service = TaskService(document_service, models_service, ingestion_timeout=INGESTION_TIMEOUT)
+ task_service = TaskService(
+ document_service,
+ models_service,
+ ingestion_timeout=INGESTION_TIMEOUT,
+ docling_service=clients.docling_service,
+ )
flows_service = FlowsService()
chat_service = ChatService(flows_service=flows_service)
knowledge_filter_service = KnowledgeFilterService(session_manager)
monitor_service = MonitorService(session_manager)
- langflow_file_service = LangflowFileService(flows_service=flows_service)
+ langflow_file_service = LangflowFileService(
+ flows_service=flows_service,
+ docling_service=clients.docling_service,
+ )
langflow_mcp_service = LangflowMCPService()
# Initialize both connector services
langflow_connector_service = LangflowConnectorService(
task_service=task_service,
session_manager=session_manager,
+ flows_service=flows_service,
+ docling_service=clients.docling_service,
)
openrag_connector_service = ConnectorService(
patched_async_client=clients,
@@ -1401,6 +1414,7 @@ async def initialize_services():
session_manager=session_manager,
models_service=models_service,
document_service=document_service,
+ docling_service=clients.docling_service,
)
# Create connector router that chooses based on configuration
@@ -1461,6 +1475,7 @@ async def initialize_services():
"session_manager": session_manager,
"api_key_service": api_key_service,
"langflow_mcp_service": langflow_mcp_service,
+ "docling_service": clients.docling_service,
}
diff --git a/src/models/processors.py b/src/models/processors.py
index 86df12194..62d3be1e7 100644
--- a/src/models/processors.py
+++ b/src/models/processors.py
@@ -13,9 +13,10 @@ logger = get_logger(__name__)
class TaskProcessor:
"""Base class for task processors with shared processing logic"""
- def __init__(self, document_service=None, models_service=None):
+ def __init__(self, document_service=None, models_service=None, docling_service=None):
self.document_service = document_service
self.models_service = models_service
+ self.docling_service = docling_service
async def check_document_exists(
self,
@@ -261,9 +262,7 @@ class TaskProcessor:
if original_filename:
slim_doc["filename"] = original_filename
else:
- from utils.docling_client import convert_file
-
- full_doc = await convert_file(file_path, httpx_client=clients.docling_http_client)
+ full_doc = await self.docling_service.convert_file(file_path)
slim_doc = extract_relevant(full_doc)
if chunk_size is not None:
@@ -407,8 +406,14 @@ class DocumentFileProcessor(TaskProcessor):
owner_email: str = None,
is_sample_data: bool = False,
connector_type: str = "local",
+ docling_service=None,
):
- super().__init__(document_service, models_service)
+ super().__init__(
+ document_service,
+ models_service,
+ docling_service=docling_service
+ or (document_service.docling_service if document_service else None),
+ )
self.owner_user_id = owner_user_id
self.jwt_token = jwt_token
self.owner_name = owner_name
@@ -484,7 +489,13 @@ class ConnectorFileProcessor(TaskProcessor):
models_service=None,
ingest_settings: Optional[Dict[str, Any]] = None,
):
- super().__init__(document_service=document_service, models_service=models_service)
+ super().__init__(
+ document_service=document_service,
+ models_service=models_service,
+ docling_service=document_service.docling_service
+ if document_service
+ else None,
+ )
self.connector_service = connector_service
self.connection_id = connection_id
self.files_to_process = files_to_process
@@ -604,7 +615,15 @@ class LangflowConnectorFileProcessor(TaskProcessor):
owner_email: str = None,
ingest_settings: Optional[Dict[str, Any]] = None,
):
- super().__init__()
+ super().__init__(
+ document_service=langflow_connector_service.task_service.document_service
+ if langflow_connector_service.task_service
+ else None,
+ models_service=langflow_connector_service.task_service.models_service
+ if langflow_connector_service.task_service
+ else None,
+ docling_service=langflow_connector_service.docling_service,
+ )
self.langflow_connector_service = langflow_connector_service
self.connection_id = connection_id
self.files_to_process = files_to_process
@@ -711,10 +730,15 @@ class S3FileProcessor(TaskProcessor):
owner_name: str = None,
owner_email: str = None,
models_service=None,
+ docling_service=None,
):
import boto3
- super().__init__(document_service, models_service)
+ super().__init__(
+ document_service,
+ models_service,
+ docling_service,
+ )
self.bucket = bucket
self.s3_client = s3_client or boto3.client("s3")
self.owner_user_id = owner_user_id
@@ -795,7 +819,6 @@ class LangflowFileProcessor(TaskProcessor):
session_id: str = None,
tweaks: dict = None,
settings: dict = None,
- delete_after_ingest: bool = True,
replace_duplicates: bool = False,
connector_type: str = "local",
):
@@ -809,7 +832,6 @@ class LangflowFileProcessor(TaskProcessor):
self.session_id = session_id
self.tweaks = tweaks or {}
self.settings = settings
- self.delete_after_ingest = delete_after_ingest
self.replace_duplicates = replace_duplicates
self.connector_type = connector_type
@@ -893,7 +915,6 @@ class LangflowFileProcessor(TaskProcessor):
tweaks=final_tweaks,
settings=self.settings,
jwt_token=effective_jwt,
- delete_after_ingest=self.delete_after_ingest,
owner=self.owner_user_id,
owner_name=self.owner_name,
owner_email=self.owner_email,
diff --git a/src/services/docling_service.py b/src/services/docling_service.py
new file mode 100644
index 000000000..b0befd650
--- /dev/null
+++ b/src/services/docling_service.py
@@ -0,0 +1,203 @@
+import asyncio
+import platform
+import json
+from pathlib import Path
+from typing import Any, Optional, Dict
+import httpx
+from pydantic import BaseModel
+
+from config.settings import get_openrag_config, DOCLING_SERVE_URL
+from utils.logging_config import get_logger
+
+logger = get_logger(__name__)
+
+class DoclingConfig(BaseModel):
+ do_ocr: bool
+ ocr_engine: str
+ do_table_structure: bool
+ do_picture_classification: bool
+ do_picture_description: bool
+ picture_description_local: Optional[dict] = None
+
+class DoclingServeError(Exception):
+ """Raised when docling-serve conversion fails."""
+
+def get_docling_preset_configs(
+ table_structure=False, ocr=False, picture_descriptions=False
+) -> Dict[str, Any]:
+ """Get docling preset configurations based on toggle settings"""
+ is_macos = platform.system() == "Darwin"
+
+ config = {
+ "do_ocr": ocr,
+ "ocr_engine": "ocrmac" if is_macos else "easyocr",
+ "do_table_structure": table_structure,
+ "do_picture_classification": picture_descriptions,
+ "do_picture_description": picture_descriptions,
+ "picture_description_local": {
+ "repo_id": "HuggingFaceTB/SmolVLM-256M-Instruct",
+ "prompt": "Describe this image in a few sentences.",
+ },
+ }
+
+ return config
+
+class DoclingService:
+ _default_client: Optional[httpx.AsyncClient] = None
+
+ def __init__(self, docling_url: Optional[str] = None, httpx_client: Optional[httpx.AsyncClient] = None):
+ """
+ Initialize the DoclingService.
+
+ Args:
+ docling_url: Base URL of the Docling Serve instance. If None, auto-detects.
+ httpx_client: Pre-configured httpx async client.
+ """
+ if docling_url:
+ self.docling_url = docling_url.rstrip("/")
+ else:
+ self.docling_url = DOCLING_SERVE_URL
+
+ self.httpx_client = httpx_client
+
+ def _get_client(self) -> httpx.AsyncClient:
+ if self.httpx_client:
+ return self.httpx_client
+ if DoclingService._default_client is None or DoclingService._default_client.is_closed:
+ DoclingService._default_client = httpx.AsyncClient(
+ timeout=httpx.Timeout(300.0, connect=10.0)
+ )
+ return DoclingService._default_client
+
+ def _build_docling_options(self) -> Dict[str, Any]:
+ """Build the options payload for docling from OpenRAG configs."""
+ config = get_openrag_config()
+ knowledge_config = config.knowledge
+
+ preset = get_docling_preset_configs(
+ table_structure=knowledge_config.table_structure,
+ ocr=knowledge_config.ocr,
+ picture_descriptions=knowledge_config.picture_descriptions
+ )
+
+ options = {
+ "to_formats": "json",
+ "image_export_mode": "placeholder",
+ **preset
+ }
+ return options
+
+ async def upload_to_docling_direct_async(self, filename: str, file_content: bytes) -> str:
+ """
+ Upload a file to Docling Serve asynchronously using direct multipart/form-data upload.
+ """
+ options = self._build_docling_options()
+
+ # Docling serve async multipart endpoint /v1/convert/file/async
+ # Options are passed as form data
+ data = {
+ k: str(v).lower() if isinstance(v, bool) else v
+ for k, v in options.items()
+ if not isinstance(v, dict)
+ } # picture_description_local needs to be JSON if it's a dict
+
+ if "picture_description_local" in options:
+ data["picture_description_local"] = json.dumps(options["picture_description_local"])
+
+ files = {"files": (filename, file_content)}
+
+ client = self._get_client()
+ should_close = client != self.httpx_client
+
+ try:
+ if should_close:
+ async with client:
+ response = await client.post(
+ f"{self.docling_url}/v1/convert/file/async",
+ files=files,
+ data=data
+ )
+ else:
+ response = await client.post(
+ f"{self.docling_url}/v1/convert/file/async",
+ files=files,
+ data=data
+ )
+
+ response.raise_for_status()
+ task = response.json()
+ return task["task_id"]
+ except Exception as e:
+ logger.error("Docling upload failed", filename=filename, error=str(e))
+ raise
+
+ async def get_docling_result_async(
+ self,
+ task_id: str,
+ poll_interval: float = 1.0,
+ timeout: float = 600.0
+ ) -> Dict[str, Any]:
+ """
+ Poll Docling Serve for the result of an async conversion task.
+ """
+ client = self._get_client()
+ should_close = client != self.httpx_client
+
+ try:
+ if should_close:
+ async with client:
+ return await self._poll_result(client, task_id, poll_interval, timeout)
+ else:
+ return await self._poll_result(client, task_id, poll_interval, timeout)
+ except Exception as e:
+ logger.error("Docling result retrieval failed", task_id=task_id, error=str(e))
+ raise
+
+ async def _poll_result(self, client: httpx.AsyncClient, task_id: str, poll_interval: float, timeout: float) -> Dict[str, Any]:
+ """Internal polling logic."""
+ elapsed = 0.0
+ while elapsed < timeout:
+ try:
+ response = await client.get(f"{self.docling_url}/v1/status/poll/{task_id}")
+ response.raise_for_status()
+ status_data = response.json()
+ except Exception as e:
+ logger.error("Error polling docling status", task_id=task_id, error=str(e))
+ raise DoclingServeError(f"Error polling docling status: {str(e)}")
+
+ status = status_data.get("task_status")
+
+ if status == "success":
+ result_response = await client.get(f"{self.docling_url}/v1/result/{task_id}")
+ result_response.raise_for_status()
+ result_json = result_response.json()
+
+ # Extract the json_content which matches the old convert_file/bytes return
+ doc_content = result_json.get("document", {}).get("json_content")
+ if doc_content is None:
+ raise DoclingServeError("docling-serve response missing document.json_content")
+
+ return doc_content
+ elif status == "failure":
+ raise DoclingServeError(f"Docling conversion failed: {status_data}")
+
+ await asyncio.sleep(poll_interval)
+ elapsed += poll_interval
+
+ raise TimeoutError(f"Docling task {task_id} did not complete within {timeout} seconds")
+
+ async def convert_file(self, file_path: str) -> Dict[str, Any]:
+ """
+ Convert a local file via docling-serve async polling.
+ """
+ path = Path(file_path)
+ file_bytes = path.read_bytes()
+ task_id = await self.upload_to_docling_direct_async(path.name, file_bytes)
+ return await self.get_docling_result_async(task_id)
+
+ async def convert_bytes(self, content: bytes, filename: str) -> Dict[str, Any]:
+ """
+ Convert in-memory bytes via docling-serve async polling.
+ """
+ task_id = await self.upload_to_docling_direct_async(filename, content)
+ return await self.get_docling_result_async(task_id)
diff --git a/src/services/document_service.py b/src/services/document_service.py
index f0c7f42d7..8b9672fb3 100644
--- a/src/services/document_service.py
+++ b/src/services/document_service.py
@@ -87,9 +87,10 @@ def chunk_texts_for_embeddings(
class DocumentService:
- def __init__(self, session_manager=None, models_service=None):
+ def __init__(self, session_manager=None, models_service=None, docling_service=None):
self.session_manager = session_manager
self.models_service = models_service
+ self.docling_service = docling_service
self._mapping_ensured = False
@@ -145,7 +146,7 @@ class DocumentService:
# Use consolidated standard processing
from models.processors import TaskProcessor
- processor = TaskProcessor(document_service=self, models_service=self.models_service)
+ processor = TaskProcessor(document_service=self, models_service=self.models_service, docling_service=self.docling_service)
result = await processor.process_document_standard(
file_path=tmp_path,
file_hash=file_hash,
@@ -191,9 +192,7 @@ class DocumentService:
"content_length": len(text_content),
}
else:
- from utils.docling_client import convert_bytes
-
- full_doc = await convert_bytes(content.read(), filename, httpx_client=clients.docling_http_client)
+ full_doc = await self.docling_service.convert_bytes(content.read(), filename)
slim_doc = extract_relevant(full_doc)
# Extract all text content
diff --git a/src/services/langflow_file_service.py b/src/services/langflow_file_service.py
index 44bc95d4d..397438a07 100644
--- a/src/services/langflow_file_service.py
+++ b/src/services/langflow_file_service.py
@@ -1,19 +1,25 @@
import json
import asyncio
+import time
import httpx
from pathlib import Path
from typing import Any, Dict, List, Optional
-from config.settings import LANGFLOW_INGEST_FLOW_ID, LANGFLOW_URL_INGEST_FLOW_ID, clients
+from config.settings import (
+ LANGFLOW_INGEST_FLOW_ID,
+ LANGFLOW_URL_INGEST_FLOW_ID,
+ clients,
+)
from utils.logging_config import get_logger
logger = get_logger(__name__)
class LangflowFileService:
- def __init__(self, flows_service=None):
+ def __init__(self, flows_service=None, docling_service=None):
self.flow_id_ingest = LANGFLOW_INGEST_FLOW_ID
self.flows_service = flows_service
+ self.docling_service = docling_service
self.flow_id_url_ingest = LANGFLOW_URL_INGEST_FLOW_ID
_TRANSIENT_STATUS_CODES = {408, 429, 500, 502, 503, 504}
@@ -133,6 +139,7 @@ class LangflowFileService:
allowed_users: Optional[List[str]] = None,
allowed_groups: Optional[List[str]] = None,
selected_embedding_model: Optional[str] = None,
+ docling_task_id: Optional[str] = None,
) -> Dict[str, Any]:
"""
Trigger the ingestion flow with provided file paths.
@@ -181,17 +188,25 @@ class LangflowFileService:
bool(jwt_token),
)
# To compute the file size in bytes, use len() on the file content (which should be bytes)
- file_size_bytes = len(file_tuples[0][1]) if file_tuples and len(file_tuples[0]) > 1 else 0
+ file_size_bytes = (
+ len(file_tuples[0][1]) if file_tuples and len(file_tuples[0]) > 1 else 0
+ )
# Avoid logging full payload to prevent leaking sensitive data (e.g., JWT)
# Extract file metadata if file_tuples is provided
- filename = str(file_tuples[0][0]) if file_tuples and len(file_tuples) > 0 else ""
- mimetype = str(file_tuples[0][2]) if file_tuples and len(file_tuples) > 0 and len(file_tuples[0]) > 2 else ""
+ filename = (
+ str(file_tuples[0][0]) if file_tuples and len(file_tuples) > 0 else ""
+ )
+ mimetype = (
+ str(file_tuples[0][2])
+ if file_tuples and len(file_tuples) > 0 and len(file_tuples[0]) > 2
+ else ""
+ )
# Get the current embedding model and provider credentials from config
from config.settings import get_openrag_config
from utils.langflow_headers import add_provider_credentials_to_headers
-
+
config = get_openrag_config()
embedding_model = config.knowledge.embedding_model
if selected_embedding_model:
@@ -207,8 +222,13 @@ class LangflowFileService:
"X-Langflow-Global-Var-MIMETYPE": mimetype,
"X-Langflow-Global-Var-FILESIZE": str(file_size_bytes),
"X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL": str(embedding_model),
- "X-Langflow-Global-Var-DOCUMENT_ID": str(document_id) if document_id else "",
+ "X-Langflow-Global-Var-DOCUMENT_ID": str(document_id)
+ if document_id
+ else "",
"X-Langflow-Global-Var-SOURCE_URL": str(source_url) if source_url else "",
+ "X-Langflow-Global-Var-DOCLING_TASK_ID": str(docling_task_id)
+ if docling_task_id
+ else "",
}
# Serialize ACL lists as JSON strings for Langflow global vars
@@ -221,18 +241,30 @@ class LangflowFileService:
headers["X-Langflow-Global-Var-ALLOWED_GROUPS"] = json.dumps(
allowed_groups or []
)
-
+
# Add provider credentials as global variables for ingestion
- await add_provider_credentials_to_headers(headers, config, flows_service=self.flows_service, jwt_token=jwt_token)
- logger.info("[INGEST] Run started", flow_id=self.flow_id_ingest, filename=filename, mimetype=mimetype)
+ await add_provider_credentials_to_headers(
+ headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ )
+ start_time = time.time()
+ logger.info(
+ "[INGEST] Run started",
+ flow_id=self.flow_id_ingest,
+ filename=filename,
+ mimetype=mimetype,
+ )
resp = await clients.langflow_request(
"POST",
f"/api/v1/run/{self.flow_id_ingest}",
json=payload,
headers=headers,
)
+ duration = round(time.time() - start_time, 2)
logger.info(
- "[INGEST] Run complete", status_code=resp.status_code, reason=resp.reason_phrase
+ "[INGEST] Run complete",
+ status_code=resp.status_code,
+ reason=resp.reason_phrase,
+ duration_s=duration,
)
if resp.status_code >= 400:
logger.error(
@@ -241,7 +273,7 @@ class LangflowFileService:
reason=resp.reason_phrase,
body=resp.text[:1000],
)
-
+
# Extract error message from Langflow response
error_message = f"Server error '{resp.status_code} {resp.reason_phrase}'"
try:
@@ -261,9 +293,9 @@ class LangflowFileService:
error_message = detail["message"]
except Exception:
pass
-
+
raise Exception(error_message)
-
+
# Check if response is actually JSON before parsing
content_type = resp.headers.get("content-type", "")
if "application/json" not in content_type:
@@ -278,7 +310,7 @@ class LangflowFileService:
f"This may indicate the ingestion flow failed or the endpoint is incorrect. "
f"Response preview: {resp.text[:500]}"
)
-
+
try:
resp_json = resp.json()
except Exception as e:
@@ -328,15 +360,15 @@ class LangflowFileService:
"X-Langflow-Global-Var-OWNER_EMAIL": str(owner_email),
"X-Langflow-Global-Var-CONNECTOR_TYPE": str(connector_type),
"X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL": str(embedding_model),
-
- "X-Langflow-Global-Var-DOCUMENT_ID":"",
+ "X-Langflow-Global-Var-DOCUMENT_ID": "",
"X-Langflow-Global-Var-SOURCE_URL": str(docs_url),
-
- "X-Langflow-Global-Var-ALLOWED_USERS": json.dumps( []),
- "X-Langflow-Global-Var-ALLOWED_GROUPS": json.dumps( []),
+ "X-Langflow-Global-Var-ALLOWED_USERS": json.dumps([]),
+ "X-Langflow-Global-Var-ALLOWED_GROUPS": json.dumps([]),
+ "X-Langflow-Global-Var-DOCLING_TASK_ID": "",
}
- await add_provider_credentials_to_headers(headers, config, flows_service=self.flows_service, jwt_token=jwt_token)
-
+ await add_provider_credentials_to_headers(
+ headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ )
logger.info(
"[LF] Running URL ingestion flow",
@@ -344,7 +376,6 @@ class LangflowFileService:
crawl_depth=crawl_depth,
connector_type=connector_type,
embedding_model=embedding_model,
- headers=headers,
payload=payload,
)
resp = await clients.langflow_request(
@@ -393,6 +424,7 @@ class LangflowFileService:
last_error: Exception | None = None
from config.paths import get_flows_path
+
flow_file = Path(get_flows_path()) / "openrag_url_mcp.json"
if not flow_file.exists():
raise ValueError(
@@ -510,15 +542,15 @@ class LangflowFileService:
tweaks: Optional[Dict[str, Any]] = None,
settings: Optional[Dict[str, Any]] = None,
jwt_token: Optional[str] = None,
- delete_after_ingest: bool = True,
owner: Optional[str] = None,
owner_name: Optional[str] = None,
owner_email: Optional[str] = None,
- connector_type: Optional[str] = None,
+ connector_type: Optional[str] = None,
) -> Dict[str, Any]:
"""
- Combined upload, ingest, and delete operation.
- First uploads the file, then runs ingestion on it, then optionally deletes the file.
+ Combined Docling upload and Langflow ingest operation.
+ First uploads the file to Docling, then runs ingestion on it via Langflow
+ using the Docling task ID.
Args:
file_tuple: File tuple (filename, content, content_type)
@@ -526,34 +558,40 @@ class LangflowFileService:
tweaks: Optional tweaks for the ingestion flow
settings: Optional UI settings to convert to component tweaks
jwt_token: Optional JWT token for authentication
- delete_after_ingest: Whether to delete the file from Langflow after ingestion (default: True)
Returns:
- Combined result with upload info, ingestion result, and deletion status
+ Combined result with Docling task info and ingestion result
"""
- logger.debug("[LF] Starting combined upload and ingest operation")
+ logger.debug("[LF] Starting Docling-based upload and ingest operation")
+
+ if self.docling_service is None:
+ raise RuntimeError(
+ "DoclingService is not configured. Ensure DOCLING_SERVE_URL is set "
+ "and the service was injected correctly."
+ )
- # Step 1: Upload the file
+ filename, content, _ = file_tuple
+
+ # Step 1: Upload the file to Docling
try:
- upload_result = await self.upload_user_file(file_tuple, jwt_token=jwt_token)
+ task_id = await self.docling_service.upload_to_docling_direct_async(
+ filename, content
+ )
logger.debug(
- "[LF] Upload completed successfully",
+ "[LF] Docling upload completed successfully",
extra={
- "file_id": upload_result.get("id"),
- "file_path": upload_result.get("path"),
+ "task_id": task_id,
+ "filename": filename,
},
)
except Exception as e:
logger.error(
- "[LF] Upload failed during combined operation", extra={"error": str(e)}
+ "[LF] Docling upload failed during combined operation",
+ extra={"error": str(e)},
)
- raise Exception(f"Upload failed: {str(e)}")
+ raise Exception(f"Docling upload failed: {str(e)}")
# Step 2: Prepare for ingestion
- file_path = upload_result.get("path")
- if not file_path:
- raise ValueError("Upload successful but no file path returned")
-
final_tweaks = LangflowFileService.merge_ui_ingest_settings_into_tweaks(
tweaks, settings
)
@@ -563,10 +601,11 @@ class LangflowFileService:
extra={"settings": settings, "tweaks": final_tweaks},
)
- # Step 3: Run ingestion
+ # Step 3: Run ingestion via Langflow
try:
+ total_start_time = time.time()
ingest_result = await self.run_ingestion_flow(
- file_paths=[file_path],
+ file_paths=[], # Files are not uploaded to Langflow FS
file_tuples=[file_tuple],
jwt_token=jwt_token,
session_id=session_id,
@@ -575,54 +614,22 @@ class LangflowFileService:
owner_name=owner_name,
owner_email=owner_email,
connector_type=connector_type,
+ docling_task_id=task_id,
)
- logger.debug("[LF] Ingestion completed successfully")
+ total_duration = round(time.time() - total_start_time, 2)
+ logger.info(f"[LF] Ingestion completed successfully in {total_duration}s")
except Exception as e:
logger.error(
"[LF] Ingestion failed during combined operation",
- extra={"error": str(e), "file_path": file_path},
+ extra={"error": str(e), "filename": filename},
)
+ # Can't cancel Docling task because API for that does not exist
raise
- # Step 4: Delete file from Langflow (optional)
- file_id = upload_result.get("id")
- delete_result = None
- delete_error = None
-
- if delete_after_ingest and file_id:
- try:
- logger.debug(
- "[LF] Deleting file after successful ingestion",
- extra={"file_id": file_id},
- )
- await self.delete_user_file(file_id)
- delete_result = {"status": "deleted", "file_id": file_id}
- logger.debug("[LF] File deleted successfully")
- except Exception as e:
- delete_error = str(e)
- logger.warning(
- "[LF] Failed to delete file after ingestion",
- extra={"error": delete_error, "file_id": file_id},
- )
- delete_result = {
- "status": "delete_failed",
- "file_id": file_id,
- "error": delete_error,
- }
-
# Return combined result
- result = {
+ return {
"status": "success",
- "upload": upload_result,
+ "docling_task_id": task_id,
"ingestion": ingest_result,
- "message": f"File '{upload_result.get('name')}' uploaded and ingested successfully",
+ "message": f"File '{filename}' processed via Docling and ingested successfully",
}
-
- if delete_after_ingest:
- result["deletion"] = delete_result
- if delete_result and delete_result.get("status") == "deleted":
- result["message"] += " and cleaned up"
- elif delete_error:
- result["message"] += f" (cleanup warning: {delete_error})"
-
- return result
diff --git a/src/services/task_service.py b/src/services/task_service.py
index 9d7006b12..85116af0f 100644
--- a/src/services/task_service.py
+++ b/src/services/task_service.py
@@ -26,9 +26,10 @@ class TaskService:
# Cleanup interval in seconds (2 hours)
CLEANUP_INTERVAL_SECONDS = 2 * 60 * 60
- def __init__(self, document_service=None, models_service=None, ingestion_timeout=3600):
+ def __init__(self, document_service=None, models_service=None, ingestion_timeout=3600, docling_service=None):
self.document_service = document_service
self.models_service = models_service
+ self.docling_service = docling_service
self.task_store: dict[
str, dict[str, UploadTask]
] = {} # user_id -> {task_id -> UploadTask}
@@ -122,6 +123,7 @@ class TaskService:
jwt_token=jwt_token,
owner_name=owner_name,
owner_email=owner_email,
+ docling_service=self.docling_service,
)
return await self.create_custom_task(user_id, file_paths, processor)
@@ -138,7 +140,6 @@ class TaskService:
session_id: str = None,
tweaks: dict = None,
settings: dict = None,
- delete_after_ingest: bool = True,
replace_duplicates: bool = False,
connector_type: str = "local",
existing_task_id: str = None,
@@ -157,7 +158,6 @@ class TaskService:
session_id=session_id,
tweaks=tweaks,
settings=settings,
- delete_after_ingest=delete_after_ingest,
replace_duplicates=replace_duplicates,
connector_type=connector_type,
)
diff --git a/src/utils/container_utils.py b/src/utils/container_utils.py
index f54d699cf..4290f62d2 100644
--- a/src/utils/container_utils.py
+++ b/src/utils/container_utils.py
@@ -102,6 +102,69 @@ def get_container_host() -> str | None:
return None
+def _get_gateway_ip_from_route() -> str | None:
+ """Return the default gateway IP visible from the current network namespace.
+
+ Returns:
+ The gateway IP address if discovered, otherwise None.
+ """
+ import socket
+ import struct
+ try:
+ with Path("/proc/net/route").open() as route_table:
+ next(route_table) # Skip header
+ for line in route_table:
+ fields = line.strip().split()
+ min_fields = 3 # interface, destination, gateway
+ if len(fields) >= min_fields and fields[1] == "00000000":
+ gateway_hex = fields[2]
+ gw_int = int(gateway_hex, 16)
+ gateway_ip = socket.inet_ntoa(struct.pack("<L", gw_int))
+ return gateway_ip
+ except (FileNotFoundError, PermissionError, IndexError, ValueError):
+ pass
+
+ return None
+
+
+def determine_docling_host() -> str:
+ """Determine the host address used for docling health checks and service access.
+
+ Works for containers, Docker Desktop hosts, and plain Linux hosts / CI runners.
+
+ Returns:
+ The hostname or IP address to use for docling-serve.
+ """
+ import socket
+ container_type = detect_container_environment()
+
+ # Container-specific env var (e.g. HOST_DOCKER_INTERNAL set explicitly)
+ if container_type:
+ container_host = get_container_host()
+ if container_host:
+ return container_host
+
+ # Try well-known hostnames (resolves on Docker Desktop even outside a
+ # container, and inside Docker/Podman containers with host networking)
+ for hostname in ["host.docker.internal", "host.containers.internal"]:
+ try:
+ socket.getaddrinfo(hostname, None)
+ return hostname
+ except socket.gaierror:
+ pass
+
+ # Container-only fallbacks: gateway IP or bridge IP
+ if container_type:
+ gateway_ip = _get_gateway_ip_from_route()
+ if gateway_ip:
+ return gateway_ip
+
+ fallback_ip = guess_host_ip_for_containers()
+ return fallback_ip
+
+ return "localhost"
+
+
def is_localhost_url(url: str) -> bool:
"""Check if the URL contains a localhost pattern."""
localhost_patterns = ["localhost", "127.0.0.1"]
diff --git a/tests/unit/test_docling_service.py b/tests/unit/test_docling_service.py
new file mode 100644
index 000000000..e23823771
--- /dev/null
+++ b/tests/unit/test_docling_service.py
@@ -0,0 +1,189 @@
+"""
+Unit tests for services/docling_service.py
+Validates async conversion logic, polling behavior, and error handling.
+"""
+
+import pytest
+from unittest.mock import AsyncMock, MagicMock, patch
+import httpx
+from services.docling_service import DoclingService, DoclingServeError
+
+def _make_response(status_code: int, json_data: dict = None) -> MagicMock:
+ """Create a mock HTTP response."""
+ resp = MagicMock(spec=httpx.Response)
+ resp.status_code = status_code
+ resp.json.return_value = json_data or {}
+
+ # Mock raise_for_status to raise if status_code >= 400
+ if status_code >= 400:
+ def raise_status():
+ raise httpx.HTTPStatusError("Error", request=MagicMock(), response=resp)
+ resp.raise_for_status.side_effect = raise_status
+ else:
+ resp.raise_for_status.return_value = None
+
+ return resp
+
+def mock_httpx_client():
+ """Provide a mocked httpx AsyncClient."""
+ client = AsyncMock(spec=httpx.AsyncClient)
+ # Mock __aenter__ and __aexit__ for 'async with client' support
+ client.__aenter__.return_value = client
+ return client
+
+def docling_service(mock_httpx_client):
+ """Provide a DoclingService instance with a mocked client."""
+ return DoclingService(docling_url="http://docling:8000", httpx_client=mock_httpx_client)
+
[email protected](autouse=True)
+def no_sleep():
+ """Patch asyncio.sleep so tests run instantly."""
+ with patch("services.docling_service.asyncio.sleep", new_callable=AsyncMock) as mock_sleep:
+ yield mock_sleep
+
+# ── Polling Logic ───────────────────────────────────────────────────
+
+async def test_poll_result_success(docling_service, mock_httpx_client):
+ """Returns json_content when Docling returns 'success'."""
+ # First call: status poll -> success
+ # Second call: get result -> document data
+ mock_httpx_client.get.side_effect = [
+ _make_response(200, {"task_status": "success"}),
+ _make_response(200, {"document": {"json_content": {"key": "value"}}})
+ ]
+
+ result = await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 10.0)
+ assert result == {"key": "value"}
+ assert mock_httpx_client.get.call_count == 2
+ # Verify URLs
+ calls = mock_httpx_client.get.call_args_list
+ assert calls[0].args[0].endswith("/v1/status/poll/task123")
+ assert calls[1].args[0].endswith("/v1/result/task123")
+
+async def test_poll_result_waits_for_pending(docling_service, mock_httpx_client, no_sleep):
+ """Polls multiple times if status is 'pending' before succeeding."""
+ mock_httpx_client.get.side_effect = [
+ _make_response(200, {"task_status": "pending"}),
+ _make_response(200, {"task_status": "pending"}),
+ _make_response(200, {"task_status": "success"}),
+ _make_response(200, {"document": {"json_content": {"key": "value"}}})
+ ]
+
+ result = await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 10.0)
+ assert result == {"key": "value"}
+ assert mock_httpx_client.get.call_count == 4
+ assert no_sleep.call_count == 2
+
+async def test_poll_result_failure_status(docling_service, mock_httpx_client):
+ """Raises DoclingServeError when status is 'failure'."""
+ mock_httpx_client.get.return_value = _make_response(200, {"task_status": "failure"})
+
+ with pytest.raises(DoclingServeError, match="Docling conversion failed"):
+ await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 10.0)
+
+async def test_poll_result_timeout(docling_service, mock_httpx_client, no_sleep):
+ """Raises TimeoutError when task stays pending beyond timeout."""
+ mock_httpx_client.get.return_value = _make_response(200, {"task_status": "pending"})
+
+ # timeout=2.0, interval=1.0 -> loop runs at T=0, T=1, exits at T=2
+ with pytest.raises(TimeoutError, match="did not complete within"):
+ await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 2.0)
+
+ assert mock_httpx_client.get.call_count == 2
+ assert no_sleep.call_count == 2
+
+async def test_poll_result_missing_content(docling_service, mock_httpx_client):
+ """Raises DoclingServeError if result response is missing json_content."""
+ mock_httpx_client.get.side_effect = [
+ _make_response(200, {"task_status": "success"}),
+ _make_response(200, {"document": {}}) # No json_content
+ ]
+
+ with pytest.raises(DoclingServeError, match="missing document.json_content"):
+ await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 10.0)
+
+async def test_poll_result_http_error(docling_service, mock_httpx_client):
+ """Propagates HTTP errors during polling as DoclingServeError."""
+ mock_httpx_client.get.return_value = _make_response(500)
+
+ with pytest.raises(DoclingServeError, match="Error polling docling status"):
+ await docling_service._poll_result(mock_httpx_client, "task123", 1.0, 10.0)
+
+# ── Upload Logic ────────────────────────────────────────────────────
+
+async def test_upload_success(docling_service, mock_httpx_client):
+ """Returns task_id on successful upload."""
+ mock_httpx_client.post.return_value = _make_response(200, {"task_id": "new-task-id"})
+
+ # Mock config to avoid missing attribute errors during _build_docling_options
+ with patch("services.docling_service.get_openrag_config") as mock_get_config:
+ mock_config = MagicMock()
+ mock_config.knowledge.table_structure = False
+ mock_config.knowledge.ocr = False
+ mock_config.knowledge.picture_descriptions = False
+ mock_get_config.return_value = mock_config
+
+ task_id = await docling_service.upload_to_docling_direct_async("test.pdf", b"data")
+
+ assert task_id == "new-task-id"
+ assert mock_httpx_client.post.call_count == 1
+
+ # Verify boolean serialization (bool -> "true"/"false")
+ _, kwargs = mock_httpx_client.post.call_args
+ data = kwargs.get("data", {})
+ assert data["do_ocr"] == "false"
+
+async def test_upload_http_error(docling_service, mock_httpx_client):
+ """Raises exception if upload returns non-200."""
+ mock_httpx_client.post.return_value = _make_response(400)
+
+ with patch("services.docling_service.get_openrag_config"):
+ with pytest.raises(httpx.HTTPStatusError):
+ await docling_service.upload_to_docling_direct_async("test.pdf", b"data")
+
+# ── Configuration Logic ─────────────────────────────────────────────
+
+def test_build_docling_options_toggles(docling_service):
+ """Correctly maps OpenRAG config to Docling options."""
+ mock_config = MagicMock()
+ mock_config.knowledge.table_structure = True
+ mock_config.knowledge.ocr = True
+ mock_config.knowledge.picture_descriptions = False
+
+ with patch("services.docling_service.get_openrag_config", return_value=mock_config):
+ options = docling_service._build_docling_options()
+
+ assert options["do_table_structure"] is True
+ assert options["do_ocr"] is True
+ assert options["do_picture_description"] is False
+ assert options["to_formats"] == "json"
+
+def test_preset_configs_macos():
+ """Uses ocrmac engine on macOS."""
+ from services.docling_service import get_docling_preset_configs
+ with patch("services.docling_service.platform.system", return_value="Darwin"):
+ preset = get_docling_preset_configs(ocr=True)
+ assert preset["ocr_engine"] == "ocrmac"
+
+def test_preset_configs_linux():
+ """Uses easyocr engine on non-macOS."""
+ from services.docling_service import get_docling_preset_configs
+ with patch("services.docling_service.platform.system", return_value="Linux"):
+ preset = get_docling_preset_configs(ocr=True)
+ assert preset["ocr_engine"] == "easyocr"
+
+def test_init_default_url():
+ """Uses DOCLING_SERVICE_URL from api.docling if not provided."""
+ with patch("api.docling.DOCLING_SERVICE_URL", "http://default:5001"):
+ service = DoclingService()
+ assert service.docling_url == "http://default:5001"