diff --git a/.changeset/old-planes-start.md b/.changeset/old-planes-start.md new file mode 100644 index 00000000000..79f1ba81970 --- /dev/null +++ b/.changeset/old-planes-start.md @@ -0,0 +1,5 @@ +--- +"kilo-code": patch +--- + +Support custom embed dimensions for Ollama provider diff --git a/src/services/code-index/embedders/ollama.ts b/src/services/code-index/embedders/ollama.ts index 82fc32c7537..01ca9d90026 100644 --- a/src/services/code-index/embedders/ollama.ts +++ b/src/services/code-index/embedders/ollama.ts @@ -14,6 +14,7 @@ import { getApiRequestTimeout } from "../../../api/providers/utils/timeout-confi export class CodeIndexOllamaEmbedder implements IEmbedder { private readonly baseUrl: string private readonly defaultModelId: string + private readonly dimensions?: number // kilocode_change constructor(options: ApiHandlerOptions) { // Ensure ollamaBaseUrl and ollamaModelId exist on ApiHandlerOptions or add defaults @@ -24,6 +25,7 @@ export class CodeIndexOllamaEmbedder implements IEmbedder { this.baseUrl = baseUrl this.defaultModelId = options.ollamaModelId || "nomic-embed-text:latest" + this.dimensions = options.ollamaNumCtx // kilocode_change } /** @@ -34,6 +36,7 @@ export class CodeIndexOllamaEmbedder implements IEmbedder { */ async createEmbeddings(texts: string[], model?: string): Promise { const modelToUse = model || this.defaultModelId + const dimensions = this.dimensions // kilocode_change const url = `${this.baseUrl}/api/embed` // Endpoint as specified // Apply model-specific query prefix if required @@ -80,6 +83,7 @@ export class CodeIndexOllamaEmbedder implements IEmbedder { body: JSON.stringify({ model: modelToUse, input: processedTexts, // Using 'input' as requested + dimensions, // kilocode_change }), signal: controller.signal, }) diff --git a/src/services/code-index/service-factory.ts b/src/services/code-index/service-factory.ts index 38838053dda..a2a44472af8 100644 --- a/src/services/code-index/service-factory.ts +++ b/src/services/code-index/service-factory.ts @@ -65,6 +65,7 @@ export class CodeIndexServiceFactory { return new CodeIndexOllamaEmbedder({ ...config.ollamaOptions, ollamaModelId: config.modelId, + ollamaNumCtx: config.modelDimension, // kilocode_change }) } else if (provider === "openai-compatible") { if (!config.openAiCompatibleOptions?.baseUrl || !config.openAiCompatibleOptions?.apiKey) {