Skip to content

Add OCR_AGENT_CACHE_SIZE environment variable #4066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.18.10

### Enhancements

### Features
- **Add OCR_AGENT_CACHE_SIZE environment variable** Added configurable cache size for OCR agents to control memory usage.

### Fixes

## 0.18.10-dev0

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.18.10-dev0" # pragma: no cover
__version__ = "0.18.10" # pragma: no cover
5 changes: 5 additions & 0 deletions unstructured/partition/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def OCR_AGENT(self) -> str:
"""OCR Agent to use"""
return self._get_string("OCR_AGENT", OCR_AGENT_TESSERACT)

@property
def OCR_AGENT_CACHE_SIZE(self) -> int:
"""Maximum number of OCR agents to cache per process"""
return self._get_int("OCR_AGENT_CACHE_SIZE", 1)

@property
def EXTRACT_IMAGE_BLOCK_CROP_HORIZONTAL_PAD(self) -> int:
"""extra image block content to add around an identified element(`Image`, `Table`) region
Expand Down
2 changes: 1 addition & 1 deletion unstructured/partition/utils/ocr_models/ocr_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_agent(cls, language: str) -> OCRAgent:
return cls.get_instance(ocr_agent_cls_qname, language)

@staticmethod
@functools.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=env_config.OCR_AGENT_CACHE_SIZE)
def get_instance(ocr_agent_module: str, language: str) -> "OCRAgent":
module_name, class_name = ocr_agent_module.rsplit(".", 1)
if module_name not in OCR_AGENT_MODULES_WHITELIST:
Expand Down