Skip to content

fix: handle empty filters in redis vector search#4523

Open
Exploreunive wants to merge 2 commits intomem0ai:mainfrom
Exploreunive:fix/redis-search-empty-filters
Open

fix: handle empty filters in redis vector search#4523
Exploreunive wants to merge 2 commits intomem0ai:mainfrom
Exploreunive:fix/redis-search-empty-filters

Conversation

@Exploreunive
Copy link
Copy Markdown

Summary

This PR fixes RedisDB.search() so it no longer crashes when filters are omitted or effectively empty.

Problem

The Redis vector store built a filter expression like this:

conditions = [Tag(key) == value for key, value in filters.items() if value is not None]
filter = reduce(lambda x, y: x & y, conditions)

When filters was:

  • None
  • {}
  • or a dict whose values were all None

conditions became empty and reduce(...) raised an exception.

This makes Redis search less robust than other vector store backends for no-filter / empty-filter calls.

Fix

  • Normalize filters with filters = filters or {}
  • Only build the combined Redis filter expression when at least one non-None condition exists
  • Otherwise pass None as filter_expression

Tests

Added regression coverage in tests/vector_stores/test_redis.py for:

  • filters=None
  • filters={}
  • filters={"user_id": None}

Validation

.venv/bin/python -m pytest -q tests/vector_stores/test_redis.py

Result:

5 passed

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.

1 participant