MCPcopy Create free account
hub / github.com/braintrustdata/bash-agent-evals / loadEmbeddings

Function loadEmbeddings

src/tools/embedding-tools.ts:29–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27let embeddingsData: { index: EmbeddingIndex; embeddings: Float32Array } | null = null;
28
29function loadEmbeddings(): { index: EmbeddingIndex; embeddings: Float32Array } {
30 if (embeddingsData) return embeddingsData;
31
32 if (!existsSync(INDEX_PATH) || !existsSync(EMBEDDINGS_PATH)) {
33 throw new Error('Embeddings not found. Run "pnpm embed" first to generate them.');
34 }
35
36 console.log('Loading pre-computed embeddings...');
37 const index: EmbeddingIndex = JSON.parse(readFileSync(INDEX_PATH, 'utf-8'));
38 const buffer = readFileSync(EMBEDDINGS_PATH);
39 const embeddings = new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
40
41 embeddingsData = { index, embeddings };
42 console.log(`Loaded ${index.count} embeddings (${(buffer.length / 1024 / 1024).toFixed(1)} MB)`);
43
44 return embeddingsData;
45}
46
47// Cache for query embeddings
48const queryCache = new Map<string, number[]>();

Callers 1

embedding-tools.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected