-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_component.py
36 lines (29 loc) · 1.2 KB
/
query_component.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
from typing import Dict, Any
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class QueryComponent:
def __init__(self):
logger.info("QueryComponent initialized")
def process_query(self, query: str, options: Dict[str, Any] = None) -> Dict[str, Any]:
"""
Process the user query and prepare it for retrieval.
:param query: The user's input query
:param options: Optional parameters for query processing
:return: A dictionary containing the processed query and any additional metadata
"""
try:
logger.info(f"Processing query: {query}")
# Basic query processing: strip whitespace and convert to lowercase
processed_query = query.strip().lower()
# Prepare the result dictionary
result = {
"original_query": query,
"processed_query": processed_query,
"options": options or {}
}
logger.info(f"Query processed successfully: {result}")
return result
except Exception as e:
logger.error(f"Error processing query: {str(e)}", exc_info=True)
raise