go-redis/redis · error

redis: got %d elements in the VSIM array, wanted a multiple

Error message

redis: got %d elements in the VSIM array, wanted a multiple of 3

What it means

Returned by VectorScoreAttribSliceCmd.readReply (command.go:8912) when parsing a RESP2 reply from VSimWithArgsWithScoresWithAttribs (VSIM ... WITHSCORES WITHATTRIBS). The flat array must contain [name, score, attribute] triples; a length not divisible by 3 breaks parsing. RESP3 returns structured maps and avoids this path.

Source

Thrown at command.go:8912

			score, err := rd.ReadFloat()
			if err != nil {
				return err
			}
			attrib, err := readVectorAttribStringOrNil(rd)
			if err != nil {
				return err
			}
			cmd.val[i] = VectorScoreAttrib{Name: name, Score: score, Attribs: attrib}
		}
		return nil
	}

	n, err := rd.ReadArrayLen()
	if err != nil {
		return err
	}
	if n%3 != 0 {
		return fmt.Errorf("redis: got %d elements in the VSIM array, wanted a multiple of 3", n)
	}
	cmd.val = make([]VectorScoreAttrib, n/3)
	for i := range cmd.val {
		name, err := rd.ReadString()
		if err != nil {
			return err
		}
		score, err := rd.ReadFloat()
		if err != nil {
			return err
		}
		attrib, err := readVectorAttribStringOrNil(rd)
		if err != nil {
			return err
		}
		cmd.val[i] = VectorScoreAttrib{Name: name, Score: score, Attribs: attrib}
	}
	return nil

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Use RESP3 (Protocol: 3) for structured map replies that avoid flat-array triple parsing
  2. Upgrade Redis and VectorSet module to a compatible version
  3. Confirm the server supports WITHSCORES and WITHATTRIBS simultaneously

Example fix

// before
rdb := redis.NewClient(&redis.Options{Addr: ":6379"})

// after
rdb := redis.NewClient(&redis.Options{Addr: ":6379", Protocol: 3})
Defensive patterns

Strategy: validation

Validate before calling

opts := &redis.Options{Addr: ":6379", Protocol: 3}
rdb := redis.NewClient(opts)

Try / catch

res, err := rdb.VSimWithArgsWithScoresWithAttribs(ctx, key, vec, args).Result()
if err != nil && strings.Contains(err.Error(), "wanted a multiple of 3") {
    log.Error("VSIM WITHSCORES WITHATTRIBS RESP2 mismatch; use Protocol:3")
}

Prevention

When it happens

Trigger: Calling VSimWithArgsWithScoresWithAttribs with RESP2 (default) where the returned flat array length is not a multiple of 3.

Common situations: RESP2 protocol with an incompatible VectorSet module; server format change between minor versions; proxy mangling the array.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/01d100e86cb6c845.json. Report an issue: GitHub.