diff --git a/packages/plugin-node/src/services/llama.ts b/packages/plugin-node/src/services/llama.ts index 7a747136c0d..f71b6626388 100644 --- a/packages/plugin-node/src/services/llama.ts +++ b/packages/plugin-node/src/services/llama.ts @@ -486,9 +486,32 @@ export class LlamaService extends Service { throw new Error("Model not initialized. Call initialize() first."); } - const embeddingContext = await this.model.createEmbeddingContext(); - const embedding = await embeddingContext.getEmbeddingFor(input); - return embedding?.vector ? [...embedding.vector] : undefined; + const ollamaModel = process.env.OLLAMA_MODEL; + const ollamaUrl = + process.env.OLLAMA_SERVER_URL || "http://localhost:11434"; + const embeddingModel = + process.env.OLLAMA_EMBEDDING_MODEL || "mxbai-embed-large"; + elizaLogger.info( + `Using Ollama API for embeddings with model ${embeddingModel} (base: ${ollamaModel})` + ); + + const response = await fetch(`${ollamaUrl}/api/embeddings`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + input: input, + model: embeddingModel, + }), + }); + + if (!response.ok) { + throw new Error(`Failed to get embedding: ${response.statusText}`); + } + + const embedding = await response.json(); + return embedding.vector; } }