Skip to content

Commit 41844f3

Browse files
committed
feat: add float encoding support for OpenAI-compatible embeddings
- Add codebaseIndexOpenAiCompatibleUseFloatEncoding configuration option - Update OpenAICompatibleEmbedder to support float/base64 encoding formats - Add comprehensive logging via VS Code output channel for debugging - Update UI with checkbox to toggle float encoding in settings - Add i18n translations for new UI elements - Update config manager and service factory to handle new setting - Add comprehensive tests for float encoding functionality Fixes #7199
1 parent 87c42c1 commit 41844f3

File tree

10 files changed

+579
-21
lines changed

10 files changed

+579
-21
lines changed

packages/types/src/codebase-index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const codebaseIndexConfigSchema = z.object({
3434
// OpenAI Compatible specific fields
3535
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
3636
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
37+
codebaseIndexOpenAiCompatibleUseFloatEncoding: z.boolean().optional(),
3738
})
3839

3940
export type CodebaseIndexConfig = z.infer<typeof codebaseIndexConfigSchema>
@@ -62,6 +63,7 @@ export const codebaseIndexProviderSchema = z.object({
6263
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
6364
codebaseIndexOpenAiCompatibleApiKey: z.string().optional(),
6465
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
66+
codebaseIndexOpenAiCompatibleUseFloatEncoding: z.boolean().optional(),
6567
codebaseIndexGeminiApiKey: z.string().optional(),
6668
codebaseIndexMistralApiKey: z.string().optional(),
6769
})

src/services/code-index/__tests__/config-manager.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ describe("CodeIndexConfigManager", () => {
173173
openAiCompatibleOptions: {
174174
baseUrl: "https://api.example.com/v1",
175175
apiKey: "test-openai-compatible-key",
176+
useFloatEncoding: false,
176177
},
177178
qdrantUrl: "http://qdrant.local",
178179
qdrantApiKey: "test-qdrant-key",
@@ -211,6 +212,7 @@ describe("CodeIndexConfigManager", () => {
211212
openAiCompatibleOptions: {
212213
baseUrl: "https://api.example.com/v1",
213214
apiKey: "test-openai-compatible-key",
215+
useFloatEncoding: false,
214216
},
215217
qdrantUrl: "http://qdrant.local",
216218
qdrantApiKey: "test-qdrant-key",
@@ -248,6 +250,7 @@ describe("CodeIndexConfigManager", () => {
248250
openAiCompatibleOptions: {
249251
baseUrl: "https://api.example.com/v1",
250252
apiKey: "test-openai-compatible-key",
253+
useFloatEncoding: false,
251254
// modelDimension is undefined when not set
252255
},
253256
qdrantUrl: "http://qdrant.local",
@@ -287,6 +290,7 @@ describe("CodeIndexConfigManager", () => {
287290
openAiCompatibleOptions: {
288291
baseUrl: "https://api.example.com/v1",
289292
apiKey: "test-openai-compatible-key",
293+
useFloatEncoding: false,
290294
},
291295
geminiOptions: undefined,
292296
qdrantUrl: "http://qdrant.local",

src/services/code-index/__tests__/service-factory.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe("CodeIndexServiceFactory", () => {
182182
openAiCompatibleOptions: {
183183
baseUrl: "https://api.example.com/v1",
184184
apiKey: "test-api-key",
185+
useFloatEncoding: false,
185186
},
186187
}
187188
mockConfigManager.getConfig.mockReturnValue(testConfig as any)
@@ -194,6 +195,15 @@ describe("CodeIndexServiceFactory", () => {
194195
"https://api.example.com/v1",
195196
"test-api-key",
196197
testModelId,
198+
undefined, // modelDimension
199+
false, // useFloatEncoding
200+
expect.objectContaining({
201+
append: expect.any(Function),
202+
appendLine: expect.any(Function),
203+
clear: expect.any(Function),
204+
dispose: expect.any(Function),
205+
show: expect.any(Function),
206+
}), // outputChannel
197207
)
198208
})
199209

@@ -205,6 +215,7 @@ describe("CodeIndexServiceFactory", () => {
205215
openAiCompatibleOptions: {
206216
baseUrl: "https://api.example.com/v1",
207217
apiKey: "test-api-key",
218+
useFloatEncoding: false,
208219
},
209220
}
210221
mockConfigManager.getConfig.mockReturnValue(testConfig as any)
@@ -217,6 +228,15 @@ describe("CodeIndexServiceFactory", () => {
217228
"https://api.example.com/v1",
218229
"test-api-key",
219230
undefined,
231+
undefined, // modelDimension
232+
false, // useFloatEncoding
233+
expect.objectContaining({
234+
append: expect.any(Function),
235+
appendLine: expect.any(Function),
236+
clear: expect.any(Function),
237+
dispose: expect.any(Function),
238+
show: expect.any(Function),
239+
}), // outputChannel
220240
)
221241
})
222242

src/services/code-index/config-manager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CodeIndexConfigManager {
1616
private modelDimension?: number
1717
private openAiOptions?: ApiHandlerOptions
1818
private ollamaOptions?: ApiHandlerOptions
19-
private openAiCompatibleOptions?: { baseUrl: string; apiKey: string }
19+
private openAiCompatibleOptions?: { baseUrl: string; apiKey: string; useFloatEncoding?: boolean }
2020
private geminiOptions?: { apiKey: string }
2121
private mistralOptions?: { apiKey: string }
2222
private qdrantUrl?: string = "http://localhost:6333"
@@ -67,6 +67,8 @@ export class CodeIndexConfigManager {
6767
// Fix: Read OpenAI Compatible settings from the correct location within codebaseIndexConfig
6868
const openAiCompatibleBaseUrl = codebaseIndexConfig.codebaseIndexOpenAiCompatibleBaseUrl ?? ""
6969
const openAiCompatibleApiKey = this.contextProxy?.getSecret("codebaseIndexOpenAiCompatibleApiKey") ?? ""
70+
const openAiCompatibleUseFloatEncoding =
71+
codebaseIndexConfig.codebaseIndexOpenAiCompatibleUseFloatEncoding ?? false
7072
const geminiApiKey = this.contextProxy?.getSecret("codebaseIndexGeminiApiKey") ?? ""
7173
const mistralApiKey = this.contextProxy?.getSecret("codebaseIndexMistralApiKey") ?? ""
7274

@@ -119,6 +121,7 @@ export class CodeIndexConfigManager {
119121
? {
120122
baseUrl: openAiCompatibleBaseUrl,
121123
apiKey: openAiCompatibleApiKey,
124+
useFloatEncoding: openAiCompatibleUseFloatEncoding,
122125
}
123126
: undefined
124127

@@ -158,6 +161,7 @@ export class CodeIndexConfigManager {
158161
ollamaBaseUrl: this.ollamaOptions?.ollamaBaseUrl ?? "",
159162
openAiCompatibleBaseUrl: this.openAiCompatibleOptions?.baseUrl ?? "",
160163
openAiCompatibleApiKey: this.openAiCompatibleOptions?.apiKey ?? "",
164+
openAiCompatibleUseFloatEncoding: this.openAiCompatibleOptions?.useFloatEncoding ?? false,
161165
geminiApiKey: this.geminiOptions?.apiKey ?? "",
162166
mistralApiKey: this.mistralOptions?.apiKey ?? "",
163167
qdrantUrl: this.qdrantUrl ?? "",
@@ -252,6 +256,7 @@ export class CodeIndexConfigManager {
252256
const prevOllamaBaseUrl = prev?.ollamaBaseUrl ?? ""
253257
const prevOpenAiCompatibleBaseUrl = prev?.openAiCompatibleBaseUrl ?? ""
254258
const prevOpenAiCompatibleApiKey = prev?.openAiCompatibleApiKey ?? ""
259+
const prevOpenAiCompatibleUseFloatEncoding = prev?.openAiCompatibleUseFloatEncoding ?? false
255260
const prevModelDimension = prev?.modelDimension
256261
const prevGeminiApiKey = prev?.geminiApiKey ?? ""
257262
const prevMistralApiKey = prev?.mistralApiKey ?? ""
@@ -289,6 +294,7 @@ export class CodeIndexConfigManager {
289294
const currentOllamaBaseUrl = this.ollamaOptions?.ollamaBaseUrl ?? ""
290295
const currentOpenAiCompatibleBaseUrl = this.openAiCompatibleOptions?.baseUrl ?? ""
291296
const currentOpenAiCompatibleApiKey = this.openAiCompatibleOptions?.apiKey ?? ""
297+
const currentOpenAiCompatibleUseFloatEncoding = this.openAiCompatibleOptions?.useFloatEncoding ?? false
292298
const currentModelDimension = this.modelDimension
293299
const currentGeminiApiKey = this.geminiOptions?.apiKey ?? ""
294300
const currentMistralApiKey = this.mistralOptions?.apiKey ?? ""
@@ -305,7 +311,8 @@ export class CodeIndexConfigManager {
305311

306312
if (
307313
prevOpenAiCompatibleBaseUrl !== currentOpenAiCompatibleBaseUrl ||
308-
prevOpenAiCompatibleApiKey !== currentOpenAiCompatibleApiKey
314+
prevOpenAiCompatibleApiKey !== currentOpenAiCompatibleApiKey ||
315+
prevOpenAiCompatibleUseFloatEncoding !== currentOpenAiCompatibleUseFloatEncoding
309316
) {
310317
return true
311318
}

0 commit comments

Comments
 (0)