feat: make vector dimension configurable via VECTOR_DIMENSION env var#6443
Open
stakeswky wants to merge 2 commits intolabring:mainfrom
Open
feat: make vector dimension configurable via VECTOR_DIMENSION env var#6443stakeswky wants to merge 2 commits intolabring:mainfrom
stakeswky wants to merge 2 commits intolabring:mainfrom
Conversation
Previously the vector dimension was hardcoded to 1536 across the embedding layer and all vector database drivers (PG, Milvus, OceanBase/SeekDB). This prevented users from using embedding models with higher dimensions such as Qwen3-Embedding-8B (4096 dims) without silent truncation. Changes: - Add VECTOR_DIMENSION constant in vectorDB/constants.ts, read from process.env.VECTOR_DIMENSION with fallback to 1536 - Update formatVectors() to use VECTOR_DIMENSION instead of hardcoded 1536 - Update PG, Milvus, and OceanBase drivers to use VECTOR_DIMENSION for table/collection creation Users can now set VECTOR_DIMENSION=4096 (or any value) in their environment to support higher-dimensional embedding models. Closes labring#6310
Preview sandbox Image: |
Preview mcp_server Image: |
Preview fastgpt Image: |
The embedding test imports formatVectors which uses VECTOR_DIMENSION from the mocked constants module. Without it in the mock, vitest throws 'No VECTOR_DIMENSION export is defined on the mock'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #6310
The vector dimension was hardcoded to 1536 across the embedding layer and all vector database drivers. This caused silent truncation for embedding models with higher dimensions (e.g. Qwen3-Embedding-8B with 4096 dims), with a warning:
Changes
VECTOR_DIMENSIONconstant inpackages/service/common/vectorDB/constants.ts, read fromprocess.env.VECTOR_DIMENSIONwith fallback to1536for backward compatibilityformatVectors()inpackages/service/core/ai/embedding/index.tsto useVECTOR_DIMENSIONinstead of hardcoded1536VECTOR_DIMENSIONfor table/collection creationUsage
Set the environment variable before starting FastGPT:
If not set, defaults to
1536(no breaking change for existing deployments).Note
Existing deployments that want to change the dimension will need to recreate their vector tables/collections, as the dimension is set at table creation time.