Adaptive_Rag / src /components /query /normalization.py
yashvasudeva's picture
Deploy ResearchLens Adaptive RAG (Gradio + FastAPI)
712c393 verified
Raw History Blame Contribute Delete
545 Bytes
from __future__ import annotations
import re
def normalize_query(query: str) -> str:
"""
Sanitize and normalize user queries.
Removes extraneous whitespace, non-printable characters,
and common delimiter injections.
"""
if not query:
return ""
# Remove non-printable control characters except standard space
cleaned = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", query)
# Collapse multiple whitespace
cleaned = re.sub(r"\s+", " ", cleaned).strip()
return cleaned