Overview
TheQueryDecomposer class analyzes user queries and extracts structured information including intent, entities, constraints, and temporal expressions. This decomposition enables the retrieval system to understand what the user is looking for and target relevant document sections.
Class Definition
Methods
decompose
Decomposes a natural language query into structured components.The natural language query to decompose
The detected intent category. One of:
penalty- Late fees, overdue paymentspayment_terms- Payment schedules, invoicesintellectual_property- IP rights, licenses, ownershipindemnification- Third-party claims, liabilitytermination- Contract termination clausesconfidentiality- Confidential information handlingscope_of_services- Service definitions and obligationsunknown- No matching intent found
Extracted entities (significant words excluding stopwords)
Extracted temporal expressions (dates, deadlines)
Example
Private Helper Methods
_extract_intent
Matches query against regex patterns to determine intent category._extract_entities
Extracts significant words from the query, filtering out stopwords._extract_constraints
Extracts structured constraints like timeframes and percentages.- Timeframe:
r"\bwithin (\d+ (days|weeks|months|years))\b" - Percentage:
r"\b(\d+(\.\d+)?)%\b"
_extract_temporals
Extracts date expressions with temporal keywords.r"\b(on|by|before|after) (\w+ \d{1,2}(, \d{4})?)\b"
Example:
Usage Example
Integration
The decomposition result is passed to theAgenticRetriever to enable intent-based section targeting and relevance scoring.