Skip to content
Open
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
20 changes: 17 additions & 3 deletions graphiti_core/driver/falkordb_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,21 @@ def convert_datetimes_to_strings(obj):

def sanitize(self, query: str) -> str:
"""
Replace FalkorDB special characters with whitespace.
Based on FalkorDB tokenization rules: ,.<>{}[]"':;!@#$%^&*()-+=~
Replace FalkorDB/RediSearch special characters with whitespace.

This method is designed for full-text search queries where text is split
into searchable words. Not suitable for exact path matching (e.g., file
paths like '/home/user/file.txt' will become 'home user file txt').

RediSearch (used by FalkorDB for full-text search) has reserved characters
that must be sanitized to prevent query syntax errors:
- Tokenization separators: ,.<>{}[]"':;!@#$%^&*()-+=~?
- Query operators: | (OR), / and \\ (path separators that break queries)

See: https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/escaping/
Related: https://github.com/getzep/graphiti/issues/1144
"""
# FalkorDB separator characters that break text into tokens
# RediSearch separator and operator characters
separator_map = str.maketrans(
{
',': ' ',
Expand Down Expand Up @@ -321,6 +332,9 @@ def sanitize(self, query: str) -> str:
'=': ' ',
'~': ' ',
'?': ' ',
'/': ' ', # Forward slash - causes query syntax errors
'\\': ' ', # Backslash - escape character in RediSearch
'|': ' ', # Pipe - OR operator in RediSearch
}
)
sanitized = query.translate(separator_map)
Expand Down