microsoft / microsoft/semantic-kernel
Python: Bug: Redis connector sends malformed `FT.CREATE PREFIX` (one prefix per character of collection name)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 14h 13m
- Merged PRs (30d)
- 18
Description
Describe the bug
The Python Redis connector sends FT.CREATE with the PREFIX argument split into one prefix per character of the collection name, instead of one prefix equal to "<collection_name>:".
Example observed on the wire for a collection named redis_json_list_data_model:
FT.CREATE redis_json_list_data_model ON JSON
PREFIX 27 r e d i s _ j s o n _ l i s t _ d a t a _ m o d e l :
SCORE 1.0 SCHEMA ...
RediSearch on Redis Stack silently accepts the malformed command and the connector appears to work for simple single-collection usage.
Root cause (client-side): python/semantic_kernel/connectors/redis.py:281 passes a plain string to redis-py's IndexDefinition(prefix=...). redis-py treats that argument as an iterable of prefixes and iterates the string character-by-character.
Expected behavior
FT.CREATE for an SK-managed collection should register exactly one key-space prefix equal to "<collection_name>:", so that the index only matches keys written for this collection.
FT.CREATE redis_json_list_data_model ON JSON
PREFIX 1 redis_json_list_data_model:
SCORE 1.0 SCHEMA ...
To Reproduce
Prerequisites: a Redis Stack server reachable on localhost:6379, redis-cli, and a working Python SK dev environment.
- Install Python SK per (
python/DEV_SETUP.md):cd python && make install-sk PYTHON_VERSION=3.12 - Start Redis Stack on port 6379. Example:
podman run -d -p 6379:6379 docker.io/redis/redis-stack:latest - In a separate terminal, attach
MONITORto the server:redis-cli -h localhost -p 6379 MONITOR - From
python/, run the Redis integration tests:REDIS_CONNECTION_STRING="redis://localhost:6379" \ uv run pytest tests/integration/memory/test_vector_store.py -k redis -v - Inspect the
MONITORoutput for theFT.CREATElines. Each one containsPREFIX <N>whereNequals the length of the collection name, followed by that many single-character prefixes.
On Redis Stack the tests pass (the bug is silent).
Platform
- Language: Python
- Source:
mainbranch ofmicrosoft/semantic-kernel(SK version1.41.2as reported bysemantic_kernel.__version__) redis-pyversion: 6.4.0- Backends tested:
- Redis Stack 7.4.7 (RediSearch v21020, ReJSON v20809) — bug is silent,
FT.CREATEaccepted
- Redis Stack 7.4.7 (RediSearch v21020, ReJSON v20809) — bug is silent,
- AI model: [e.g. OpenAI:GPT-4o-mini(2024-07-18)]
- IDE: Kiro
- OS: macOS 25.4.0 (Darwin), arm64
Additional context
Correctness on Redis: indexes register unintended single-character prefixes. In multi-collection deployments on a shared Redis, collections whose names share any character will register overlapping prefixes and can match each other's keys.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at python/semantic_kernel/connectors/redis.py:281 and inspect how IndexDefinition receives the collection prefix. Run the Redis integration test at tests/integration/memory/test_vector_store.py with -k redis while monitoring Redis with redis-cli MONITOR. Done means FT.CREATE shows PREFIX 1 followed by the complete collection_name: prefix rather than one prefix per character.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, redis
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100