Skip to content

bug(mcp): release-date queries exceed reranker batch limit (32) and silently skip the cross-encoder #308

Todo

Description

@karan-panda

Area

mcp

What happened

For release_date intent queries, search_docs_auto fetches up to AUTO_TEMPORAL_CANDIDATE_DEPTH (default 50) hits, and reranker_client.rerank_hits() sends all the hits left after version matching to TEI /rerank in a single request.

TEI's default --max-client-batch-size is 32. docs-agent-mcp/terraform/variables.tf also sets 32, but docs-agent-mcp/terraform/reranker.tf uses $${var...} (double $), which Terraform treats as literal text, so the deployed value can't be confirmed from the repo. With a limit of 32, any request with more than 32 texts gets a 413. The broad except in reranker_client.py prints the error and returns the hits in raw BM25 order, so the only symptom is worse ranking.

Scope today (with a limit of 32):

  • Affected: any release_date query that still has more than 32 hits after version matching. This includes questions without a version (e.g. "When was Katib released?"), and versioned ones where no hit matches or more than 32 match.
  • Not affected by default: "latest" queries (skip the cross-encoder), comparison/exact queries (fetch 30), and general/conceptual queries (fetch top_k, max 20).

Expected behavior

  • Release-date candidates are reranked by the cross-encoder instead of silently falling back to BM25 order.
  • Rerank requests stay within the server's batch limit.
  • A fallback to unranked results is logged as a warning, not only printed.

Proposed fix: split rerank calls into chunks of at most RERANKER_MAX_BATCH (default 32, configurable) and merge the scores before sorting; replace the failure print with a logged warning; add unit tests for the >32 case and the fallback path. If reranking 50 texts is too slow in prod, an alternative is to rerank only the top 32.

Discussed in #kubeflow-doc-agent (CNCF Slack): https://cloud-native.slack.com/archives/C0AF5C85J9J/p1795364263681319?thread_ts=1795336697.288409&cid=C0AF5C85J9J

Reproduction

Local TEI with the settings intended in the Terraform config (text-embeddings-inference:cpu-1.7, BAAI/bge-reranker-base, --max-client-batch-size 32):

  • 32 texts → 200; 33 texts → 413 batch size 33 > maximum allowed batch size 32
  • "When was Katib released?" → release_date intent, 50 hits → Reranker failed: 413; results in raw BM25 order (top hit: the metrics-collector page)
  • "When was Kubeflow 1.9 released?" → works (14 hits after version filtering)

Suspected files

docs-agent-mcp/mcp-server/reranker_client.py, docs-agent-mcp/mcp-server/milvus_search.py, docs-agent-mcp/terraform/reranker.tf

Activity

  1. fizae47-arch commented on Nov 23, 2026

    @fizae47-arch

    /assign

  2. karan-panda commented on Nov 24, 2026

    @karan-panda
    Author

    /assign

    Hi @fizae47-arch, thanks for your interest! I opened this one and asked to work on it in the description, so I'm picking it up.
    I'd be glad to have your review on the PR once it's up.

    /assign

  3. karan-panda commented on Nov 25, 2026

    @karan-panda
    Author

    @tarekabouzeid @Sharkyii I have a batching fix working locally with tests, and I'd like your input before I open the PR.

    Reranking 50 texts took about 46s locally (TEI emulated on an M4 Mac, 2 CPUs), so it's not representative of prod. But RERANKER_TIMEOUT_SEC and the chart's remoteMcp.timeout are both 30s. Today these queries fail fast with a 413. With batching, a slow reranker could use the whole 30s, and the tool call could time out before the fallback returns.

    1. What --max-client-batch-size does prod use? I can't confirm it from the repo (details in the description).
    2. Roughly how long does reranking 30 texts take in prod?
    3. If 50 is too slow, would you prefer (a) batching all candidates, or (b) fetching 50 but reranking only the top 32? I lean towards (a) if prod is fast enough, otherwise (b). Either way, the rerank budget probably needs to be below 30s.

    I'd avoid lowering AUTO_TEMPORAL_CANDIDATE_DEPTH, since "latest" queries use it too. Raising TEI's limit wouldn't reduce the work.

    I've also corrected the description (batch limit source, affected queries, and no truncation needed, since --auto-truncate is already set). I can open a separate issue for the $${var...} problem in reranker.tf.

  4. karan-panda commented on Dec 2, 2026

    @karan-panda
    Author

    Quick update: I have opened a draft PR for this in #311.

    #290 added the reranker config (deploy/platform/reranker/inferenceservice.yaml), and it sets --max-client-batch-size to 32, so the 413 on release-date queries is confirmed.

    The PR batches all candidates for now. @kmr-rohit, if reranking 50 texts turns out too slow in prod, I can switch it to rerank only the top 32. Let me know what you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions