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

Function fetchEmbedding

src/core/embeddings.ts:282–308  ·  view source on GitHub ↗
(input: string | string[])

Source from the content-addressed store, hash-verified

280}
281
282export async function fetchEmbedding(input: string | string[]): Promise<number[][]> {
283 const inputs = Array.isArray(input) ? input : [input];
284 if (inputs.length === 0) return [];
285
286 const chunkedInputs = inputs.map(splitEmbeddingInput);
287 const flattenedInputs = chunkedInputs.flat();
288 const batchSize = getEmbeddingBatchSize();
289 const flattenedEmbeddings: number[][] = [];
290
291 for (let i = 0; i < flattenedInputs.length; i += batchSize) {
292 const batch = flattenedInputs.slice(i, i + batchSize);
293 flattenedEmbeddings.push(...await embedBatchAdaptive(batch));
294 }
295
296 const embeddings: number[][] = [];
297 let offset = 0;
298 for (const chunks of chunkedInputs) {
299 const vectors = flattenedEmbeddings.slice(offset, offset + chunks.length);
300 if (vectors.length !== chunks.length) {
301 throw new Error(`Merged embedding size mismatch: expected ${chunks.length}, got ${vectors.length}`);
302 }
303 embeddings.push(mergeEmbeddingVectors(vectors, chunks.map((chunk) => chunk.length)));
304 offset += chunks.length;
305 }
306
307 return embeddings;
308}
309
310function hashContent(text: string): string {
311 let h = 0;

Callers 12

fetchEmbeddingsFunction · 0.85
buildIdentifierIndexFunction · 0.85
rankCallSitesFunction · 0.85
semanticIdentifierSearchFunction · 0.85
upsertNodeFunction · 0.85
searchGraphFunction · 0.85
indexMethod · 0.85
searchMethod · 0.85

Calls 3

getEmbeddingBatchSizeFunction · 0.85
embedBatchAdaptiveFunction · 0.85
mergeEmbeddingVectorsFunction · 0.85

Tested by

no test coverage detected