feat(file-processors): add async/fallback support to docling-serve#6014
Conversation
e4c4cdd to
c39f590
Compare
Docling team confirmed async endpoints work on both local and SaaS. Default to async mode with automatic fallback to sync on failure. This eliminates timeout issues under load and enables compatibility with IBM Docling SaaS async-only endpoints. - Added async submit/poll/result workflow methods - Implemented automatic fallback from async to sync - Added unit tests for async mode and fallback behavior Will need rebase after ogx-ai#5627 merges. Signed-off-by: Sahana Sreeram <[email protected]>
…g-serve using docling-slim's new asyncio capabilities. Adds support for async endpoints using AsyncDoclingServiceClient with automatic fallback to sync. Updates base_url to remove /v1 suffix (SDK adds it internally). Adds unit tests for async mode. Signed-off-by: Sahana Sreeram <[email protected]>
cafe291 to
2c26574
Compare
Fix api_key type (str not Optional), remove unsupported chunking_max_tokens, fix ChunkedDocumentResultItem handling (object not dict). Signed-off-by: Sahana Sreeram <[email protected]>
Signed-off-by: Sahana Sreeram <[email protected]>
|
This pull request has merge conflicts that must be resolved before it can be merged. @sahana-sreeram please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork |
…g-serve Integrate AsyncDoclingServiceClient to support async endpoints for both IBM Docling SaaS and local docling-serve. - Use AsyncDoclingServiceClient for async conversion - Handle dual response formats (presigned URLs for SaaS, direct documents for local) - Block chunking for IBM SaaS with clear error (not supported) - Require docling-slim[service-client]>=2.103.0 This enables IBM Docling SaaS, which only provides async endpoints. Signed-off-by: Sahana Sreeram <[email protected]>
…M SaaS chunking Fixed URL matching by catching HTTP 404/405 responses instead of checking for 'ibm.com' in URL. This resolves the CodeQL security warning and makes the code self-correcting if IBM adds chunking support later. Signed-off-by: Sahana Sreeram <[email protected]>
| mode: str = Field( | ||
| default="async", | ||
| description=( | ||
| "API mode: 'async' (use asynchronous submit/poll endpoints, recommended for both local and SaaS), " | ||
| "'sync' (use synchronous endpoints, fallback option), or 'auto' (detect server capabilities)" | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Use Literal["async", "sync", "auto"] to get Pydantic validation at config load time
| sdk_module="docling.service_client", | ||
| ) | ||
| conversion_method = "async" | ||
| except Exception as e: |
There was a problem hiding this comment.
This catches all exceptions including InvalidParameterError, which _convert_and_chunk_async raises when IBM SaaS returns 404/405 for unsupported chunking. That user-facing error gets silently swallowed, a redundant sync request hits the same 404/405, and only then does the error reach the caller.
Also, mode='async' and mode='auto' behave identically here — both fall back to sync on any failure. If a user sets mode='async', they probably don't expect a silent sync fallback.
Consider narrowing the catch and only falling back in auto mode:
except (httpx.ConnectError, httpx.TimeoutException) as e:
if self.config.mode == "auto":
log.warning("Async failed, falling back to sync", error=str(e))
chunks = None
else:
raise
There was a problem hiding this comment.
Fixed in 0d54af1, now using your exact code suggestion which:
- Catches network errors
(httpx.ConnectError, httpx.TimeoutException) - In
automode: falls back to sync on network errors. Inasyncmode: raises immediately InvalidParameterErrorraised up immediately (without sync retry)
Add Literal type validation, narrow exception handling to network errors only, and only fallback in auto mode. Signed-off-by: Sahana Sreeram <[email protected]>
Signed-off-by: Sahana Sreeram <[email protected]>
|
@alinaryan pls ping me when you've approved this |
alinaryan
left a comment
There was a problem hiding this comment.
LGTM. I have one nit, but non-blocking
| ) | ||
|
|
||
| @pytest.fixture | ||
| def config_async(self) -> DoclingServeFileProcessorConfig: |
There was a problem hiding this comment.
test_fallback_from_async_to_sync takes config_async in its signature but creates its own config_auto inside the body. The fixture is instantiated but never used.
There was a problem hiding this comment.
fixed (2c222f6) - the parameter was left over from earlier testing. Also renamed the test to test_auto_mode_falls_back_to_sync to be more representative of its behavior after review code fixes
Signed-off-by: Sahana Sreeram <[email protected]>
…oclingServiceClient Signed-off-by: Sahana Sreeram <[email protected]>
What does this PR do?
Integrates AsyncDoclingServiceClient from docling-slim to enable async endpoints for both IBM Docling SaaS and local docling-serve. This enables IBM Docling SaaS and improves performance for local deployments.
Problem: Before this PR, docling-serve provider had critical limitations:
Solution:
This solution is lightweight and requires no infrastructure changes. Users can:
base_urlandapi_keyin their configTest Plan
Validated async functionality using both unit tests and integration testing against a local Docling Serve instance.
Unit Tests
23 passed in 1.49s
Unit Tests New tests added: tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_ibm_saas_blocks_chunking_with_clear_error PASSED [ 91%] tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_ibm_saas_allows_conversion_without_chunking PASSED [ 95%] tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_local_docker_allows_chunking PASSED [100%] ======================== 23 passed, 1 warning in 1.49s =========================Integration Testing
Tested against local docling-serve Docker (v1.24.0) and IBM's Docling SaaS (both in async mode) with real 37KB PDF (
ogx_and_models.pdf):Conversion works as expected for IBM SaaS; Local Docling-Serve can run both convert and chunk methods. Confirms API endpoints are hit correctly.
Test Setup