{"id":"7cf7b8a2fc34fec7","repo":"go-redis/redis","slug":"redis-vectorscoreslicecmd-expects-even-number-of","errorCode":null,"errorMessage":"redis: VectorScoreSliceCmd expects even number of elements, got %d","messagePattern":"redis: VectorScoreSliceCmd expects even number of elements, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":8585,"sourceCode":"\ttyp, err := rd.PeekReplyType()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar n int\n\tif typ == proto.RespMap {\n\t\tn, err = rd.ReadMapLen()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\t// RESP2 returns a flat array [name, score, name, score, ...]\n\t\tn, err = rd.ReadArrayLen()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif n%2 != 0 {\n\t\t\treturn fmt.Errorf(\"redis: VectorScoreSliceCmd expects even number of elements, got %d\", n)\n\t\t}\n\t\tn /= 2\n\t}\n\n\tcmd.val = make([]VectorScore, n)\n\tfor i := 0; i < n; i++ {\n\t\tname, err := rd.ReadString()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i].Name = name\n\n\t\tscore, err := rd.ReadFloat()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i].Score = score\n\t}","sourceCodeStart":8567,"sourceCodeEnd":8603,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/command.go#L8567-L8603","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nrdb := redis.NewClient(&redis.Options{Addr: \":6379\"})\nres, err := rdb.VSimWithScores(ctx, \"mykey\", vec).Result()\n\n// after - use RESP3 to get map-structured replies\nrdb := redis.NewClient(&redis.Options{\n    Addr:     \":6379\",\n    Protocol: 3,\n})\nres, err := rdb.VSimWithScores(ctx, \"mykey\", vec).Result()","handlingStrategy":"validation","validationCode":"// Use RESP3 to avoid flat-array pair parsing issues with all VSIM commands\nopts := &redis.Options{\n    Addr:     \":6379\",\n    Protocol: 3,\n}\nrdb := redis.NewClient(opts)","typeGuard":null,"tryCatchPattern":"res, err := rdb.VSimWithScores(ctx, key, vec).Result()\nif err != nil {\n    if strings.Contains(err.Error(), \"expects even number of elements\") {\n        log.Error(\"VSIM RESP2 format mismatch; switch to Protocol:3 or upgrade Redis VectorSet module\")\n    }\n    return nil, err\n}","preventionTips":["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"],"tags":["vectorset","vsim","resp2","parsing","protocol"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}