Skip to content

feat(indexing): support 'auto' dimension with runtime detection fallback#11609

Open
rrauenza wants to merge 2 commits into
Kilo-Org:mainfrom
rrauenza:feat/auto-detect-embedding-dimension
Open

feat(indexing): support 'auto' dimension with runtime detection fallback#11609
rrauenza wants to merge 2 commits into
Kilo-Org:mainfrom
rrauenza:feat/auto-detect-embedding-dimension

Conversation

@rrauenza

@rrauenza rrauenza commented Jun 23, 2026

Copy link
Copy Markdown

<I'm going to take this out of draft to see if it triggers CI - I haven't successfully pulled the plugin into my vscode yet.)

Issue

Fixes # #11500

Context

We can autodetect when unset the number of dimensions that an embedder has by passing in a sample embedding and seeing how many dimensions we get back.

Implementation

I decided not to add an enum of 'auto' for the dimensions type in the config. If you want that, let me know. The datatype remains null | undefined | number. The null / undefined were already being treated as 'use default'.

If config.modelDimension is not defined, we create a temporary embedder and do a query to get the dimensions. Then we explicitly pass that as an override into CreateEmbedder. Otherwise CreateEmbedder just uses it's default, config.ModelDimension.

Screenshots / Video

n/a

How to Test

Manual/local verification

Unit tests added - I don't have access to any of the api key'ed endpoints.

$ cd packages/kilo-indexing && bun test --timeout 30000 ./test/kilocode/indexing/service-factory.test.ts
bun test v1.3.13 (bf2e2cec)

test/kilocode/indexing/service-factory.test.ts:
✓ CodeIndexServiceFactory > creates an OpenAI-compatible embedder without an API key [1.43ms]
✓ CodeIndexServiceFactory > uses default LanceDB directory when config is unset [0.58ms]
✓ CodeIndexServiceFactory > uses explicit LanceDB directory when configured [0.11ms]
✓ CodeIndexServiceFactory > passes configured dimension to Ollama embed requests [3.62ms]
✓ CodeIndexServiceFactory > leaves Ollama dimensions unset when no override is configured [0.28ms]
✓ CodeIndexServiceFactory > passes configured dimension to OpenRouter embed requests [1.95ms]
✓ CodeIndexServiceFactory > creates vector store for OpenRouter Gemini embedding preview [0.13ms]
✓ CodeIndexServiceFactory > uses configured dimension before static model metadata for vector stores [0.09ms]
✓ CodeIndexServiceFactory > creates Kilo embedder with Cloud-provided model [1.56ms]
✓ CodeIndexServiceFactory > uses registry default for known model without explicit dimension [0.63ms]
✓ CodeIndexServiceFactory > uses explicit dimension over registry default [0.20ms]
✓ CodeIndexServiceFactory > detects dimension for unknown model without explicit dimension [0.49ms]

12 pass
0 fail
23 expect() calls
Ran 12 tests across 1 file. [373.00ms]

(I haven't figured out a way to get a self built plugin into vscode yet.)

Reviewer test steps

  • Set to an embedder with a default (gemini)
  • Set to a custom embedder with no default and see if it works or complains

run unit tests (which will be in CI automatically for this PR, I believe)

Blocked checks and substitute verification

Checklist

  • [x ] Issue linked above, or exception explained
  • [ x] Tests/verification described
  • [ n/a] Screenshots/video included for visual changes, or marked N/A
  • [ ?] Changeset considered for user-facing changes
  • [ x] I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

@rrauenza rrauenza force-pushed the feat/auto-detect-embedding-dimension branch 2 times, most recently from 44a57fc to f05ec41 Compare June 23, 2026 23:52
@rrauenza rrauenza force-pushed the feat/auto-detect-embedding-dimension branch from f05ec41 to c5880ee Compare June 24, 2026 00:07
@rrauenza rrauenza marked this pull request as ready for review June 24, 2026 00:25
effectiveDimension = registryDimension
} else {
const detectionEmbedder = this.createEmbedder()
effectiveDimension = await this.detectEmbeddingDimension(detectionEmbedder)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Runtime detection still does not cover baseline-backed worktrees

This fallback runs after CodeIndexManager._recreateServices() has already called createBaseline(factory), and createBaseline() still builds its vector store with no detected override. For an unknown custom model in a worktree session, initialization will still fail with Cannot determine vector dimension... before execution ever reaches this branch.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

effectiveDimension = await this.detectEmbeddingDimension(detectionEmbedder)
}

const embedder = this.createEmbedder(effectiveDimension)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Detected dimensions are not applied to openai-compatible embeddings

effectiveDimension is passed into createEmbedder() here, but the openai-compatible branch above still constructs OpenAICompatibleEmbedder without its dimensions option. That means the vector store is created at the detected size while later embedding requests still use the endpoint's default size, which will trip a vector-length mismatch as soon as indexing starts for unknown custom models.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-indexing/src/indexing/service-factory.ts 294 Runtime detection still does not cover baseline-backed worktrees.
packages/kilo-indexing/src/indexing/service-factory.ts 297 Detected dimensions are not applied to openai-compatible embeddings.
Files Reviewed (3 files)
  • packages/kilo-indexing/src/indexing/manager.ts - 0 issues
  • packages/kilo-indexing/src/indexing/service-factory.ts - 2 issues
  • packages/kilo-indexing/test/kilocode/indexing/service-factory.test.ts - 0 issues

Reviewed by gpt-5.4-20260305 · Input: 101.3K · Output: 12.3K · Cached: 594.2K

Review guidance: REVIEW.md from base branch main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant