UltraRAG icon indicating copy to clipboard operation
UltraRAG copied to clipboard

fix(custom): escape pipes in r1_searcher_query_extract tag regex

Open Chen17-sq opened this issue 5 months ago • 0 comments

Bug

r1_searcher_query_extract extracts the wrong text because its tag regex has unescaped pipes:

pattern = re.compile(r"<|begin_of_query|>([^<]*)", re.DOTALL)

In a regex | is alternation, so this matches < or begin_of_query or >([^<]*) — not the literal <|begin_of_query|> tag the function intends (and that its docstring documents).

Reproduction

text = "Reasoning... <|begin_of_query|>capital of France<|end_of_query|> done"
r1_searcher_query_extract([text])
# before: {'extract_query_list': ['done?']}              <- trailing text, wrong
# after:  {'extract_query_list': ['capital of France?']}

findall on the buggy pattern returns ['', '', 'capital of France', '', ' done'], and get_query takes matches[-1] → ' done', so the extracted "query" is whatever trails the tag.

Fix

Escape the pipes so the literal tag is matched:

pattern = re.compile(r"<\|begin_of_query\|>([^<]*)", re.DOTALL)

The sibling <search> extractor is unaffected (no pipes).

Tests

Adds tests/servers/custom/test_query_extract.py covering correct extraction, last-query selection, the ? suffix, and the no-tag fallback. pytest is already declared as a dev dependency; these are the first tests in the repo. All 4 pass locally.

Chen17-sq avatar Jun 09 '26 18:06 Chen17-sq