-
Notifications
You must be signed in to change notification settings - Fork 697
UN-3575 [FEAT] Lookup enrichment support for agentic-table prompts (OSS side) #2189
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
+154
−0
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b06ac05
UN-3575 [FEAT] Thread lookup_config into agentic-table dispatch
pk-zipstack a820880
UN-3575 [FEAT] Add shared parallel_map bounded-concurrency util
pk-zipstack 6c9d4c1
Merge remote-tracking branch 'origin/main' into feat/agentic-table-lo…
pk-zipstack e2c922f
UN-3575 [FIX] Address review on parallel_map + dispatch comment
pk-zipstack c463404
UN-3575 [FIX] Let callers preload lookup reference texts (per-row rea…
pk-zipstack f2bf640
UN-3575 [FIX] Guard preload_reference_texts against plugin exceptions
pk-zipstack bbc29ab
Merge branch 'main' into feat/agentic-table-lookup
pk-zipstack fb86083
Merge branch 'main' into feat/agentic-table-lookup
pk-zipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
UN-3575 [FEAT] Add shared parallel_map bounded-concurrency util
Length-preserving bounded-concurrency map used by per-row lookup enrichment (and reusable by other LLM call sites). max_workers=1 == sequential. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Loading branch information
commit a820880f33fcea104baddfa13b8f3d7fbd2bc22c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """Generic bounded-concurrency map for LLM (and other I/O-bound) call sites. | ||
|
|
||
| Runs ``worker(item)`` across a thread pool capped at ``max_workers`` and returns | ||
| results in input order. Unlike the agentic extractor's older ``parallel_page_map`` | ||
| (which drops ``None`` results), this is **length-preserving**: the output list is | ||
| always the same length as the input, so callers can realign results to inputs by | ||
| index — essential for per-row enrichment where row *i* in must map to row *i* out. | ||
|
|
||
| ``max_workers=1`` runs effectively sequentially, so a single knob covers both the | ||
| sequential and bounded-parallel strategies with no code change. | ||
|
|
||
| Rate limiting / retries are intentionally NOT handled here — the SDK LLM client | ||
|
pk-zipstack marked this conversation as resolved.
Outdated
|
||
| already retries transient errors (429/500/503/... and provider "overloaded") | ||
| with backoff and honors ``Retry-After``, so ``max_workers`` concurrent callers | ||
| self-throttle without any extra coordination in this utility. | ||
|
|
||
| NOTE: there is no early-abort. All submitted work runs to completion even if the | ||
|
pk-zipstack marked this conversation as resolved.
pk-zipstack marked this conversation as resolved.
|
||
| caller is later cancelled or times out — in-flight threads cannot be killed. | ||
| Callers that need to stop a doomed run early must gate submission themselves. | ||
| """ | ||
|
|
||
| import logging | ||
| import threading | ||
| from collections.abc import Callable | ||
| from concurrent.futures import ThreadPoolExecutor, as_completed | ||
| from typing import TypeVar | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| T = TypeVar("T") | ||
| R = TypeVar("R") | ||
|
|
||
|
|
||
| def parallel_map( | ||
| items: list[T], | ||
| worker: Callable[[T], R], | ||
| *, | ||
| max_workers: int, | ||
| on_error: Callable[[int, T, Exception], R] | None = None, | ||
| label: str = "", | ||
| ) -> list[R]: | ||
| """Apply ``worker`` to each item with bounded concurrency, order preserved. | ||
|
|
||
| Args: | ||
| items: Inputs to process. An empty list returns ``[]``. | ||
| worker: Called as ``worker(item)`` for each item. | ||
| max_workers: Thread-pool cap. ``<= 1`` runs effectively sequentially. | ||
| on_error: Called as ``on_error(index, item, exception)`` to produce a | ||
| fallback result when a worker raises. If omitted, a failed item's | ||
| slot is left as ``None`` (still counted — length is preserved). | ||
|
pk-zipstack marked this conversation as resolved.
|
||
| label: Optional label for the progress log line. | ||
|
|
||
| Returns: | ||
| A list the SAME LENGTH as ``items``, results in input order. Failed | ||
| items hold either the ``on_error`` fallback or ``None``. | ||
| """ | ||
| if not items: | ||
| return [] | ||
|
|
||
| n = len(items) | ||
| effective_workers = max(max_workers, 1) | ||
| results: list[R | None] = [None] * n | ||
|
pk-zipstack marked this conversation as resolved.
|
||
| log_lock = threading.Lock() | ||
|
|
||
| if effective_workers > 1: | ||
| suffix = f" ({label})" if label else "" | ||
| logger.info( | ||
| "parallel_map: %d items across up to %d workers%s", | ||
| n, | ||
| effective_workers, | ||
| suffix, | ||
| ) | ||
|
|
||
| with ThreadPoolExecutor(max_workers=effective_workers) as executor: | ||
| future_to_idx = { | ||
| executor.submit(worker, item): idx for idx, item in enumerate(items) | ||
| } | ||
|
pk-zipstack marked this conversation as resolved.
|
||
| for future in as_completed(future_to_idx): | ||
| idx = future_to_idx[future] | ||
| try: | ||
| results[idx] = future.result() | ||
| except Exception as e: | ||
| with log_lock: | ||
| logger.error( | ||
|
Check failure on line 84 in workers/shared/parallel_map.py
|
||
|
pk-zipstack marked this conversation as resolved.
Outdated
|
||
| "parallel_map: item %d/%d failed: %s", | ||
|
pk-zipstack marked this conversation as resolved.
Outdated
|
||
| idx + 1, | ||
| n, | ||
| e, | ||
| exc_info=True, | ||
| ) | ||
| if on_error is not None: | ||
|
pk-zipstack marked this conversation as resolved.
|
||
| results[idx] = on_error(idx, items[idx], e) | ||
|
|
||
| return results | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.