{"record":{"id":"417a8f09872d57c7","repo":"redis/go-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":8596,"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":8578,"sourceCodeEnd":8614,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L8578-L8614","documentation":"VectorScoreSliceCmd parses VEMB/VSIM-style replies as name/score pairs. Under RESP2 the reply is a flat array that must contain an even number of elements; an odd count means the server sent something the client cannot pair up, so it fails before building the []VectorScore.","triggerScenarios":"Executing a vector-set command returning a flat [name, score, ...] array (RESP2 protocol) where the array length is odd — e.g. a server bug, truncated reply, or calling the parser against an unexpected command output.","commonSituations":"Using Protocol: 2 (RESP2) with Redis vector-set commands; custom/modified server returning unexpected element counts; mixing up commands that return 1 vs 3 fields per element.","solutions":["Use RESP3 (set Protocol: 3 in Options) so vector replies arrive as properly shaped maps/arrays.","Check that you are calling the intended command (VSIM with WITHSCORES vs WITHSCORES+WITHATTRIBS produce different arities).","Upgrade go-redis and Redis server to matching, current versions.","Inspect the raw reply with MONITOR or redis-cli to see what the server actually returns."],"exampleFix":"// before: RESP2 flat array parsing fails on odd length\nrdb := redis.NewClient(&redis.Options{Protocol: 2})\ncmd := rdb.VSimWithScores(ctx, \"pts\", vector)\n\n// after: use RESP3\nrdb := redis.NewClient(&redis.Options{Protocol: 3})\ncmd := rdb.VSimWithScores(ctx, \"pts\", vector)","handlingStrategy":"try-catch","validationCode":"// ensure RESP3 is configured for vector-set commands\nif rdb.Options().Protocol < 3 {\n    // recreate client with Protocol: 3\n}","typeGuard":null,"tryCatchPattern":"cmd := rdb.VSimWithScores(ctx, \"pts\", vec)\nif err := cmd.Err(); err != nil {\n    if strings.Contains(err.Error(), \"expects even number of elements\") {\n        // inspect raw reply and/or switch to RESP3 client\n    }\n    return err\n}","preventionTips":["Use Protocol: 3 (RESP3) for vector-set workloads","Match go-redis and Redis versions supporting vector sets","Verify option flags (WITHSCORES etc.) match the command variant used","Capture raw replies with MONITOR when debugging"],"tags":["redis","vectorset","resp2","reply-parsing"],"backgroundTag":"unexpected-reply-shape","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}