@javierkaiser/opencode-indexing 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +157 -2
- package/README.md +192 -21
- package/index.ts +133 -17
- package/install.mjs +229 -128
- package/install.ps1 +7 -1
- package/install.sh +1 -1
- package/package.json +6 -2
- package/src/config.ts +1 -1
- package/src/embedder.ts +339 -99
- package/src/import.ts +30 -9
- package/src/indexer.ts +23 -1
- package/src/registry.ts +105 -19
- package/src/rpc.ts +27 -3
- package/src/search.ts +41 -2
- package/src/settings-commands.ts +6 -4
- package/src/settings.ts +28 -13
- package/src/status.ts +52 -5
- package/src/tools.ts +65 -20
- package/src/types.ts +32 -0
- package/tui/settings-page-data.ts +31 -15
- package/tui/settings-page.tsx +7 -1
- package/tui/workspace-rpc.ts +98 -0
- package/tui.ts +112 -41
package/src/indexer.ts
CHANGED
|
@@ -95,7 +95,18 @@ export async function runIndex(deps: IndexerDeps, options: IndexOptions): Promis
|
|
|
95
95
|
// Determine dimension (probe embedder if unknown).
|
|
96
96
|
let dimension = settings.dimension
|
|
97
97
|
const existingInfo = await store.info()
|
|
98
|
-
|
|
98
|
+
const existingProfile = existingInfo.profile
|
|
99
|
+
// The stored dimension is only authoritative for the profile we are about to
|
|
100
|
+
// write. Inheriting it across a provider change is how a 1536-wide Mistral
|
|
101
|
+
// index makes an OpenAI model look 1536-dimensional: the probe that would
|
|
102
|
+
// have asked the provider never runs, and the inherited number is then
|
|
103
|
+
// persisted as though it had been measured, which makes the mismatch
|
|
104
|
+
// self-consistent and undetectable on every later run.
|
|
105
|
+
const sameProfile =
|
|
106
|
+
existingProfile !== undefined &&
|
|
107
|
+
existingProfile.provider === settings.provider &&
|
|
108
|
+
existingProfile.modelId === settings.modelId
|
|
109
|
+
if (!dimension && sameProfile && existingProfile?.dimension) dimension = existingProfile.dimension
|
|
99
110
|
if (!dimension) {
|
|
100
111
|
const probe = await getEmbedder().embed(["dimension probe"])
|
|
101
112
|
dimension = probe[0]?.length ?? 0
|
|
@@ -146,10 +157,15 @@ export async function runIndex(deps: IndexerDeps, options: IndexOptions): Promis
|
|
|
146
157
|
if (shouldImport) {
|
|
147
158
|
await deps.onProgress?.({ phase: "importing", processed: 0, total: 0 })
|
|
148
159
|
try {
|
|
160
|
+
// Collected rather than thrown: discovery no longer fails on an
|
|
161
|
+
// unreadable source, and the caller has to be told why the scan below is
|
|
162
|
+
// about to re-embed the whole workspace at their expense.
|
|
163
|
+
const problems: string[] = []
|
|
149
164
|
const sources = await discoverKiloSources(root, {
|
|
150
165
|
qdrant,
|
|
151
166
|
homeDir: undefined,
|
|
152
167
|
targetProfile: profile,
|
|
168
|
+
onProblem: (message) => problems.push(message),
|
|
153
169
|
})
|
|
154
170
|
const source = sources.find((item) => item.compatible) ?? sources[0]
|
|
155
171
|
if (source && source.compatible) {
|
|
@@ -179,6 +195,12 @@ export async function runIndex(deps: IndexerDeps, options: IndexOptions): Promis
|
|
|
179
195
|
report.errors.push(
|
|
180
196
|
`Kilo index found (${source.name}) but its embedding profile does not match ${profile.provider}:${profile.modelId}:${profile.dimension}; indexing from scratch`,
|
|
181
197
|
)
|
|
198
|
+
} else if (problems.length > 0) {
|
|
199
|
+
// No usable source and a reason why. Without this the build reads as a
|
|
200
|
+
// workspace that has no Kilo index at all, and the full re-embedding
|
|
201
|
+
// that follows looks like the normal path rather than the expensive
|
|
202
|
+
// fallback it is.
|
|
203
|
+
report.errors.push(`${problems.join(" · ")} Indexing from scratch instead.`)
|
|
182
204
|
}
|
|
183
205
|
} catch (error) {
|
|
184
206
|
report.errors.push(`import failed: ${describeError(error)}`)
|
package/src/registry.ts
CHANGED
|
@@ -4,42 +4,71 @@ import { createHash } from "node:crypto"
|
|
|
4
4
|
* Embedding model catalog, mirrored from Kilo Code / Roo Code
|
|
5
5
|
* (`packages/kilo-indexing/src/indexing/model-registry.ts`) so that query
|
|
6
6
|
* embeddings are compatible with existing Kilo indexes.
|
|
7
|
+
*
|
|
8
|
+
* The mirror is the compatibility contract: an import is accepted only when
|
|
9
|
+
* provider, model id and dimension match byte for byte, so an entry here that
|
|
10
|
+
* drifts from Kilo's silently makes an index un-importable. Entries marked
|
|
11
|
+
* `kiloMirror: false` are ours alone and can never be imported.
|
|
7
12
|
*/
|
|
8
13
|
|
|
9
14
|
import type { EmbedderProvider, ModelProfile } from "./types.ts"
|
|
10
15
|
|
|
16
|
+
/** Input ceilings and batch limits are from each provider's own documentation. */
|
|
11
17
|
const profiles: Partial<Record<EmbedderProvider, Record<string, ModelProfile>>> = {
|
|
12
18
|
openai: {
|
|
13
|
-
"text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4 },
|
|
14
|
-
"text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4 },
|
|
15
|
-
"text-embedding-ada-002": { dimension: 1536, scoreThreshold: 0.4 },
|
|
19
|
+
"text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4, maxInputTokens: 8192, maxBatchItems: 2048, maxBatchTokens: 300_000 },
|
|
20
|
+
"text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4, maxInputTokens: 8192, maxBatchItems: 2048, maxBatchTokens: 300_000 },
|
|
21
|
+
"text-embedding-ada-002": { dimension: 1536, scoreThreshold: 0.4, maxInputTokens: 8192, maxBatchItems: 2048, maxBatchTokens: 300_000 },
|
|
16
22
|
},
|
|
17
23
|
ollama: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
24
|
+
// 512 tokens is the smallest input in the catalog by a wide margin. A chunk of
|
|
25
|
+
// real code is routinely longer, and Ollama truncates by default, so this one
|
|
26
|
+
// is also the reason the Ollama adapter refuses to truncate silently.
|
|
27
|
+
"mxbai-embed-large": { dimension: 1024, scoreThreshold: 0.3, maxInputTokens: 512, normalized: true },
|
|
28
|
+
"nomic-embed-text": { dimension: 768, scoreThreshold: 0.3, queryPrefix: "search_query: ", maxInputTokens: 2048, normalized: true },
|
|
29
|
+
// Ollama reports the tag, but Kilo stores whatever its config names, so an
|
|
30
|
+
// index carrying this id was written by us and cannot be imported.
|
|
31
|
+
"nomic-embed-text:latest": { dimension: 768, scoreThreshold: 0.3, queryPrefix: "search_query: ", maxInputTokens: 2048, normalized: true, kiloMirror: false },
|
|
32
|
+
"all-minilm": { dimension: 384, scoreThreshold: 0.3, maxInputTokens: 512, normalized: true },
|
|
33
|
+
"bge-m3": { dimension: 1024, scoreThreshold: 0.3, maxInputTokens: 8192, normalized: true, kiloMirror: false },
|
|
22
34
|
},
|
|
23
35
|
gemini: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"embedding-001": { dimension:
|
|
36
|
+
// gemini-embedding-001 accepts only 2048 tokens, the tightest cloud ceiling here.
|
|
37
|
+
// gemini-embedding-2 takes 8192 and is the better default despite costing more.
|
|
38
|
+
"gemini-embedding-001": { dimension: 3072, scoreThreshold: 0.35, maxInputTokens: 2048 },
|
|
39
|
+
"gemini-embedding-2": { dimension: 3072, scoreThreshold: 0.35, maxInputTokens: 8192, normalized: true, kiloMirror: false },
|
|
40
|
+
"text-embedding-004": { dimension: 768, scoreThreshold: 0.35, maxInputTokens: 2048 },
|
|
41
|
+
"embedding-001": { dimension: 768, scoreThreshold: 0.35, maxInputTokens: 2048 },
|
|
27
42
|
},
|
|
28
43
|
mistral: {
|
|
29
|
-
"codestral-embed-2505": { dimension: 1536, scoreThreshold: 0.35 },
|
|
30
|
-
"codestral-embed": { dimension: 1536, scoreThreshold: 0.35 },
|
|
31
|
-
"mistral-embed": { dimension: 1024, scoreThreshold: 0.35 },
|
|
44
|
+
"codestral-embed-2505": { dimension: 1536, scoreThreshold: 0.35, maxInputTokens: 8192, normalized: true },
|
|
45
|
+
"codestral-embed": { dimension: 1536, scoreThreshold: 0.35, maxInputTokens: 8192, normalized: true },
|
|
46
|
+
"mistral-embed": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 8192, normalized: true },
|
|
32
47
|
},
|
|
33
48
|
voyage: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"voyage-
|
|
49
|
+
// 32k of context on a code-specific model: four times any other entry here, and
|
|
50
|
+
// the reason voyage is a better default than codestral for code chunks.
|
|
51
|
+
"voyage-code-4": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, maxBatchTokens: 120_000, normalized: true, kiloMirror: false },
|
|
52
|
+
"voyage-code-3": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, maxBatchTokens: 120_000, normalized: true },
|
|
53
|
+
"voyage-4-large": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, maxBatchTokens: 120_000, normalized: true, kiloMirror: false },
|
|
54
|
+
"voyage-4": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, maxBatchTokens: 320_000, normalized: true, kiloMirror: false },
|
|
55
|
+
"voyage-4-lite": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, maxBatchTokens: 1_000_000, normalized: true, kiloMirror: false },
|
|
56
|
+
"voyage-3": { dimension: 1024, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, normalized: true },
|
|
57
|
+
"voyage-3-lite": { dimension: 512, scoreThreshold: 0.35, maxInputTokens: 32_000, maxBatchItems: 1000, normalized: true },
|
|
37
58
|
},
|
|
38
59
|
openrouter: {
|
|
39
|
-
"openai/text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4 },
|
|
40
|
-
"openai/text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4 },
|
|
41
|
-
|
|
60
|
+
"openai/text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4, maxInputTokens: 8192, maxBatchTokens: 300_000 },
|
|
61
|
+
"openai/text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4, maxInputTokens: 8192, maxBatchTokens: 300_000 },
|
|
62
|
+
// Kilo's registry names this `google/gemini-embedding-2-preview`. Ours said
|
|
63
|
+
// `google/gemini-embedding-001`, which can never match a Kilo index: the
|
|
64
|
+
// profile comparison is exact string equality, so the drift was invisible and
|
|
65
|
+
// simply made every Gemini-via-OpenRouter index un-importable.
|
|
66
|
+
"google/gemini-embedding-2-preview": { dimension: 3072, scoreThreshold: 0.35, maxInputTokens: 8192 },
|
|
42
67
|
},
|
|
68
|
+
// Kilo's registry also lists `bedrock` and `vercel-ai-gateway`. Both are
|
|
69
|
+
// deliberately absent: bedrock needs SigV4 request signing, and neither is a
|
|
70
|
+
// provider this plugin offers. A catalog entry with no implemented adapter is
|
|
71
|
+
// worse than a missing model, because it looks selectable and then fails.
|
|
43
72
|
"openai-compatible": {},
|
|
44
73
|
}
|
|
45
74
|
|
|
@@ -49,6 +78,7 @@ const defaults: Record<string, string> = {
|
|
|
49
78
|
gemini: "gemini-embedding-001",
|
|
50
79
|
mistral: "codestral-embed-2505",
|
|
51
80
|
voyage: "voyage-code-3",
|
|
81
|
+
bedrock: "amazon.titan-embed-text-v2:0",
|
|
52
82
|
openrouter: "openai/text-embedding-3-small",
|
|
53
83
|
"openai-compatible": "",
|
|
54
84
|
}
|
|
@@ -59,6 +89,15 @@ export const DEFAULT_EMBEDDING_BATCH_SIZE = 60
|
|
|
59
89
|
export const DEFAULT_MAX_FILE_SIZE_BYTES = 1024 * 1024
|
|
60
90
|
export const MAX_SEARCH_RESULTS = 200
|
|
61
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Ceiling used when a model is not in the catalog.
|
|
94
|
+
*
|
|
95
|
+
* `mxbai-embed-large` takes 512 tokens, and Ollama truncates anything longer
|
|
96
|
+
* without saying so. For an unknown model the safe assumption is the tightest
|
|
97
|
+
* documented one: a shorter index beat a silently wrong index.
|
|
98
|
+
*/
|
|
99
|
+
export const FALLBACK_MAX_INPUT_TOKENS = 512
|
|
100
|
+
|
|
62
101
|
/** Scanner extension allowlist mirrored from Kilo's tree-sitter index. */
|
|
63
102
|
export const DEFAULT_SCANNER_EXTENSIONS: readonly string[] = [
|
|
64
103
|
".bash",
|
|
@@ -145,6 +184,41 @@ export function getDefaultModelId(provider: EmbedderProvider): string {
|
|
|
145
184
|
return defaults[provider] ?? ""
|
|
146
185
|
}
|
|
147
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Providers whose adapter has been exercised against the real service.
|
|
189
|
+
*
|
|
190
|
+
* Not a quality judgement, a statement of fact. The others were written from
|
|
191
|
+
* each provider's documentation and tested against fixtures written alongside
|
|
192
|
+
* them, so a wrong assumption about a field name or a response shape would pass
|
|
193
|
+
* every test and fail on first use. Surfacing that where a provider is chosen is
|
|
194
|
+
* cheaper than letting a user discover it from a failed indexing run.
|
|
195
|
+
*/
|
|
196
|
+
export const LIVE_TESTED_PROVIDERS: ReadonlySet<string> = new Set(["mistral"])
|
|
197
|
+
|
|
198
|
+
export function isLiveTested(provider: EmbedderProvider): boolean {
|
|
199
|
+
return LIVE_TESTED_PROVIDERS.has(provider)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Every model id the catalog knows for a provider, in catalog order.
|
|
204
|
+
*/
|
|
205
|
+
export function listModelIds(provider: EmbedderProvider): string[] {
|
|
206
|
+
return Object.keys(profiles[provider] ?? {})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Whether an index built with this profile could ever be imported from Kilo.
|
|
211
|
+
*
|
|
212
|
+
* `undefined` means the profile is unknown to us, which is a different thing
|
|
213
|
+
* from "not importable": a model we have never heard of may still be exactly
|
|
214
|
+
* what a Kilo index holds.
|
|
215
|
+
*/
|
|
216
|
+
export function isKiloMirrored(provider: EmbedderProvider, modelId: string): boolean | undefined {
|
|
217
|
+
const profile = getModelProfile(provider, modelId)
|
|
218
|
+
if (!profile) return undefined
|
|
219
|
+
return profile.kiloMirror !== false
|
|
220
|
+
}
|
|
221
|
+
|
|
148
222
|
export function getModelProfile(provider: EmbedderProvider, modelId: string): ModelProfile | undefined {
|
|
149
223
|
return profiles[provider]?.[modelId]
|
|
150
224
|
}
|
|
@@ -161,6 +235,18 @@ export function getModelQueryPrefix(provider: EmbedderProvider, modelId: string)
|
|
|
161
235
|
return getModelProfile(provider, modelId)?.queryPrefix
|
|
162
236
|
}
|
|
163
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Largest input the model accepts, in tokens.
|
|
240
|
+
*
|
|
241
|
+
* Falls back to the most conservative ceiling any catalog model has, rather than
|
|
242
|
+
* the most generous: guessing high means sending a 32,000-character chunk to a
|
|
243
|
+
* model that accepts 512, which comes back silently truncated and gets indexed
|
|
244
|
+
* as if it covered the whole function.
|
|
245
|
+
*/
|
|
246
|
+
export function getModelMaxInputTokens(provider: EmbedderProvider, modelId: string): number {
|
|
247
|
+
return getModelProfile(provider, modelId)?.maxInputTokens ?? FALLBACK_MAX_INPUT_TOKENS
|
|
248
|
+
}
|
|
249
|
+
|
|
164
250
|
/** sha256 hex of a workspace path (no normalization, mirrors Kilo). */
|
|
165
251
|
export function workspaceHash(root: string): string {
|
|
166
252
|
return createHash("sha256").update(root).digest("hex")
|
package/src/rpc.ts
CHANGED
|
@@ -19,6 +19,20 @@ const empty = { type: "object", properties: {}, additionalProperties: false } as
|
|
|
19
19
|
*/
|
|
20
20
|
const directoryShape = { directory: { type: "string" } } as const
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Input schema for a method whose only argument is the caller's workspace.
|
|
24
|
+
*
|
|
25
|
+
* Exists so `kilo.discover` and `settings.test` cannot be written as a bare
|
|
26
|
+
* `directoryShape`: that is a fragment of `properties`, not a schema, and a
|
|
27
|
+
* validator reading it as one sees no `directory` at all — silently answering
|
|
28
|
+
* about the service's own workspace again.
|
|
29
|
+
*/
|
|
30
|
+
const workspaceInputShape = {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: { ...directoryShape },
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
} as const
|
|
35
|
+
|
|
22
36
|
const settingsShape = {
|
|
23
37
|
type: "object",
|
|
24
38
|
properties: {
|
|
@@ -32,8 +46,7 @@ const settingsShape = {
|
|
|
32
46
|
importFromKilo: { type: "boolean" },
|
|
33
47
|
autoRefresh: { type: "boolean" },
|
|
34
48
|
searchMaxResults: { type: "number" },
|
|
35
|
-
|
|
36
|
-
hasOpenAiKey: { type: "boolean" },
|
|
49
|
+
configuredProviders: { type: "array", items: { type: "string" } },
|
|
37
50
|
settingsFile: { type: "string" },
|
|
38
51
|
},
|
|
39
52
|
required: ["vectorStore", "qdrantUrl", "provider", "importFromKilo", "settingsFile"],
|
|
@@ -63,6 +76,9 @@ export const IndexingRpc = {
|
|
|
63
76
|
type: "object",
|
|
64
77
|
properties: {
|
|
65
78
|
target: { type: "string", enum: ["qdrant", "lancedb", "provider", "kilo"] },
|
|
79
|
+
// Only `kilo` is workspace-scoped; the other targets describe global
|
|
80
|
+
// backends. Sending it costs nothing and keeps one shape for the client.
|
|
81
|
+
...directoryShape,
|
|
66
82
|
},
|
|
67
83
|
required: ["target"],
|
|
68
84
|
additionalProperties: false,
|
|
@@ -75,7 +91,7 @@ export const IndexingRpc = {
|
|
|
75
91
|
},
|
|
76
92
|
},
|
|
77
93
|
"kilo.discover": {
|
|
78
|
-
input:
|
|
94
|
+
input: workspaceInputShape,
|
|
79
95
|
output: {
|
|
80
96
|
type: "object",
|
|
81
97
|
properties: {
|
|
@@ -95,6 +111,14 @@ export const IndexingRpc = {
|
|
|
95
111
|
additionalProperties: true,
|
|
96
112
|
},
|
|
97
113
|
},
|
|
114
|
+
/**
|
|
115
|
+
* Sources that exist but could not be read, in plain language.
|
|
116
|
+
*
|
|
117
|
+
* Without this the only thing a caller can say when the list is empty
|
|
118
|
+
* is "not found", which is a different statement from "found, and the
|
|
119
|
+
* read failed" — and the second one is the one that needs acting on.
|
|
120
|
+
*/
|
|
121
|
+
problems: { type: "array", items: { type: "string" } },
|
|
98
122
|
},
|
|
99
123
|
required: ["sources"],
|
|
100
124
|
additionalProperties: false,
|
package/src/search.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { getModelScoreThreshold, profileKey, workspaceHash } from "./registry.ts
|
|
|
8
8
|
import { withProfile } from "./config.ts"
|
|
9
9
|
import type { EmbedderProvider, IndexingSettings, KVStore, QueryHit, SearchHit } from "./types.ts"
|
|
10
10
|
import type { Qdrant } from "./qdrant.ts"
|
|
11
|
+
import type { VectorStoreAdapter } from "./vector-store.ts"
|
|
11
12
|
import { describeError } from "./errors.ts"
|
|
12
13
|
|
|
13
14
|
export interface SearchDeps {
|
|
@@ -15,6 +16,13 @@ export interface SearchDeps {
|
|
|
15
16
|
kv: KVStore
|
|
16
17
|
root: string
|
|
17
18
|
settings: IndexingSettings
|
|
19
|
+
/**
|
|
20
|
+
* The own-index store. Built from the settings when omitted.
|
|
21
|
+
*
|
|
22
|
+
* Injected so a caller that already holds one does not build a second
|
|
23
|
+
* identical client, and so the search can be exercised without a server.
|
|
24
|
+
*/
|
|
25
|
+
ownStore?: VectorStoreAdapter
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
export interface SearchMeta {
|
|
@@ -80,7 +88,7 @@ export async function searchCode(deps: SearchDeps, query: string, pathPrefix?: s
|
|
|
80
88
|
const errors: string[] = []
|
|
81
89
|
const limit = Math.max(1, Math.min(overrideLimit ?? settings.searchMaxResults, 200))
|
|
82
90
|
|
|
83
|
-
const ownStore = createOwnStore(settings, root)
|
|
91
|
+
const ownStore = deps.ownStore ?? createOwnStore(settings, root)
|
|
84
92
|
const qdrantClient = settings.vectorStore === "qdrant" ? qdrant : createSettingsQdrant(settings)
|
|
85
93
|
const [ownInfo, kiloCollection] = await Promise.all([
|
|
86
94
|
ownStore.info().catch(() => null),
|
|
@@ -102,6 +110,7 @@ export async function searchCode(deps: SearchDeps, query: string, pathPrefix?: s
|
|
|
102
110
|
if (!profiles.has(profileKey(baseProfile))) profiles.set(profileKey(baseProfile), baseProfile)
|
|
103
111
|
|
|
104
112
|
const vectors = new Map<string, number[]>()
|
|
113
|
+
const embedFailures = new Map<string, string>()
|
|
105
114
|
for (const [key, profile] of profiles) {
|
|
106
115
|
try {
|
|
107
116
|
const embedder = createEmbedder(withProfile(settings, profile))
|
|
@@ -109,10 +118,32 @@ export async function searchCode(deps: SearchDeps, query: string, pathPrefix?: s
|
|
|
109
118
|
if (!vector) throw new Error("empty embedding")
|
|
110
119
|
vectors.set(key, vector)
|
|
111
120
|
} catch (error) {
|
|
112
|
-
|
|
121
|
+
embedFailures.set(key, describeError(error))
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Refuse to answer from part of the corpus.
|
|
127
|
+
*
|
|
128
|
+
* A stored index whose profile cannot be embedded is unreachable, and
|
|
129
|
+
* returning only the half that worked looks exactly like a complete answer
|
|
130
|
+
* whose other half ranked lower. The caller asked what matches, not what
|
|
131
|
+
* matches in whichever part happened to be readable, so this is an error.
|
|
132
|
+
* An index with no points needs no query vector and is not a problem.
|
|
133
|
+
*/
|
|
134
|
+
const unreachable = (label: string, profile: ProfileRef | undefined, points: number | null | undefined): void => {
|
|
135
|
+
if (!profile || (points ?? 0) <= 0) return
|
|
136
|
+
const key = profileKey(profile)
|
|
137
|
+
if (vectors.has(key)) return
|
|
138
|
+
const cause = embedFailures.get(key)
|
|
139
|
+
throw new Error(
|
|
140
|
+
`Cannot search ${label}: it holds ${points} points built with ${key}, and that profile could not be embedded` +
|
|
141
|
+
`${cause ? ` (${cause})` : ""}. Searching only the other index would return an incomplete result set as if it were complete.`,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
unreachable("the own index", ownInfo?.profile, ownInfo?.pointsCount)
|
|
145
|
+
unreachable("Kilo's index", kiloInfo?.profile, kiloInfo?.pointsCount)
|
|
146
|
+
|
|
116
147
|
const minScore = settings.searchMinScore
|
|
117
148
|
|
|
118
149
|
const kiloHits = (async (): Promise<SearchHit[]> => {
|
|
@@ -129,6 +160,11 @@ export async function searchCode(deps: SearchDeps, query: string, pathPrefix?: s
|
|
|
129
160
|
})
|
|
130
161
|
return hits.map((hit) => toSearchHit(hit, "kilo")).filter((hit): hit is SearchHit => hit !== undefined)
|
|
131
162
|
})().catch((error) => {
|
|
163
|
+
// Kilo's index exists and holds points; failing to read it would drop those
|
|
164
|
+
// results from an answer that still looks complete.
|
|
165
|
+
if ((kiloInfo?.pointsCount ?? 0) > 0) {
|
|
166
|
+
throw new Error(`Cannot read Kilo's index (${kiloCollection}): ${describeError(error)}`)
|
|
167
|
+
}
|
|
132
168
|
errors.push(`kilo search: ${describeError(error)}`)
|
|
133
169
|
return [] as SearchHit[]
|
|
134
170
|
})
|
|
@@ -147,6 +183,9 @@ export async function searchCode(deps: SearchDeps, query: string, pathPrefix?: s
|
|
|
147
183
|
})
|
|
148
184
|
return hits.map((hit) => toSearchHit(hit, "own")).filter((hit): hit is SearchHit => hit !== undefined)
|
|
149
185
|
})().catch((error) => {
|
|
186
|
+
if ((ownInfo?.pointsCount ?? 0) > 0) {
|
|
187
|
+
throw new Error(`Cannot read the own index (${ownStore.name}): ${describeError(error)}`)
|
|
188
|
+
}
|
|
150
189
|
errors.push(`own search: ${describeError(error)}`)
|
|
151
190
|
return [] as SearchHit[]
|
|
152
191
|
})
|
package/src/settings-commands.ts
CHANGED
|
@@ -172,10 +172,12 @@ const KEY_SPECS: Record<string, KeySpec> = {
|
|
|
172
172
|
description: "Embedding provider",
|
|
173
173
|
toPatch: (value) => {
|
|
174
174
|
const provider = value as (typeof PROVIDERS)[number]
|
|
175
|
-
//
|
|
176
|
-
// one
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
// Clear the model so the new provider's default applies. Model ids are
|
|
176
|
+
// namespaced per provider, so keeping the old one is never right: it
|
|
177
|
+
// turned a switch to Voyage into `voyage` + `codestral-embed-2505`. The
|
|
178
|
+
// previous code claimed to do this and returned only the provider, which
|
|
179
|
+
// left the stale model in the file and outranked the default.
|
|
180
|
+
return { provider: provider as SettingsFile["provider"], model: "" }
|
|
179
181
|
},
|
|
180
182
|
display: (settings) => settings.provider,
|
|
181
183
|
},
|
package/src/settings.ts
CHANGED
|
@@ -93,6 +93,18 @@ function compact<T extends Record<string, unknown>>(input: T): T {
|
|
|
93
93
|
return out as T
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Merge the two objects a level deep.
|
|
98
|
+
*
|
|
99
|
+
* Derived from the incoming keys rather than listing the provider names here.
|
|
100
|
+
* The hand-written list this replaced silently dropped any credential added to
|
|
101
|
+
* the shape but not to the list: the field existed, the resolver read it, and
|
|
102
|
+
* the value never reached the file.
|
|
103
|
+
*/
|
|
104
|
+
function mergeNested<T extends Record<string, unknown>>(current: T | undefined, incoming: T): T {
|
|
105
|
+
return compact({ ...(current ?? {}), ...incoming }) as T
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
function deepMerge(base: SettingsFile, patch: SettingsFile): SettingsFile {
|
|
97
109
|
const out: SettingsFile = { ...base }
|
|
98
110
|
for (const [key, value] of Object.entries(patch)) {
|
|
@@ -108,19 +120,22 @@ function deepMerge(base: SettingsFile, patch: SettingsFile): SettingsFile {
|
|
|
108
120
|
if (key === "apiKeys") {
|
|
109
121
|
const current = out.apiKeys ?? {}
|
|
110
122
|
const incoming = value as NonNullable<SettingsFile["apiKeys"]>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
const merged: Record<string, unknown> = { ...current }
|
|
124
|
+
for (const [provider, providerValue] of Object.entries(incoming)) {
|
|
125
|
+
if (providerValue === undefined) continue
|
|
126
|
+
// ollama and openai-compatible are objects; the rest are plain keys.
|
|
127
|
+
// Both shapes merge the same way, so no per-provider branch is needed.
|
|
128
|
+
merged[provider] =
|
|
129
|
+
typeof providerValue === "object" && providerValue !== null
|
|
130
|
+
? mergeNested(
|
|
131
|
+
typeof merged[provider] === "object" && merged[provider] !== null
|
|
132
|
+
? (merged[provider] as Record<string, unknown>)
|
|
133
|
+
: undefined,
|
|
134
|
+
providerValue as Record<string, unknown>,
|
|
135
|
+
)
|
|
136
|
+
: providerValue
|
|
137
|
+
}
|
|
138
|
+
out.apiKeys = compact(merged) as SettingsFile["apiKeys"]
|
|
124
139
|
continue
|
|
125
140
|
}
|
|
126
141
|
;(out as Record<string, unknown>)[key] = value
|
package/src/status.ts
CHANGED
|
@@ -5,10 +5,11 @@ import { getKiloStoreInfo, resolveKiloCollection } from "./kilo-store.ts"
|
|
|
5
5
|
import { discoverKiloSources, type KiloSourceInfo } from "./import.ts"
|
|
6
6
|
import { createOwnStore, createSettingsQdrant } from "./store-factory.ts"
|
|
7
7
|
import { diffFiles, loadManifest } from "./manifest.ts"
|
|
8
|
-
import { workspaceHash } from "./registry.ts"
|
|
8
|
+
import { getModelDimension, profileKey, workspaceHash } from "./registry.ts"
|
|
9
9
|
import { scanWorkspace } from "./scanner.ts"
|
|
10
10
|
import type { IndexingSettings, KVStore } from "./types.ts"
|
|
11
11
|
import type { Qdrant } from "./qdrant.ts"
|
|
12
|
+
import type { VectorStoreAdapter } from "./vector-store.ts"
|
|
12
13
|
import { describeError } from "./errors.ts"
|
|
13
14
|
|
|
14
15
|
export interface StatusDeps {
|
|
@@ -16,6 +17,8 @@ export interface StatusDeps {
|
|
|
16
17
|
kv: KVStore
|
|
17
18
|
root: string
|
|
18
19
|
settings: IndexingSettings
|
|
20
|
+
/** The own-index store. Built from the settings when omitted. */
|
|
21
|
+
ownStore?: VectorStoreAdapter
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export interface IndexStatus {
|
|
@@ -78,7 +81,7 @@ export async function getStatus(deps: StatusDeps, options?: { checkFreshness?: b
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
const ownStore = createOwnStore(settings, root)
|
|
84
|
+
const ownStore = deps.ownStore ?? createOwnStore(settings, root)
|
|
82
85
|
const cacheKey = KILO_CACHE_PREFIX + workspaceHash(root).slice(0, 16)
|
|
83
86
|
const cachedKilo = await kv.get(cacheKey)
|
|
84
87
|
const kiloCollection = reachable
|
|
@@ -90,11 +93,19 @@ export async function getStatus(deps: StatusDeps, options?: { checkFreshness?: b
|
|
|
90
93
|
settings.dimension > 0
|
|
91
94
|
? { provider: settings.provider, modelId: settings.modelId, dimension: settings.dimension }
|
|
92
95
|
: undefined
|
|
96
|
+
// Discovery problems are collected here rather than thrown away, so `indexing_status`
|
|
97
|
+
// can say "found but unreadable" instead of the much less useful "nothing there".
|
|
98
|
+
const kiloProblems: string[] = []
|
|
93
99
|
const [kiloInfo, ownInfo, manifest, kiloSources] = await Promise.all([
|
|
94
100
|
kiloCollection ? getKiloStoreInfo(qdrant, kiloCollection).catch(() => null) : null,
|
|
95
101
|
ownStore.info().catch(() => null),
|
|
96
102
|
loadManifest(kv, root),
|
|
97
|
-
discoverKiloSources(root, {
|
|
103
|
+
discoverKiloSources(root, {
|
|
104
|
+
qdrant,
|
|
105
|
+
homeDir: undefined,
|
|
106
|
+
targetProfile,
|
|
107
|
+
onProblem: (message) => kiloProblems.push(message),
|
|
108
|
+
}).catch(() => [] as KiloSourceInfo[]),
|
|
98
109
|
])
|
|
99
110
|
|
|
100
111
|
const freshness = { checked: false, total: 0, added: 0, maybeStale: 0, deleted: 0 }
|
|
@@ -123,8 +134,40 @@ export async function getStatus(deps: StatusDeps, options?: { checkFreshness?: b
|
|
|
123
134
|
: null
|
|
124
135
|
|
|
125
136
|
const compatibleSource = kiloSources.find((source) => source.compatible)
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A profile change destroys the own index and re-embeds everything.
|
|
140
|
+
*
|
|
141
|
+
* Saying so here is the point: the rebuild happens on the next build or
|
|
142
|
+
* refresh, so a user who changes provider to save money can spend the whole
|
|
143
|
+
* repository on embeddings before seeing any indication that it happened.
|
|
144
|
+
* The count is reported because it is the only estimate of the cost.
|
|
145
|
+
*/
|
|
146
|
+
const configuredProfile = {
|
|
147
|
+
provider: settings.provider,
|
|
148
|
+
modelId: settings.modelId,
|
|
149
|
+
dimension: settings.dimension || getModelDimension(settings.provider, settings.modelId) || 0,
|
|
150
|
+
}
|
|
151
|
+
const storedProfile = ownInfo?.profile
|
|
152
|
+
const profileChanged =
|
|
153
|
+
storedProfile !== undefined &&
|
|
154
|
+
(storedProfile.provider !== configuredProfile.provider ||
|
|
155
|
+
storedProfile.modelId !== configuredProfile.modelId ||
|
|
156
|
+
(configuredProfile.dimension > 0 && storedProfile.dimension !== configuredProfile.dimension))
|
|
157
|
+
if (profileChanged && (ownInfo?.pointsCount ?? 0) > 0) {
|
|
158
|
+
warnings.push(
|
|
159
|
+
`The own index holds ${ownInfo?.pointsCount} points built with ${profileKey(storedProfile)} but the configured ` +
|
|
160
|
+
`model is ${profileKey(configuredProfile)}. The next build or refresh will delete them and re-embed the whole ` +
|
|
161
|
+
`workspace. Set the model back to reuse them, or re-import from Kilo if a matching source exists.`,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
126
165
|
let recommendation: string
|
|
127
|
-
if (
|
|
166
|
+
if (profileChanged) {
|
|
167
|
+
recommendation =
|
|
168
|
+
`The embedding model changed since the own index was built (${profileKey(storedProfile!)} -> ` +
|
|
169
|
+
`${profileKey(configuredProfile)}). Run indexing_build to rebuild it, which re-embeds every file.`
|
|
170
|
+
} else if (!reachable && settings.vectorStore === "qdrant") {
|
|
128
171
|
recommendation = "Start Qdrant (e.g. `docker run -p 6333:6333 qdrant/qdrant` or Podman equivalent), then re-run indexing_status."
|
|
129
172
|
} else if (!kiloCollection && !ownInfo?.exists && kiloSources.length === 0) {
|
|
130
173
|
recommendation = "No index found. Run indexing_build to create an independent index (works without Kilo Code)."
|
|
@@ -169,6 +212,10 @@ export async function getStatus(deps: StatusDeps, options?: { checkFreshness?: b
|
|
|
169
212
|
},
|
|
170
213
|
freshness,
|
|
171
214
|
recommendation,
|
|
172
|
-
warnings
|
|
215
|
+
// Discovery problems ride along as warnings because that is the list
|
|
216
|
+
// `indexing_status` already renders, so they surface without a field of
|
|
217
|
+
// their own. It is the only consumer: the footer reads point counts and
|
|
218
|
+
// `ownStoreReachable`, and never looks at warnings.
|
|
219
|
+
warnings: [...warnings, ...kiloProblems],
|
|
173
220
|
}
|
|
174
221
|
}
|