Extract a compact search query from the user's message. Strips filler words, keeps technical terms and intent keywords. Capped at max_words to avoid over-querying the KB. Args: user_message: Raw user message max_words: Max query terms to keep Returns:
(user_message: str, max_words: int = 15)
| 37 | |
| 38 | |
| 39 | def extract_query(user_message: str, max_words: int = 15) -> str: |
| 40 | """ |
| 41 | Extract a compact search query from the user's message. |
| 42 | |
| 43 | Strips filler words, keeps technical terms and intent keywords. |
| 44 | Capped at max_words to avoid over-querying the KB. |
| 45 | |
| 46 | Args: |
| 47 | user_message: Raw user message |
| 48 | max_words: Max query terms to keep |
| 49 | |
| 50 | Returns: |
| 51 | Space-separated query string |
| 52 | """ |
| 53 | # Remove non-alphanumeric except spaces and common code chars |
| 54 | cleaned = re.sub(r"[^\w\s\.\-/_]", " ", user_message.lower()) |
| 55 | words = cleaned.split() |
| 56 | query_words = [w for w in words if w not in _FILLER and len(w) > 2] |
| 57 | return " ".join(query_words[:max_words]) |
| 58 | |
| 59 | |
| 60 | def retrieve(user_message: str, budget_chars: int = None) -> str: |
no outgoing calls
no test coverage detected