From 734b89570040e97f0c7743c4c0bc28e30a3cd4ee Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 24 Sep 2025 23:38:36 +0700 Subject: init --- rag/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rag/utils.py (limited to 'rag/utils.py') diff --git a/rag/utils.py b/rag/utils.py new file mode 100644 index 0000000..10519a4 --- /dev/null +++ b/rag/utils.py @@ -0,0 +1,15 @@ +import re + +FTS_META_CHARS = r'''["'*()^+-]''' # include ? if you see issues + +def sanitize_query(q: str, *, allow_ops: bool = False) -> str: + q = q.strip() + if not q: + return q + if allow_ops: + # escape stray double quotes inside, then wrap + q = q.replace('"', '""') + return f'"{q}"' + # literal search: quote and escape special chars + q = re.sub(r'"', '""', q) + return f'"{q}"' -- cgit v1.2.3