Skip to content

Commit 6f87a73

Browse files
committed
refactor: remove requiresClear logic and simplify collection initialization in QdrantVectorStore
1 parent b655c0d commit 6f87a73

File tree

5 files changed

+427
-62
lines changed

5 files changed

+427
-62
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe("CodeIndexConfigManager", () => {
4242
searchMinScore: 0.4,
4343
})
4444
expect(result.requiresRestart).toBe(false)
45-
expect(result.requiresClear).toBe(false)
4645
})
4746

4847
it("should load configuration from globalState and secrets", async () => {
@@ -98,29 +97,6 @@ describe("CodeIndexConfigManager", () => {
9897
const result = await configManager.loadConfiguration()
9998
expect(result.requiresRestart).toBe(true)
10099
})
101-
102-
it("should detect clear requirement when model dimensions change", async () => {
103-
// Initial state with a model
104-
mockContextProxy.getGlobalState.mockReturnValue({
105-
codebaseIndexEnabled: true,
106-
codebaseIndexQdrantUrl: "http://qdrant.local",
107-
codebaseIndexEmbedderProvider: "openai",
108-
codebaseIndexEmbedderModelId: "text-embedding-3-small",
109-
})
110-
111-
await configManager.loadConfiguration()
112-
113-
// Change to a model with different dimensions
114-
mockContextProxy.getGlobalState.mockReturnValue({
115-
codebaseIndexEnabled: true,
116-
codebaseIndexQdrantUrl: "http://qdrant.local",
117-
codebaseIndexEmbedderProvider: "openai",
118-
codebaseIndexEmbedderModelId: "text-embedding-3-large",
119-
})
120-
121-
const result = await configManager.loadConfiguration()
122-
expect(result.requiresClear).toBe(true)
123-
})
124100
})
125101

126102
describe("isConfigured", () => {

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ApiHandlerOptions } from "../../shared/api"
22
import { ContextProxy } from "../../core/config/ContextProxy"
33
import { EmbedderProvider } from "./interfaces/manager"
4-
import { getModelDimension, getDefaultModelId } from "../../shared/embeddingModels"
54
import { CodeIndexConfig, PreviousConfigSnapshot } from "./interfaces/config"
65
import { SEARCH_MIN_SCORE } from "./constants"
76

@@ -38,7 +37,6 @@ export class CodeIndexConfigManager {
3837
searchMinScore?: number
3938
}
4039
requiresRestart: boolean
41-
requiresClear: boolean
4240
}> {
4341
const previousConfigSnapshot: PreviousConfigSnapshot = {
4442
enabled: this.isEnabled,
@@ -84,16 +82,6 @@ export class CodeIndexConfigManager {
8482
ollamaBaseUrl: codebaseIndexEmbedderBaseUrl,
8583
}
8684

87-
const previousModelId =
88-
previousConfigSnapshot.modelId ?? getDefaultModelId(previousConfigSnapshot.embedderProvider)
89-
const currentModelId = this.modelId ?? getDefaultModelId(this.embedderProvider)
90-
const previousDimension = previousModelId
91-
? getModelDimension(previousConfigSnapshot.embedderProvider, previousModelId)
92-
: undefined
93-
const currentDimension = currentModelId ? getModelDimension(this.embedderProvider, currentModelId) : undefined
94-
const requiresClear =
95-
previousDimension !== undefined && currentDimension !== undefined && previousDimension !== currentDimension
96-
9785
return {
9886
configSnapshot: previousConfigSnapshot,
9987
currentConfig: {
@@ -108,7 +96,6 @@ export class CodeIndexConfigManager {
10896
searchMinScore: this.searchMinScore,
10997
},
11098
requiresRestart: this._didConfigChangeRequireRestart(previousConfigSnapshot),
111-
requiresClear,
11299
}
113100
}
114101

src/services/code-index/manager.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class CodeIndexManager {
100100
public async initialize(contextProxy: ContextProxy): Promise<{ requiresRestart: boolean }> {
101101
// 1. ConfigManager Initialization and Configuration Loading
102102
this._configManager = new CodeIndexConfigManager(contextProxy)
103-
const { requiresRestart, requiresClear } = await this._configManager.loadConfiguration()
103+
const { requiresRestart } = await this._configManager.loadConfiguration()
104104

105105
// 2. Check if feature is enabled
106106
if (!this.isFeatureEnabled) {
@@ -170,20 +170,11 @@ export class CodeIndexManager {
170170
)
171171
}
172172

173-
// 5. Handle Data Clearing
174-
if (requiresClear) {
175-
if (this._orchestrator) {
176-
await this._orchestrator.clearIndexData()
177-
}
178-
if (this._cacheManager) {
179-
await this._cacheManager.clearCacheFile()
180-
}
181-
}
182-
183-
// Handle Indexing Start/Restart
173+
// 5. Handle Indexing Start/Restart
174+
// The enhanced vectorStore.initialize() in startIndexing() now handles dimension changes automatically
175+
// by detecting incompatible collections and recreating them, so we rely on that for dimension changes
184176
const shouldStartOrRestartIndexing =
185177
requiresRestart ||
186-
requiresClear ||
187178
(needsServiceRecreation && (!this._orchestrator || this._orchestrator.state !== "Indexing"))
188179

189180
if (shouldStartOrRestartIndexing) {

0 commit comments

Comments
 (0)