refactor: Concurrent batch processing

This commit is contained in:
2026-07-03 13:07:41 +05:30
parent 61d78af5c1
commit 1902cd2d03
2 changed files with 26 additions and 6 deletions

View File

@@ -362,14 +362,34 @@ async def _process_job_async(job_id: str, transactions: List[Dict[str, Any]]):
)
try:
client = genai.Client(api_key=api_key)
# Batch transactions in chunks of 50
# Split into batches of 50 and fire all concurrently
batch_size = 50
for i in range(0, len(uncategorized_txns), batch_size):
batch = uncategorized_txns[i : i + batch_size]
batch_results = await classify_transactions_batch(
client, batch, allowed_categories
batches = [
uncategorized_txns[i : i + batch_size]
for i in range(0, len(uncategorized_txns), batch_size)
]
logger.info(
f"Dispatching {len(batches)} classification batch(es) concurrently..."
)
with benchmark(
"LLM Concurrent Batch Classification (all batches)"
):
batch_results_list = await asyncio.gather(
*[
classify_transactions_batch(
client, batch, allowed_categories
)
for batch in batches
],
return_exceptions=True,
)
llm_results.update(batch_results)
for batch_result in batch_results_list:
if isinstance(batch_result, Exception):
logger.error(
f"A classification batch failed: {batch_result}"
)
else:
llm_results.update(batch_result)
except Exception as e:
logger.error(
f"Failed to initialize GenAI Client or classify: {e}"

View File