(input: string)
| 205 | } |
| 206 | |
| 207 | async function embedSingleAdaptive(input: string): Promise<number[]> { |
| 208 | let candidate = input; |
| 209 | |
| 210 | for (let attempt = 0; attempt <= MAX_SINGLE_INPUT_RETRIES; attempt++) { |
| 211 | try { |
| 212 | const timeoutCtrl = AbortSignal.timeout(EMBED_TIMEOUT_MS); |
| 213 | const signal = AbortSignal.any([embedAbortController.signal, timeoutCtrl]); |
| 214 | const embeddings = await callProviderEmbed([candidate], signal); |
| 215 | if (!embeddings[0]) throw new Error("Missing embedding vector in response"); |
| 216 | return embeddings[0]; |
| 217 | } catch (error) { |
| 218 | if (!isContextLengthError(error)) throw error; |
| 219 | const nextCandidate = shrinkEmbeddingInput(candidate); |
| 220 | if (nextCandidate.length === candidate.length) throw error; |
| 221 | candidate = nextCandidate; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | throw new Error("Unable to embed oversized input after adaptive retries"); |
| 226 | } |
| 227 | |
| 228 | async function embedBatchAdaptive(batch: string[]): Promise<number[][]> { |
| 229 | try { |
no test coverage detected