GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: RAGMiddleware drops all knowledge-base context when one knowledge base cannot embed an attachment · Issue #3975 · agentscope-ai/agentscope

[Bug]: RAGMiddleware drops all knowledge-base context when one knowledge base cannot embed an attachment #3975

New issue
Copy link
New issue
Copy link
Closed
#3976
Closed
[Bug]: RAGMiddleware drops all knowledge-base context when one knowledge base cannot embed an attachment#3975
#3976
Copy link
Labels
triage/confirmedVerified: the reported defect exists

Description

@shuxiachai
shuxiachai
opened on Nov 12, 2026
Issue body actions

Prerequisites

  • I have searched the existing issues and discussions, and this is not a duplicate.
  • This is a bug, not a usage question.

Related: #3649 and #3656 cover sibling vector queries inside one KnowledgeBase.search. This issue is about separate knowledge bases in RAGMiddleware. I found no issue or pull request for it.

Background / Description

RAGMiddleware takes several knowledge bases, and they may use different embedding models (source). In static mode it searches all of them with the user's turn, attachments included. _search_across relies on each knowledge base to drop the inputs its model cannot use (source), but KnowledgeBase.search drops DataBlocks only for text-only models (source). A multimodal model can still reject a block. For example, DashScopeEmbeddingModel raises ValueError while building the request for any media type other than image/* or video/*, such as a PDF (source).

_search_across gathers the per-knowledge-base searches without isolating failures (source), so that one ValueError aborts the whole search. The static-mode handler then logs it and continues without any context (source). A text knowledge base that matched the question contributes nothing either.

For example, take a support agent with a text knowledge base of store policies and an image knowledge base of product photos. A customer attaches an invoice PDF and asks about returns. The agent answers without the return policy, and the only trace is an ERROR log line. The same coupling applies when one knowledge base fails for any other reason, such as an unavailable embedding provider or vector store. In agentic mode the queries are text only, but there too one failing knowledge base makes the search_knowledge tool return Search failed: ... instead of the other knowledge bases' hits (source).

Expected behavior: a knowledge base whose search fails is logged and skipped, and the others still contribute, much as a failing reranker already falls back to the vector order (source). When every knowledge base fails, the current behavior can stay.

Error Messages / Observed Behavior

The reproduction below prints:

policies         : 1 hint(s), has the return policy: True
policies+catalog : 0 hint(s), has the return policy: False
catalog.search   : ValueError: Unsupported media type 'application/pdf' in DataBlock. Expected image/* or video/*.
DashScope API calls: 0

The first line is the control: the same message with only the text knowledge base. In the second run the middleware logs:

ERROR   | _rag:on_reasoning:991 - Knowledge-base search failed; proceeding without matched context.
Traceback (most recent call last):
  ...
ValueError: Unsupported media type 'application/pdf' in DataBlock. Expected image/* or video/*.

Steps to Reproduce

  1. Save this as repro_rag_kb_failure.py:
"""RAGMiddleware static mode: one knowledge base that cannot embed an
attachment drops the context of every knowledge base.

Runs offline: the DashScope multimodal model rejects the PDF block while
building the request, before any API call.
"""
import asyncio
from types import SimpleNamespace

import dashscope

from agentscope.credential import DashScopeCredential
from agentscope.embedding import DashScopeEmbeddingModel, EmbeddingResponse
from agentscope.message import (
    Base64Source,
    DataBlock,
    HintBlock,
    Msg,
    TextBlock,
)
from agentscope.middleware import RAGMiddleware
from agentscope.rag import Chunk, KnowledgeBase, QdrantStore, VectorRecord

api_calls = []
dashscope.MultiModalEmbedding.call = lambda **kw: api_calls.append(kw)


class TextEmbedding:
    """Offline stand-in for a text-only embedding model."""

    supports_multimodal = False
    dimensions = 3

    async def __call__(self, inputs):
        return EmbeddingResponse(embeddings=[[1.0, 0.0, 0.0]] * len(inputs))


async def hints_seen(knowledge_bases, msg):
    """Run one static-mode reply; return the hints the model would see."""
    middleware = RAGMiddleware(
        knowledge_bases=knowledge_bases,
        parameters=RAGMiddleware.Parameters(mode="static"),
    )
    context, seen = [], []

    def append_context(name, blocks):
        carrier = Msg(name=name, role="assistant", content=blocks)
        carrier.id = "reply-1"
        context.append(carrier)

    state = SimpleNamespace(context=context, reply_id="reply-1",
                            session_id="s-1", cur_iter=0,
                            append_context=append_context)
    agent = SimpleNamespace(name="assistant", state=state)

    async def reasoning(**_):
        seen.extend(b.hint for m in context for b in m.content
                    if isinstance(b, HintBlock))
        yield "reasoning"

    async def reply(**_):
        async for evt in middleware.on_reasoning(
            agent=agent, input_kwargs={}, next_handler=reasoning,
        ):
            yield evt

    async for _ in middleware.on_reply(
        agent=agent, input_kwargs={"inputs": msg}, next_handler=reply,
    ):
        pass
    return seen


async def main():
    async with QdrantStore(location=":memory:") as store:
        await store.create_collection("policies", dimensions=3)
        await store.insert("policies", [VectorRecord(
            vector=[1.0, 0.0, 0.0],
            document_id="returns",
            chunk=Chunk(
                content=TextBlock(text="Items can be returned within 30 days."),
                source="returns.md", chunk_index=0, total_chunks=1,
            ),
        )])
        policies = KnowledgeBase(
            name="policies", description="Store policies.",
            embedding_model=TextEmbedding(),
            vector_store=store, collection="policies",
        )
        catalog = KnowledgeBase(
            name="catalog", description="Product photos.",
            embedding_model=DashScopeEmbeddingModel(
                credential=DashScopeCredential(api_key="sk-offline"),
                model="multimodal-embedding-v1", dimensions=1024,
            ),
            vector_store=store, collection="catalog",
        )
        question = TextBlock(text="How long do I have to return this order?")
        invoice = DataBlock(source=Base64Source(
            media_type="application/pdf", data="JVBERi0xLjQK",
        ))
        msg = Msg(name="user", role="user", content=[question, invoice])

        for kbs in ([policies], [policies, catalog]):
            hints = await hints_seen(kbs, msg)
            print(f"{'+'.join(kb.name for kb in kbs):<17}: "
                  f"{len(hints)} hint(s), "
                  f"has the return policy: {any('30 days' in h for h in hints)}")
        try:
            await catalog.search([question, invoice])
        except ValueError as e:
            print(f"catalog.search   : ValueError: {e}")
        print(f"DashScope API calls: {len(api_calls)}")


asyncio.run(main())
  1. From a checkout of main at 6047bc00f1ba0461b5833c4861cef0e050b0bfea (2.0.12dev), run:
python -m pip install -e ".[vdb-qdrant]"
python repro_rag_kb_failure.py

No network access or credentials are needed. The API key is a placeholder, and the script replaces the DashScope SDK call with a counter, which stays at 0.

Environment

  • AgentScope: 2.0.12dev, main commit 6047bc00f1ba0461b5833c4861cef0e050b0bfea.
  • Python: 3.11.9, with qdrant-client 1.19.1 and dashscope 1.27.7.
  • OS: Windows.

Proposed Scope

Would it fit for _search_across to gather with return_exceptions=True, log each failing knowledge base by name, merge the others' results, and re-raise only when every knowledge base failed? CancelledError and other non-Exception errors would still propagate. Both modes share the helper, so agentic mode would then return the working knowledge bases' hits. If you would rather the tool result also name the skipped ones, I can add that. I can add regression tests for a failing knowledge base next to a working one, both in _search_across and through static mode, and for the case where all of them fail.

A single multimodal knowledge base would still lose the text part of such a turn, because all inputs go into one embedding call. Skipping blocks outside the model card's input_types could address that, but it needs a new capability check on the embedding model, so I would leave it out of this issue.

Claude Code assisted with source inspection, duplicate searches, and the offline reproduction. I have not started a fix.

Activity

  1. github-actions
    added
    triage/verifyingA bot is verifying whether this bug is real
    triage/confirmedVerified: the reported defect exists
    and removed
    triage/verifyingA bot is verifying whether this bug is real
    on Nov 12, 2026
  2. 2SinceJuly commented on Nov 12, 2026

    @2SinceJuly
    2SinceJuly
    on Nov 12, 2026
    Contributor
    More actions

    Fix is up in #3976, along the lines of your proposed scope: _search_across gathers with return_exceptions=True, logs each failing knowledge base by name and skips it, and re-raises only when every knowledge base failed. Non-Exception errors such as CancelledError still propagate.

    Regression tests cover a failing knowledge base next to a working one, the all-fail case, and cancellation. Your repro now prints policies+catalog : 1 hint(s), has the return policy: True.

    I left the multimodal-block-skipping capability check out, matching how you scoped this issue.

  3. qbc2016
    closed this as completedin #3976on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/confirmedVerified: the reported defect exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.