1+ import { resolveSafeTimeoutDelayMs } from "../../../gateway-client/src/timeouts.js" ;
12import { splitBatchRequests } from "./batch-utils.js" ;
23import { runWithConcurrency } from "./internal.js" ;
34
@@ -9,6 +10,20 @@ export type EmbeddingBatchExecutionParams = {
910 debug ?: ( message : string , data ?: Record < string , unknown > ) => void ;
1011} ;
1112
13+ function resolveEmbeddingBatchPollIntervalMs ( params : {
14+ pollIntervalMs : number ;
15+ timeoutMs : number ;
16+ } ) : number {
17+ const safePollIntervalMs = resolveSafeTimeoutDelayMs ( params . pollIntervalMs ) ;
18+ const safeTimeoutMs =
19+ typeof params . timeoutMs === "number" &&
20+ Number . isFinite ( params . timeoutMs ) &&
21+ params . timeoutMs > 0
22+ ? resolveSafeTimeoutDelayMs ( params . timeoutMs )
23+ : safePollIntervalMs ;
24+ return Math . min ( safePollIntervalMs , safeTimeoutMs ) ;
25+ }
26+
1227export async function runEmbeddingBatchGroups < TRequest > ( params : {
1328 requests : TRequest [ ] ;
1429 maxRequests : number ;
@@ -23,23 +38,33 @@ export async function runEmbeddingBatchGroups<TRequest>(params: {
2338 groupIndex : number ;
2439 groups : number ;
2540 byCustomId : Map < string , number [ ] > ;
41+ pollIntervalMs : number ;
42+ timeoutMs : number ;
2643 } ) => Promise < void > ;
2744} ) : Promise < Map < string , number [ ] > > {
2845 if ( params . requests . length === 0 ) {
2946 return new Map ( ) ;
3047 }
3148 const groups = splitBatchRequests ( params . requests , params . maxRequests ) ;
3249 const byCustomId = new Map < string , number [ ] > ( ) ;
50+ const pollIntervalMs = resolveEmbeddingBatchPollIntervalMs ( params ) ;
3351 const tasks = groups . map ( ( group , groupIndex ) => async ( ) => {
34- await params . runGroup ( { group, groupIndex, groups : groups . length , byCustomId } ) ;
52+ await params . runGroup ( {
53+ group,
54+ groupIndex,
55+ groups : groups . length ,
56+ byCustomId,
57+ pollIntervalMs,
58+ timeoutMs : params . timeoutMs ,
59+ } ) ;
3560 } ) ;
3661
3762 params . debug ?.( params . debugLabel , {
3863 requests : params . requests . length ,
3964 groups : groups . length ,
4065 wait : params . wait ,
4166 concurrency : params . concurrency ,
42- pollIntervalMs : params . pollIntervalMs ,
67+ pollIntervalMs,
4368 timeoutMs : params . timeoutMs ,
4469 } ) ;
4570
@@ -51,11 +76,12 @@ export function buildEmbeddingBatchGroupOptions<TRequest>(
5176 params : { requests : TRequest [ ] } & EmbeddingBatchExecutionParams ,
5277 options : { maxRequests : number ; debugLabel : string } ,
5378) {
79+ const pollIntervalMs = resolveEmbeddingBatchPollIntervalMs ( params ) ;
5480 return {
5581 requests : params . requests ,
5682 maxRequests : options . maxRequests ,
5783 wait : params . wait ,
58- pollIntervalMs : params . pollIntervalMs ,
84+ pollIntervalMs,
5985 timeoutMs : params . timeoutMs ,
6086 concurrency : params . concurrency ,
6187 debug : params . debug ,
0 commit comments