summaryrefslogtreecommitdiff
path: root/rag/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'rag/utils.py')
-rw-r--r--rag/utils.py15
1 files changed, 15 insertions, 0 deletions
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}"'