Skip to content

Commit f20d907

Browse files
added Unstructured fallback to auto provider. Wire remote::unstructured-api into the auto file processor as an optional fallback. When an unstructured api key is provided by the user in config, the auto provider will route supported file formats to Unstructured before checking for/returning a 422 error. This provides 65+ additional format support (including EML, DOC, MSG) when users opt-in with an API key, while maintaining priority routing to pypdf for pdfs and markitdown for office/image/audio. Tested with .eml file, successfully routes to Unstructured. pypdf and markitdown routing unchanged.
1 parent 9c689f7 commit f20d907

7 files changed

Lines changed: 36 additions & 4 deletions

File tree

docs/docs/providers/file_processors/inline_auto.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Composite file processor that automatically dispatches to the appropriate backen
1818
| `default_chunk_overlap_tokens` | `int` | No | 400 | Default chunk overlap in tokens when chunking_strategy type is 'auto' |
1919
| `extract_metadata` | `bool` | No | True | Whether to extract PDF metadata (title, author, etc.) |
2020
| `clean_text` | `bool` | No | True | Whether to clean extracted text (remove extra whitespace, normalize line breaks) |
21+
| `unstructured_api_key` | `SecretStr \| None` | No | | Optional Unstructured.io API key. If provided, uses Unstructured as fallback for unsupported file types. |
2122

2223
## Sample Configuration
2324

2425
```yaml
25-
{}
26+
unstructured_api_key: ${env.UNSTRUCTURED_API_KEY}
2627
```

src/ogx/distributions/ci-tests/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ providers:
193193
file_processors:
194194
- provider_id: auto
195195
provider_type: inline::auto
196+
config:
197+
unstructured_api_key: ${env.UNSTRUCTURED_API_KEY}
196198
interactions:
197199
- provider_id: builtin
198200
provider_type: inline::builtin

src/ogx/distributions/ci-tests/run-with-postgres-store.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ providers:
193193
file_processors:
194194
- provider_id: auto
195195
provider_type: inline::auto
196+
config:
197+
unstructured_api_key: ${env.UNSTRUCTURED_API_KEY}
196198
interactions:
197199
- provider_id: builtin
198200
provider_type: inline::builtin

src/ogx/distributions/starter/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ providers:
187187
file_processors:
188188
- provider_id: auto
189189
provider_type: inline::auto
190+
config:
191+
unstructured_api_key: ${env.UNSTRUCTURED_API_KEY}
190192
interactions:
191193
- provider_id: builtin
192194
provider_type: inline::builtin

src/ogx/distributions/starter/run-with-postgres-store.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ providers:
187187
file_processors:
188188
- provider_id: auto
189189
provider_type: inline::auto
190+
config:
191+
unstructured_api_key: ${env.UNSTRUCTURED_API_KEY}
190192
interactions:
191193
- provider_id: builtin
192194
provider_type: inline::builtin

src/ogx/providers/inline/file_processor/auto/auto.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from ogx.providers.inline.file_processor.markitdown.markitdown_processor import MarkItDownFileProcessor
1313
from ogx.providers.inline.file_processor.pypdf.config import PyPDFFileProcessorConfig
1414
from ogx.providers.inline.file_processor.pypdf.pypdf import PyPDFFileProcessor
15+
from ogx.providers.remote.file_processor.unstructured_api.config import UnstructuredApiFileProcessorConfig
16+
from ogx.providers.remote.file_processor.unstructured_api.unstructured_api import UnstructuredApiFileProcessor
1517
from ogx_api.file_processors import ProcessFileRequest, ProcessFileResponse
1618
from ogx_api.files import RetrieveFileRequest
1719

@@ -50,7 +52,8 @@
5052
SUPPORTED_DESCRIPTION = (
5153
"PDF, text (txt, csv, md, json, xml, html, code), "
5254
"office (DOCX, PPTX, XLSX, XLS, DOC, PPT, RTF), "
53-
"EPUB, RSS, ZIP, images, and audio"
55+
"EPUB, RSS, ZIP, images, audio, "
56+
"and additional formats via Unstructured.io (if user API key provided)"
5457
)
5558

5659

@@ -80,6 +83,15 @@ def __init__(self, config: AutoFileProcessorConfig, files_api) -> None:
8083
)
8184
self.markitdown = MarkItDownFileProcessor(markitdown_config, files_api)
8285

86+
# Initialize Unstructured if API key is provided
87+
self.unstructured = None
88+
if config.unstructured_api_key:
89+
unstructured_config = UnstructuredApiFileProcessorConfig(
90+
api_key=config.unstructured_api_key,
91+
default_chunk_size_tokens=config.default_chunk_size_tokens,
92+
)
93+
self.unstructured = UnstructuredApiFileProcessor(unstructured_config, files_api)
94+
8395
async def process_file(
8496
self,
8597
request: ProcessFileRequest,
@@ -100,6 +112,10 @@ async def process_file(
100112
if mime_type in MARKITDOWN_MIME_TYPES:
101113
return await self.markitdown.process_file(request=request, file=file)
102114

115+
# Try Unstructured as fallback for unsupported types
116+
if self.unstructured:
117+
return await self.unstructured.process_file(request=request, file=file)
118+
103119
raise HTTPException(
104120
status_code=422,
105121
detail=f"File type '{mime_type or 'unknown'}' is not supported. Supported types: {SUPPORTED_DESCRIPTION}.",

src/ogx/providers/inline/file_processor/auto/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from typing import Any
88

9-
from pydantic import BaseModel, Field
9+
from pydantic import BaseModel, Field, SecretStr
1010

1111
from ogx_api.vector_io import VectorStoreChunkingStrategyStaticConfig
1212

@@ -39,6 +39,13 @@ class AutoFileProcessorConfig(BaseModel):
3939
default=True, description="Whether to clean extracted text (remove extra whitespace, normalize line breaks)"
4040
)
4141

42+
unstructured_api_key: SecretStr | None = Field(
43+
default=None,
44+
description="Optional Unstructured.io API key. If provided, uses Unstructured as fallback for unsupported file types.",
45+
)
46+
4247
@classmethod
4348
def sample_run_config(cls, **kwargs: Any) -> dict[str, Any]:
44-
return {}
49+
return {
50+
"unstructured_api_key": "${env.UNSTRUCTURED_API_KEY}",
51+
}

0 commit comments

Comments
 (0)