fix: prioritize user-configured embedding dimension over model default #10488
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #8102
Description
This PR attempts to address Issue #8102 where the embedding dimension setting was not consistently applied, causing a dimension mismatch (e.g., 1536 vs 1024) between collection creation and embedding generation.
Root Cause:
The code was prioritizing the model's built-in dimension over the user-configured dimension. When a user set a custom dimension (e.g., 1536), the collection was created with that dimension, but embeddings were generated using the model's default dimension (e.g., 1024), causing vector dimension errors.
Implementation:
currentModelDimensiongetter inconfig-manager.tsto prioritize user-configured dimension as the single source of truthcreateVectorStore()inservice-factory.tsto use user-configured dimension before falling back to model's built-in dimensionKey design choice: User-configured dimension now takes priority because users may intentionally set specific dimensions for compatibility with existing indexes or for using models that support variable dimensions.
Feedback and guidance are welcome.
Test Procedure
cd src && ./node_modules/.bin/vitest run services/code-index/__tests__/config-manager.spec.ts services/code-index/__tests__/service-factory.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
This is a re-attempt at fixing issue #8102. The previous PR #8106 was closed without being merged.