Skip to content

fix: critical bug fixes in query extraction, FAISS search, and MCP config#425

Open
zhengdaqi wants to merge 1 commit into
OpenBMB:mainfrom
zhengdaqi:fix/critical-bug-fixes
Open

fix: critical bug fixes in query extraction, FAISS search, and MCP config#425
zhengdaqi wants to merge 1 commit into
OpenBMB:mainfrom
zhengdaqi:fix/critical-bug-fixes

Conversation

@zhengdaqi
Copy link
Copy Markdown
Contributor

Summary

Six bug fixes for correctness issues that produce wrong results or crash at runtime. All fixes are non-breaking for valid inputs.

1. Broken regex in r1_searcher_query_extract (95/100 severity)

The regex pattern r"<|begin_of_query|>([^<]*)" treats | as alternation, so it matches < OR b OR e OR ... instead of the literal token <|begin_of_query|>. This completely breaks query extraction in the Search-R1 pipeline.

Fix: Escape the pipes → r"<\|begin_of_query\|>([^<]*)".

2. Remote MCP server config stored as tuple (90/100)

A trailing comma turns the config into a 1-tuple (dict,) instead of a dict:

# Before (bug): creates a tuple
mcp_servers[name] = ({...},)

# After (fix): creates a dict  
mcp_servers[name] = {...}

This affects both build() and load_pipeline_context(), breaking all HTTP/HTTPS remote MCP server configurations.

3. FAISS search returns wrong passages (85/100)

IndexIDMap.search() returns -1 for padding when fewer than top_k neighbors exist. The code used self.contents[-1], silently returning the last document instead of filtering the padding.

4. _surveycpm_to_one_line() content duplication (78/100)

The function concatenated content with a recursive call on the same content string, producing doubled output text:

# Before: "[OK] content" + "content" (duplicated)
return "[OK] " + string["content"]... + _surveycpm_to_one_line(string["content"])

# After: "[OK] content" (correct)
return "[OK] " + string["content"].replace("\n", " ").strip()

5. Exa web search uses "EMPTY" API key silently (73/100)

When EXA_API_KEY is not configured, the backend silently set api_key="EMPTY", leading to confusing 401 errors at search time. Now raises ToolError with a clear message immediately, consistent with the Tavily backend's behavior.

6. evaluate_trec_pvalue crashes when metrics is None (72/100)

The function signature allows metrics: List[str] | None, but the loop for m in metrics raises TypeError when None is passed. Added a default metrics list.

Test Plan

  • Run pytest to verify no regressions
  • Verify Search-R1 query extraction with <|begin_of_query|> tokens
  • Verify FAISS search with small indices (< top_k documents)
  • Test remote MCP server config with HTTP endpoints
  • Test Exa backend initialization without API key configured

Made with Cursor

…nfig

- Fix broken regex in r1_searcher_query_extract: unescaped `|` in
  `<|begin_of_query|>` was treated as regex alternation, causing the
  pattern to never match the intended token
- Fix FAISS search returning wrong passages when fewer than top_k
  neighbors exist (-1 padding indices were used to index contents)
- Fix remote MCP server config stored as tuple instead of dict due to
  trailing comma in both build() and load_pipeline_context()
- Fix _surveycpm_to_one_line() duplicating content by concatenating the
  same text with an unnecessary recursive call
- Fix evaluate_trec_pvalue crashing when metrics parameter is None
  (function signature allows None but loop body did not guard it)
- Fix Exa web search backend silently using "EMPTY" as API key; now
  raises ToolError with a clear message, consistent with Tavily backend

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant