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

Function mockEmbedding

test/main/memory-graph.test.mjs:29–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27let embedCounter = 0;
28
29function mockEmbedding() {
30 embedCounter = 0;
31 const original = Ollama.prototype.embed;
32 Ollama.prototype.embed = async function ({ input }) {
33 const batch = Array.isArray(input) ? input : [input];
34 return {
35 embeddings: batch.map((text) => {
36 embedCounter++;
37 const vec = new Array(64).fill(0);
38 for (let i = 0; i < Math.min(text.length, 64); i++) {
39 vec[i] = (text.charCodeAt(i) % 100) / 100;
40 }
41 const norm = Math.sqrt(vec.reduce((s, v) => s + v * v, 0));
42 return norm > 0 ? vec.map((v) => v / norm) : vec;
43 }),
44 };
45 };
46 return () => { Ollama.prototype.embed = original; };
47}
48
49before(async () => {
50 await rm(FIXTURE, { recursive: true, force: true });

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected