Repository navigation
fix: distinguish query and document embeddings for DashScope and NVIDIA - #11014
Closed
hongdougao111 wants to merge 10 commits into
Closed
hongdougao111 wants to merge 10 commits into
hongdougao111 wants to merge 10 commits into
Conversation
Contributor
|
Sorry @hongdougao111, your pull request is larger than the review limit of 150,000 diff characters |
…tDevs#10740) * fix(qqofficial): stop logging image payload on upload failure 图片上传最终失败时,warning 把整包 payload 写进日志,其中 file_data 是整张 图片的 base64(单张卡片常见数 MB)。一条这样的日志足以拖慢日志写入,并让 WebUI 的日志流卡住,表现为服务器/面板几乎不可用。 - 失败日志只保留 file_type、接收方与数据体积,不再包含图片二进制; - 图片上传重试 5 次 → 3 次,并关闭逐次 WARNING(保留一条汇总),避免一次 失败在指数退避下占住事件循环 30s 以上、同时刷屏; - 新增回归测试,断言失败日志中不含 base64 数据且尝试次数为 3。 * Delete tests/test_qqofficial_image_upload_log.py --------- Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
Allow command names in plugin details to wrap instead of truncating them with an ellipsis. Keep command-group controls, indentation, and table column widths unchanged. Fixes AstrBotDevs#10856
…BotDevs#10837) * fix: preserve animation guidance with persistent montage images * test: focus animation guidance coverage on history replay --------- Co-authored-by: Anka <1350989414@qq.com>
…s#10828) * fix(provider): default Gemini TTS to gemini-3.8-flash-tts Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test: remove Gemini TTS default model tests --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: Anka <1350989414@qq.com>
…me (AstrBotDevs#10715) * fix(telegram): fall back to display name for senders without a username Co-authored-by: Cursor <cursoragent@cursor.com> * test: remove sender nickname fallback test --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Anka <1350989414@qq.com>
…tDevs#11005) - remove stdlib self-tests, docs snapshots, and redundant coverage - parameterize timeout, image, download, CLI, reply, and backoff cases - merge System One template defaults and assert unknown provider no-op 5311 passed, 35 skipped (was 5345 passed)
…evs#11009) Keep an explicit dashboard choice instead of overwriting it with the full-profile default, and run the full suite against ./tests with --cov=astrbot to match CI.
hongdougao111
force-pushed
the
fix/dashscope-nvidia-task-type
branch
from
November 5, 2026 12:21
e3ab6f2 to
0fba758
Compare
`gemini_embedding_source.py` embedded queries and documents with the same
configuration, so retrieval similarity had little to no discriminative power.
Two separate problems were involved.
Task conditioning was missing entirely:
- `gemini-embedding-001` supports `task_type` (`RETRIEVAL_QUERY` /
`RETRIEVAL_DOCUMENT`) but only `output_dimensionality` was sent.
- `gemini-embedding-2` dropped support for `task_type` and expects the task
baked into the text instead (`task: search result | query: {text}` for
queries, `title: none | text: {text}` for documents); neither was applied.
Separately, FAISS stored and searched raw provider vectors. `IndexFlatL2` with
`score = 1 - distance / 2` only equals cosine similarity for unit vectors, and
Gemini returns unnormalized vectors below 3072 dimensions whose magnitude
drifts with text length. The score was therefore dominated by vector magnitude
rather than meaning, which is why no similarity threshold could separate
relevant from irrelevant memories.
Changes:
- Add `EmbeddingProvider.get_query_embedding()`, defaulting to
`get_embedding()` so other providers are unaffected. `FaissVecDB.retrieve()`
and the dashboard query embedding now use it.
- Gemini adapter branches on model generation, with a
`embedding_task_type_mode` escape hatch (`auto` / `never` / `always`).
- L2-normalize vectors on insert, batch insert and search.
- Re-normalize existing indexes once on load so upgraded instances do not end
up with normalized queries against unnormalized stored vectors. The rewrite
is idempotent (zero vectors excluded from the check so they cannot retrigger
it), keeps the id-to-vector mapping intact, is skipped for index types that
cannot be reconstructed, and a failed write only warns instead of preventing
the knowledge base from starting.
- Accept `title: none` for untitled documents, and fall back to `search
result` for an unrecognized task name rather than failing the retrieval path.
Closes AstrBotDevs#11006
Both adapters embedded retrieval queries with the document-side encoding mode, which lowers retrieval accuracy. DashScope supports `text_type`: `query` for user queries and `document` for stored text. The adapter never sent it, so everything was embedded as a document (that is the API default). The multimodal endpoint does not accept `text_type`, so it is excluded. NVIDIA is more explicit about the consequence. Their docs state that models such as NV-Embed-QA, E5 and nemotron "require the input_type parameter" and that using the wrong value "will result in large drops in retrieval accuracy". The adapter hardcoded `input_type` to a single configured value (default `passage`), so queries were also embedded as passages. Changes: - `get_query_embedding()` is now implemented in both adapters; `get_embedding()` and `get_embeddings()` keep document semantics for indexing and for the existing connectivity/dimension probes. - DashScope gains `embedding_text_type_mode` (`auto` / `never`); the default `auto` sends the correct `text_type` per call and skips it for multimodal models. - NVIDIA gains `query_input_type` (default `query`) while `input_type` keeps controlling the document side. Both are opt-outable in case a deployment hits a provider that rejects the extra field. Tests use a fake SDK/HTTP client, so this has not been exercised against the live APIs.
hongdougao111
force-pushed
the
fix/dashscope-nvidia-task-type
branch
from
November 5, 2026 12:23
0fba758 to
9a211e1
Compare
Author
|
Closing this — the diff was polluted by my fork being 9 commits behind upstream, so it showed 42 files instead of 6. I'll resubmit cleanly once the fork is synced. Sorry for the noise. |
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.
Problem
dashscope_embedding_source.pyandnvidia_embedding_source.pyboth embeddedretrieval queries with the document-side encoding mode.
DashScope
The API supports
text_type:query— for user queries, produces vectors optimized for retrievaldocument(default) — for stored text, optimized to be retrievedThe adapter never sent it, so queries were embedded as documents.
The multimodal endpoint is different:
MultiModalEmbedding.callhas notext_typeparameter, so it has to stay excluded.NVIDIA
Their documentation is blunt about this:
The adapter hardcoded a single configured
input_type(defaultpassage) forevery request, so queries were also embedded as passages.
Changes
get_query_embedding().get_embedding()andget_embeddings()keep document semantics — they are used by indexing andby the connectivity/dimension probes in the dashboard, which only need a
vector of the right length.
embedding_text_type_mode(auto/never).autosends the correct
text_typeper call and skips it for multimodal models.query_input_type(defaultquery);input_typecontinuesto control the document side.
the extra field.
Depends on #11012
This is stacked on #11012, which adds the
get_query_embedding()hook onEmbeddingProviderand switchesFaissVecDB.retrieve()to use it. Withoutthat PR the method would exist but never be called. Merge #11012 first, or
review the two together.
Verification
tests/test_embedding_task_types.py, using a fake DashScope SDKand a fake
aiohttpsession.ruff format --check/ruff checkclean.I have no API keys for either provider, so this has not been exercised
against the live APIs. The request-shape assertions are based on the official
documentation and the DashScope SDK signature. If either endpoint rejects the
parameter for some model variant, the
never/ opt-out switch is the escapehatch.