import { IEmbeddings } from "../../interfaces/IEmbedding"; import { OptionsEmbeddingService } from "../../types/embedding"; import { Ollama } from 'ollama' import { Logger } from "../../utils/Logger"; export class OllamaEmbeddingService implements IEmbeddings { client: Ollama model: string constructor(options?: OptionsEmbeddingService) { this.client = new Ollama({ host: options?.baseUrl || process.env.OLLAMA_HOST || "http://127.0.0.1:11434", }) this.model = options?.model || process.env.OLLAMA_EMBEDDING_MODEL || "milkey/m3e:latest" Logger.debug("ollama eb model", this.model) } async getEmbeddings(text: string | string[]): Promise { const prompts = Array.isArray(text) ? text : [text] const results: number[][] = [] for (let index = 0; index < prompts.length; index++) { const prompt = prompts[index]; const result = await this.client.embeddings({ model: this.model, prompt: prompt, }) results.push(result.embedding) } return results } }