Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions redisvl/utils/token_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class TokenEscaper:
"""

# Characters that RediSearch requires us to escape during queries.
# Source: https://redis.io/docs/stack/search/reference/escaping/#the-rules-of-text-field-tokenization
DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]"
# Source: https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/escaping/#tokenization-rules-for-text-fields
DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ \?]"

# Same as above but excludes * to allow wildcard patterns
# Same as above but excludes * and ? to allow wildcard patterns
ESCAPED_CHARS_NO_WILDCARD = r"[,.<>{}\[\]\\\"\':;!@#$%^&()\-+=~\/ ]"

def __init__(self, escape_chars_re: Optional[Pattern] = None):
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_token_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def escaper():
),
(
r"& symbols, like * and ?",
r"\&\ symbols\,\ like\ \*\ and\ ?",
), # TODO: question marks are not caught?
r"\&\ symbols\,\ like\ \*\ and\ \?",
),
# underscores are ignored
(r"-dashes_and_underscores-", r"\-dashes_and_underscores\-"),
],
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_escape_text_chars(escaper, test_input, expected):
("(parentheses)", r"\(parentheses\)"),
("[brackets]", r"\[brackets\]"),
("{braces}", r"\{braces\}"),
# ("question?mark", r"question\?mark"), #TODO - question marks are not caught?
("question?mark", r"question\?mark"),
# Unicode characters in tags
("你好", r"你好"), # Assuming non-Latin characters don't need escaping
("emoji:😊", r"emoji\:😊"),
Expand All @@ -81,6 +81,7 @@ def test_escape_text_chars(escaper, test_input, expected):
"parentheses",
"brackets",
"braces",
"question",
"non-latin",
"emoji",
],
Expand Down
Loading