nikeshn commited on
Commit
f6e8df5
Β·
verified Β·
1 Parent(s): c3983ed

Update src/api/agent.py

Browse files
Files changed (1) hide show
  1. src/api/agent.py +20 -5
src/api/agent.py CHANGED
@@ -1575,6 +1575,7 @@ def _light_strip_retrieval_boilerplate(text: str) -> str:
1575
  cleaned = re.sub(r"^\s*please\s+", "", cleaned, flags=re.IGNORECASE)
1576
  cleaned = re.sub(r"\s+(please|thanks|thank you|asap)$", "", cleaned, flags=re.IGNORECASE)
1577
  # Strip search intent verbs β€” these are action signals, not topic content
 
1578
  cleaned = re.sub(
1579
  r"^\s*(find|search for|search|look for|get me|show me|give me|fetch|retrieve|"
1580
  r"research on|articles on|papers on|literature on|studies on|"
@@ -1583,6 +1584,18 @@ def _light_strip_retrieval_boilerplate(text: str) -> str:
1583
  r"i want articles on|i need papers on|i want papers on)\s+",
1584
  "", cleaned, flags=re.IGNORECASE
1585
  )
 
 
 
 
 
 
 
 
 
 
 
 
1586
  return re.sub(r"\s+", " ", cleaned).strip()
1587
 
1588
 
@@ -1751,16 +1764,18 @@ async def _build_search_plan(question: str, model: str) -> dict:
1751
  light_query = _light_strip_retrieval_boilerplate(raw_query) or raw_query
1752
 
1753
  # ── Ambiguity gate ────────────────────────────────────────────────────────
1754
- # After stripping intent verbs, check if what remains is meaningful enough
1755
- # to build a boolean query. Numbers, single characters, and very short tokens
1756
- # cannot produce a useful search and should prompt clarification.
1757
  _stripped = light_query.strip()
1758
  _is_pure_number = bool(re.fullmatch(r"[\d\s\.\,\-\/]+", _stripped))
1759
  _is_too_short = len(_stripped) < 2
1760
  _is_single_char = bool(re.fullmatch(r"[a-zA-Z0-9]", _stripped))
 
 
 
1761
 
1762
- if _is_pure_number or _is_too_short or _is_single_char:
1763
- _display = _escaped = _stripped or raw_query
1764
  return {
1765
  "corrected": raw_query,
1766
  "natural": light_query,
 
1575
  cleaned = re.sub(r"^\s*please\s+", "", cleaned, flags=re.IGNORECASE)
1576
  cleaned = re.sub(r"\s+(please|thanks|thank you|asap)$", "", cleaned, flags=re.IGNORECASE)
1577
  # Strip search intent verbs β€” these are action signals, not topic content
1578
+ # Pass 1: strip leading intent verb phrases (including compound forms)
1579
  cleaned = re.sub(
1580
  r"^\s*(find|search for|search|look for|get me|show me|give me|fetch|retrieve|"
1581
  r"research on|articles on|papers on|literature on|studies on|"
 
1584
  r"i want articles on|i need papers on|i want papers on)\s+",
1585
  "", cleaned, flags=re.IGNORECASE
1586
  )
1587
+ # Pass 2: strip residual noun boilerplate left after pass 1
1588
+ # e.g. "find research on 33" β†’ pass1 β†’ "research on 33" β†’ pass2 β†’ "33"
1589
+ cleaned = re.sub(
1590
+ r"^\s*(research|articles?|papers?|books?|literature|studies|study|"
1591
+ r"journals?|publications?|resources?)\s+(on|about|for|regarding|into)\s+",
1592
+ "", cleaned, flags=re.IGNORECASE
1593
+ )
1594
+ # Pass 3: strip dangling prepositions after intent removal
1595
+ cleaned = re.sub(
1596
+ r"^\s*(on|about|for|regarding|concerning|into|around|of|in|the)\s+",
1597
+ "", cleaned, flags=re.IGNORECASE
1598
+ )
1599
  return re.sub(r"\s+", " ", cleaned).strip()
1600
 
1601
 
 
1764
  light_query = _light_strip_retrieval_boilerplate(raw_query) or raw_query
1765
 
1766
  # ── Ambiguity gate ────────────────────────────────────────────────────────
1767
+ # After stripping intent verbs and prepositions, check if what remains
1768
+ # is meaningful enough to build a boolean query.
 
1769
  _stripped = light_query.strip()
1770
  _is_pure_number = bool(re.fullmatch(r"[\d\s\.\,\-\/]+", _stripped))
1771
  _is_too_short = len(_stripped) < 2
1772
  _is_single_char = bool(re.fullmatch(r"[a-zA-Z0-9]", _stripped))
1773
+ # Check if remaining words are all numbers/single chars β€” no real content words
1774
+ _content_words = [w for w in _stripped.split() if len(w) > 1 and not re.fullmatch(r"[\d\.\,\-]+", w)]
1775
+ _no_content = len(_content_words) == 0 and len(_stripped) > 0
1776
 
1777
+ if _is_pure_number or _is_too_short or _is_single_char or _no_content:
1778
+ _display = _stripped or raw_query
1779
  return {
1780
  "corrected": raw_query,
1781
  "natural": light_query,