fix: silence repeated SiliconFlow embedding dimensions warning
Modifications
Fixes #9228.
Implements option 2 from the issue ("initialization-time one-shot warning"):
- Moved SiliconFlow dimensions detection and warning log from
_embedding_kwargs()(called per embedding request) to__init__via a new_build_embedding_kwargs()method. The resulting kwargs dict is cached inself._cached_kwargs;_embedding_kwargs()now just returns the cached dict. get_dim()is intentionally left unchanged, to preserve the dimension-mismatch guard inknowledge_base_service.create_kband FAISS index sizing invec_db.py.
Why
PR #8508 fixed the SiliconFlow embedding 400 error by stripping the dimensions parameter for non-Qwen models, but the detection ran on every _embedding_kwargs() call. When embedding_dimensions is configured, this emitted a WARN log per embedding request (3+ per conversation due to memory recall + reflection), severely hurting log readability.
Why option 2 (init-time one-shot) over the other two options in the issue
- Option 1 (first WARN, then DEBUG): still executes the detection logic on every call; only downgrades the log level. The per-call overhead remains.
- Option 3 (auto-clear config): mutating user config has side effects and may break other code paths that read
embedding_dimensions. Higher complexity, lower payoff. - Option 2 (chosen): detection runs exactly once at init; zero per-call overhead; warning still surfaces at startup so users know their
dimensionsconfig is being ignored.
Behavior change
-
Before: WARN logged on every
get_embedding/get_embeddingscall when SiliconFlow + non-Qwen +embedding_dimensionsconfigured. -
After: WARN logged exactly once at provider initialization.
-
API request parameters: unchanged (still stripped for SiliconFlow non-Qwen).
-
Non-SiliconFlow paths: unchanged.
-
[x] This is NOT a breaking change.
Screenshots or Test Results
uv run ruff format --check .✅ (480 files already formatted)uv run ruff check .✅ (All checks passed)uv run pytest tests/test_openai_embedding_source.py tests/unit/test_faiss_vec_db.py✅ (4 passed)- Smoke test: AstrBot started, WebUI returned HTTP 200 on localhost:6185
Checklist
- [x] 😊 No new features added (bug fix only, discussed in #9228).
- [x] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
- [x] 🤓 No new dependencies introduced.
- [x] 😮 No malicious code.
Summary by Sourcery
Bug Fixes:
- Ensure SiliconFlow embedding dimensions warnings are emitted only once at initialization instead of on every embedding request.
Summary by Sourcery
Bug Fixes:
- Emit SiliconFlow embedding-dimension warnings only once at provider initialization instead of on every embedding request.