go-redis/redis · error
redis: VectorScoreSliceCmd expects even number of elements,
Error message
redis: VectorScoreSliceCmd expects even number of elements, got %d
What it means
Returned by VectorScoreSliceCmd.readReply (command.go:8585) when parsing a RESP2 reply from VSimWithScores or VSimWithArgsWithScores. In RESP2 the server returns a flat array of [name, score, name, score, ...] pairs; an odd element count means the name/score pairing is broken. Under RESP3 the reply is a proper map and this code path is not reached.
Source
Thrown at command.go:8585
typ, err := rd.PeekReplyType()
if err != nil {
return err
}
var n int
if typ == proto.RespMap {
n, err = rd.ReadMapLen()
if err != nil {
return err
}
} else {
// RESP2 returns a flat array [name, score, name, score, ...]
n, err = rd.ReadArrayLen()
if err != nil {
return err
}
if n%2 != 0 {
return fmt.Errorf("redis: VectorScoreSliceCmd expects even number of elements, got %d", n)
}
n /= 2
}
cmd.val = make([]VectorScore, n)
for i := 0; i < n; i++ {
name, err := rd.ReadString()
if err != nil {
return err
}
cmd.val[i].Name = name
score, err := rd.ReadFloat()
if err != nil {
return err
}
cmd.val[i].Score = score
}View on GitHub (pinned to 36d97525cd)
Solutions
- Set Protocol: 3 in redis.Options so VSIM returns a structured RESP3 map, bypassing flat-array pair parsing entirely
- Upgrade Redis and the VectorSet module to a version whose VSIM reply format matches this go-redis release
- Verify the server actually supports the VectorSet module and the WITHSCORES option
Example fix
// before
rdb := redis.NewClient(&redis.Options{Addr: ":6379"})
res, err := rdb.VSimWithScores(ctx, "mykey", vec).Result()
// after - use RESP3 to get map-structured replies
rdb := redis.NewClient(&redis.Options{
Addr: ":6379",
Protocol: 3,
})
res, err := rdb.VSimWithScores(ctx, "mykey", vec).Result() Defensive patterns
Strategy: validation
Validate before calling
// Use RESP3 to avoid flat-array pair parsing issues with all VSIM commands
opts := &redis.Options{
Addr: ":6379",
Protocol: 3,
}
rdb := redis.NewClient(opts) Try / catch
res, err := rdb.VSimWithScores(ctx, key, vec).Result()
if err != nil {
if strings.Contains(err.Error(), "expects even number of elements") {
log.Error("VSIM RESP2 format mismatch; switch to Protocol:3 or upgrade Redis VectorSet module")
}
return nil, err
} Prevention
- Use Protocol:3 for all VectorSet commands to get structured RESP3 map replies
- Keep Redis server and go-redis versions aligned for VectorSet module compatibility
- Test VSIM commands in a staging environment after server upgrades
When it happens
Trigger: Calling VSimWithScores or VSimWithArgsWithScores (VSIM key ... WITHSCORES) while the client is using RESP2 (the default) and the server returns an array with an odd number of elements.
Common situations: VectorSet module version mismatch where the server's VSIM reply format differs from what go-redis expects; a RESP-intermediating proxy mangling the flat array; a server-side bug in the VECTORSET module's VSIM WITHSCORES serialization.
Related errors
- redis: got %d elements in the VLINKS array, wanted a multipl
- redis: got %d elements in the VSIM array, wanted a multiple
- redis: got %d elements in the VSIM array, wanted a multiple
- redis: can't parse reply=%T reading string
- invalid term format
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/7cf7b8a2fc34fec7.json.
Report an issue: GitHub.