microsoft / microsoft/semantic-kernel

Python: Bug: Redis connector sends malformed `FT.CREATE PREFIX` (one prefix per character of collection name)

Open Beginner friendly
#13,894 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug python
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.

  1. Install Python SK per (python/DEV_SETUP.md):
    cd python && make install-sk PYTHON_VERSION=3.12
    
  2. Start Redis Stack on port 6379. Example:
    podman run -d -p 6379:6379 docker.io/redis/redis-stack:latest
    
  3. In a separate terminal, attach MONITOR to the server:
    redis-cli -h localhost -p 6379 MONITOR
    
  4. 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
    
  5. Inspect the MONITOR output for the FT.CREATE lines. Each one contains PREFIX <N> where N equals 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: main branch of microsoft/semantic-kernel (SK version 1.41.2 as reported by semantic_kernel.__version__)
  • redis-py version: 6.4.0
  • Backends tested:
    • Redis Stack 7.4.7 (RediSearch v21020, ReJSON v20809) — bug is silent, FT.CREATE accepted
  • 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.