MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / embedSingleAdaptive

Function embedSingleAdaptive

src/core/embeddings.ts:207–226  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

205}
206
207async 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
228async function embedBatchAdaptive(batch: string[]): Promise<number[][]> {
229 try {

Callers 1

embedBatchAdaptiveFunction · 0.85

Calls 3

callProviderEmbedFunction · 0.85
isContextLengthErrorFunction · 0.85
shrinkEmbeddingInputFunction · 0.85

Tested by

no test coverage detected