Skip to content

fix: escape RediSearch special characters in group_id fulltext queries#1295

Open
StephenBadger wants to merge 1 commit intogetzep:mainfrom
StephenBadger:fix/falkordb-redisearch-group-id-escaping
Open

fix: escape RediSearch special characters in group_id fulltext queries#1295
StephenBadger wants to merge 1 commit intogetzep:mainfrom
StephenBadger:fix/falkordb-redisearch-group-id-escaping

Conversation

@StephenBadger
Copy link

Summary

  • Group IDs containing hyphens or other RediSearch special characters (e.g. "my-group", "ap-erp") cause RediSearch: Syntax error in FalkorDB fulltext search queries
  • The hyphen - is interpreted as the RediSearch NOT operator rather than a literal character, even when the value is double-quoted
  • Error manifests as: RediSearch: Syntax error at offset 14 near ap

Fix

  • Added _escape_redisearch_value() helper that backslash-escapes RediSearch special characters (,.<>{}[]"':;!@#$%^&*()-+=~?|/\) before interpolating group_ids into fulltext query strings
  • Applied the fix to both query builder locations:
    • _build_falkor_fulltext_query() in search_ops.py (used by FalkorSearchOperations)
    • FalkorDriver.build_fulltext_query() in falkordb_driver.py (used by search_utils.fulltext_query() fallback path)

Before/After

# Before: RediSearch syntax error
(@group_id:"ap-erp") (search terms)

# After: properly escaped
(@group_id:ap\-erp) (search terms)

Reproduction

  1. Create a Graphiti instance with FalkorDB
  2. Ingest data with group_id="my-group" (any group_id containing a hyphen)
  3. Call search_() or search() with group_ids=["my-group"]
  4. Observe RediSearch: Syntax error

Group IDs containing hyphens or other RediSearch special characters
(e.g. "my-group") cause syntax errors in FalkorDB fulltext search
queries. The hyphen is interpreted as the RediSearch NOT operator
rather than a literal character.

Added _escape_redisearch_value() to backslash-escape special
characters before interpolating group_ids into fulltext query strings.
Applied the fix to both query builder locations:
- _build_falkor_fulltext_query() in search_ops.py
- FalkorDriver.build_fulltext_query() in falkordb_driver.py
@danielchalef
Copy link
Member

danielchalef commented Mar 3, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@StephenBadger
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@StephenBadger
Copy link
Author

recheck

danielchalef added a commit that referenced this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants