I'm building a .NET 8 demo that stores OpenAI text embeddings in Redis Stack and performs similarity search with FT.SEARCH (KNN over HNSW vector index).
The setup works for indexing and upserting data, but FT.SEARCH consistently times out even after increasing client timeouts and limiting HNSW runtime parameters.
The Redis server responds to PING instantly, and all embeddings are dimensionally consistent (1536 for text-embedding-3-small).
The timeout happens inside the SearchTopK method when running this query:
FT.SEARCH idx:documents "*=>[KNN $K @vector_field $BLOB EF_RUNTIME 16 AS score]" PARAMS 2 K 2 BLOB <bytes> RETURN 2 text_field score SORTBY score ASC DIALECT 2
The error:
StackExchange.Redis.RedisTimeoutException HResult=0x80131505 Message=Timeout awaiting response (outbound=0KiB, inbound=0KiB, 20125ms elapsed, timeout is 20000ms), command=FT.SEARCH, next: FT.SEARCH, inst: 0, qu: 0, qs: 1, aw: False, bw: Inactive, rs: ReadAsync, ws: Idle, in: 0, in-pipe: 0, out-pipe: 0, last-in: 2, cur-in: 0, sync-ops: 0, async-ops: 5, serverEndpoint: localhost:6379, conn-sec: 39.31, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: ATHENA(SE.Redis-v2.9.32.54708), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=16,Max=32767), POOL: (Threads=2,QueuedItems=0,CompletedItems=88,Timers=3), v: 2.9.32.54708 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts) Source=RedisDemo StackTrace: at Program.d__8.MoveNext() in
What I have verified so far:
Redis connection health
Confirmed that Redis Stack container is running and healthy.
PING returns PONG immediately.
No errors or warnings in docker logs redis-stack.
Container memory usage stable (~20 MB), CPU spikes only during FT.SEARCH.
Index creation and schema validation
Verified that the index idx:documents exists and is fully built:
FT.INFO idx:documents dim = 1536 distance_metric = COSINE indexing = 0 (not rebuilding) percent_indexed = 1 (complete) algorithm = HNSW (M=16, ef_construction=200)Index definition in code matches Redis schema exactly:
FT.CREATE idx:documents ON HASH PREFIX 1 "doc:" SCHEMA text_field TEXT WEIGHT 1.0 vector_field VECTOR HNSW 6 TYPE FLOAT32 DIM 1536 DISTANCE_METRIC COSINEData consistency and embedding validation
Verified documents were inserted:
KEYS doc:* → doc:1, doc:2, doc:3Verified each document hash structure:
HGETALL doc:1Contains both
text_fieldandvector_field.Verified vector byte length:
HSTRLEN doc:1 vector_field = 6144 → 6144 / 4 = 1536, confirming FLOAT32 × 1536 dims.No index errors or rebuilds (hash_indexing_failures = 0).
Query embedding validation
The query embedding generated using OpenAI’s text-embedding-3-small model has length 1536.
Program prints:
DEBUG: query embedding length = 1536. Expected DIM = 1536
→ Confirms perfect dimension match between stored vectors, query embedding, and index schema.
Client configuration and timeout adjustments
Using StackExchange.Redis v2.9.32.
Configured connection options:
var config = new ConfigurationOptions { EndPoints = { "localhost:6379" }, AbortOnConnectFail = false, ConnectTimeout = 10000, SyncTimeout = 20000, ClientName = "redisdemo-ATHENA" };Despite 20 second timeout, FT.SEARCH still times out around 20.1 s.
The timeout consistently occurs inside:
await db.ExecuteAsync("FT.SEARCH", redisArgs);Confirmed no network drop or connection loss (all other Redis operations succeed instantly).
Query optimization attempts
Added EF_RUNTIME parameter to limit HNSW runtime effort:
Tried EF_RUNTIME 64
Tried EF_RUNTIME 16Both attempts still resulted in RedisTimeoutException around 20 s.
Verified that commands reach Redis (seen via CLIENT LIST and CPU spike), but Redis doesn’t respond within the client’s timeout window.
Elimination of common root causes
No vector dimension mismatch.
No missing or rebuilding index.
No missing document hashes.
No OpenAI embedding issues (embedding call succeeds for all documents).
No container resource exhaustion (CPU spike localized to FT.SEARCH).
No SLOWLOG entries generated (SLOWLOG GET empty).
Summary of current state
All data, embeddings, and index configurations are consistent. FT.SEARCH is the only operation timing out after ~20 s despite small dataset (3 docs) and low EF_RUNTIME.
This strongly suggests a Redis-side blocking condition or an issue in how StackExchange.Redis handles binary vector parameters during FT.SEARCH.