Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-planes-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Support custom embed dimensions for Ollama provider
4 changes: 4 additions & 0 deletions src/services/code-index/embedders/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand All @@ -34,6 +36,7 @@ export class CodeIndexOllamaEmbedder implements IEmbedder {
*/
async createEmbeddings(texts: string[], model?: string): Promise<EmbeddingResponse> {
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
Expand Down Expand Up @@ -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,
})
Expand Down
1 change: 1 addition & 0 deletions src/services/code-index/service-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading