Skip to content

feat: make vector dimension configurable via VECTOR_DIMENSION env var#6443

Open
stakeswky wants to merge 2 commits intolabring:mainfrom
stakeswky:fix/configurable-vector-dimension
Open

feat: make vector dimension configurable via VECTOR_DIMENSION env var#6443
stakeswky wants to merge 2 commits intolabring:mainfrom
stakeswky:fix/configurable-vector-dimension

Conversation

@stakeswky
Copy link
Contributor

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:

The current vector dimension is 4096, and the vector dimension cannot exceed 1536. The first 1536 dimensions are automatically captured

Changes

  • Add VECTOR_DIMENSION constant in packages/service/common/vectorDB/constants.ts, read from process.env.VECTOR_DIMENSION with fallback to 1536 for backward compatibility
  • Update formatVectors() in packages/service/core/ai/embedding/index.ts to use VECTOR_DIMENSION instead of hardcoded 1536
  • Update PG, Milvus, and OceanBase/SeekDB drivers to use VECTOR_DIMENSION for table/collection creation

Usage

Set the environment variable before starting FastGPT:

VECTOR_DIMENSION=4096

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.

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
@github-actions
Copy link

github-actions bot commented Feb 17, 2026

Preview sandbox Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_sandbox_21bb8a48fd53e17958afc5ec557a3d7677e68f81

@github-actions
Copy link

github-actions bot commented Feb 17, 2026

Preview mcp_server Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_mcp_server_21bb8a48fd53e17958afc5ec557a3d7677e68f81

@github-actions
Copy link

github-actions bot commented Feb 17, 2026

Preview fastgpt Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_21bb8a48fd53e17958afc5ec557a3d7677e68f81

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'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector dimension cannot exceed 1536

1 participant