Skip to content

Commit f717863

Browse files
authored
fix: correct OpenRouter Mistral model dimension from 3072 to 1536 (#9028)
1 parent 8e4b145 commit f717863

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,124 @@ describe("CodeIndexConfigManager", () => {
18071807
// Should return undefined since custom dimension is invalid
18081808
expect(configManager.currentModelDimension).toBe(undefined)
18091809
})
1810+
1811+
describe("OpenRouter provider dimension handling", () => {
1812+
it("should correctly handle OpenRouter mistral model dimensions across restarts", async () => {
1813+
// Mock getModelDimension to return correct dimensions for OpenRouter models
1814+
mockedGetModelDimension.mockImplementation((provider, modelId) => {
1815+
if (provider === "openrouter") {
1816+
if (modelId === "mistralai/codestral-embed-2505") return 1536
1817+
if (modelId === "mistralai/mistral-embed-2312") return 1024
1818+
if (modelId === "openai/text-embedding-3-large") return 3072
1819+
}
1820+
return undefined
1821+
})
1822+
1823+
// Initial configuration with OpenRouter and Mistral model
1824+
mockContextProxy.getGlobalState.mockReturnValue({
1825+
codebaseIndexEnabled: true,
1826+
codebaseIndexEmbedderProvider: "openrouter",
1827+
codebaseIndexEmbedderModelId: "mistralai/codestral-embed-2505",
1828+
codebaseIndexQdrantUrl: "http://localhost:6333",
1829+
})
1830+
mockContextProxy.getSecret.mockImplementation((key: string) => {
1831+
if (key === "codebaseIndexOpenRouterApiKey") return "test-openrouter-key"
1832+
if (key === "codeIndexQdrantApiKey") return "test-qdrant-key"
1833+
return undefined
1834+
})
1835+
1836+
configManager = new CodeIndexConfigManager(mockContextProxy)
1837+
await configManager.loadConfiguration()
1838+
1839+
// Should correctly return the built-in dimension for the Mistral model
1840+
expect(configManager.currentModelDimension).toBe(1536)
1841+
expect(mockedGetModelDimension).toHaveBeenCalledWith("openrouter", "mistralai/codestral-embed-2505")
1842+
1843+
// Simulate restart by creating a new config manager with same configuration
1844+
const restartConfigManager = new CodeIndexConfigManager(mockContextProxy)
1845+
await restartConfigManager.loadConfiguration()
1846+
1847+
// After "restart", dimension should still be correct
1848+
expect(restartConfigManager.currentModelDimension).toBe(1536)
1849+
expect(restartConfigManager.isFeatureConfigured).toBe(true)
1850+
})
1851+
1852+
it("should not require restart for OpenRouter when same model dimensions are used", async () => {
1853+
// Mock both models to have same dimension
1854+
mockedGetModelDimension.mockImplementation((provider, modelId) => {
1855+
if (provider === "openrouter") {
1856+
if (modelId === "mistralai/codestral-embed-2505") return 1536
1857+
if (modelId === "openai/text-embedding-3-small") return 1536
1858+
}
1859+
return undefined
1860+
})
1861+
1862+
// Initial state with OpenRouter and Mistral model
1863+
mockContextProxy.getGlobalState.mockReturnValue({
1864+
codebaseIndexEnabled: true,
1865+
codebaseIndexEmbedderProvider: "openrouter",
1866+
codebaseIndexEmbedderModelId: "mistralai/codestral-embed-2505",
1867+
codebaseIndexQdrantUrl: "http://localhost:6333",
1868+
})
1869+
mockContextProxy.getSecret.mockImplementation((key: string) => {
1870+
if (key === "codebaseIndexOpenRouterApiKey") return "test-key"
1871+
if (key === "codeIndexQdrantApiKey") return "test-key"
1872+
return undefined
1873+
})
1874+
1875+
await configManager.loadConfiguration()
1876+
1877+
// Change to another model with same dimension
1878+
mockContextProxy.getGlobalState.mockReturnValue({
1879+
codebaseIndexEnabled: true,
1880+
codebaseIndexEmbedderProvider: "openrouter",
1881+
codebaseIndexEmbedderModelId: "openai/text-embedding-3-small", // Same 1536 dimension
1882+
codebaseIndexQdrantUrl: "http://localhost:6333",
1883+
})
1884+
1885+
const result = await configManager.loadConfiguration()
1886+
// Should NOT require restart since dimensions are the same
1887+
expect(result.requiresRestart).toBe(false)
1888+
})
1889+
1890+
it("should require restart for OpenRouter when model dimensions change", async () => {
1891+
// Mock models with different dimensions
1892+
mockedGetModelDimension.mockImplementation((provider, modelId) => {
1893+
if (provider === "openrouter") {
1894+
if (modelId === "mistralai/codestral-embed-2505") return 1536
1895+
if (modelId === "mistralai/mistral-embed-2312") return 1024
1896+
}
1897+
return undefined
1898+
})
1899+
1900+
// Initial state with 1536-dimension model
1901+
mockContextProxy.getGlobalState.mockReturnValue({
1902+
codebaseIndexEnabled: true,
1903+
codebaseIndexEmbedderProvider: "openrouter",
1904+
codebaseIndexEmbedderModelId: "mistralai/codestral-embed-2505",
1905+
codebaseIndexQdrantUrl: "http://localhost:6333",
1906+
})
1907+
mockContextProxy.getSecret.mockImplementation((key: string) => {
1908+
if (key === "codebaseIndexOpenRouterApiKey") return "test-key"
1909+
if (key === "codeIndexQdrantApiKey") return "test-key"
1910+
return undefined
1911+
})
1912+
1913+
await configManager.loadConfiguration()
1914+
1915+
// Change to model with different dimension
1916+
mockContextProxy.getGlobalState.mockReturnValue({
1917+
codebaseIndexEnabled: true,
1918+
codebaseIndexEmbedderProvider: "openrouter",
1919+
codebaseIndexEmbedderModelId: "mistralai/mistral-embed-2312", // Different 1024 dimension
1920+
codebaseIndexQdrantUrl: "http://localhost:6333",
1921+
})
1922+
1923+
const result = await configManager.loadConfiguration()
1924+
// Should require restart since dimensions changed
1925+
expect(result.requiresRestart).toBe(true)
1926+
})
1927+
})
18101928
})
18111929
})
18121930
})

src/shared/embeddingModels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const EMBEDDING_MODEL_PROFILES: EmbeddingModelProfiles = {
8686
"google/gemini-embedding-001": { dimension: 3072, scoreThreshold: 0.4 },
8787
// Mistral models via OpenRouter
8888
"mistralai/mistral-embed-2312": { dimension: 1024, scoreThreshold: 0.4 },
89-
"mistralai/codestral-embed-2505": { dimension: 3072, scoreThreshold: 0.4 },
89+
"mistralai/codestral-embed-2505": { dimension: 1536, scoreThreshold: 0.4 },
9090
// Qwen models via OpenRouter
9191
"qwen/qwen3-embedding-8b": { dimension: 4096, scoreThreshold: 0.4 },
9292
},

0 commit comments

Comments
 (0)