{"record":{"id":"9ab4dee9d2fe53f5","repo":"redis/go-redis","slug":"redis-got-d-elements-in-the-vsim-array-wanted-a-9ab4de","errorCode":null,"errorMessage":"redis: got %d elements in the VSIM array, wanted a multiple of 3","messagePattern":"redis: got (.+?) elements in the VSIM array, wanted a multiple of 3","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":8923,"sourceCode":"\t\t\tscore, err := rd.ReadFloat()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tattrib, err := readVectorAttribStringOrNil(rd)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcmd.val[i] = VectorScoreAttrib{Name: name, Score: score, Attribs: attrib}\n\t\t}\n\t\treturn nil\n\t}\n\n\tn, err := rd.ReadArrayLen()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif n%3 != 0 {\n\t\treturn fmt.Errorf(\"redis: got %d elements in the VSIM array, wanted a multiple of 3\", n)\n\t}\n\tcmd.val = make([]VectorScoreAttrib, n/3)\n\tfor i := range cmd.val {\n\t\tname, err := rd.ReadString()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tscore, err := rd.ReadFloat()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tattrib, err := readVectorAttribStringOrNil(rd)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tcmd.val[i] = VectorScoreAttrib{Name: name, Score: score, Attribs: attrib}\n\t}\n\treturn nil","sourceCodeStart":8905,"sourceCodeEnd":8941,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/command.go#L8905-L8941","documentation":"VSIM replies parsed into VectorScoreAttrib values contain name/score/attribute triples, so the array length must be a multiple of 3. Any other count means the reply shape does not match the requested options and parsing fails immediately.","triggerScenarios":"Calling VSIM with both WITHSCORES and WITHATTRIBS (the tri-field parser at command.go:~8923) and receiving an array whose length is not divisible by 3.","commonSituations":"Server returning fewer fields per element (e.g. attribs dropped for large attributes) causing arity mismatch; version skew between client expectations and server vector-set implementation; proxies altering the reply.","solutions":["Confirm the server supports attributes in VSIM replies and is not silently dropping them (redis-cli VSIM ... WITHSCORES WITHATTRIBS).","Use RESP3 (Protocol: 3) so the reply structure is explicit.","Upgrade go-redis and the Redis server to matching current versions.","If only scores are needed, switch to the score-only variant so a 2-field reply parses correctly."],"exampleFix":"// before: server drops attribs -> 2 fields per element vs expected 3\nres, err := rdb.VSimWithScoresAttrib(ctx, \"pts\", vector)\n// redis: got 6 elements in the VSIM array, wanted a multiple of 3\n\n// after: match the parser to the actual reply shape\nres, err := rdb.VSimWithScores(ctx, \"pts\", vector)","handlingStrategy":"try-catch","validationCode":"raw, _ := rdb.Do(ctx, \"VSIM\", \"pts\", vec, \"WITHSCORES\", \"WITHATTRIBS\").Result()\n_ = raw // confirm 3 fields per element in the reply","typeGuard":null,"tryCatchPattern":"cmd := rdb.VSimWithScoresAttrib(ctx, \"pts\", vec)\nif err := cmd.Err(); err != nil {\n    if strings.Contains(err.Error(), \"wanted a multiple of 3\") {\n        // degrade to VSimWithScores (2 fields) or raw parsing\n    }\n    return err\n}","preventionTips":["Confirm the server actually returns attributes for VSIM","Match the parser variant to the requested WITH* flags","Use RESP3 to make reply arity explicit","Version-gate vector-set usage in CI against REDIS_VERSION"],"tags":["redis","vectorset","vsim","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"}