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 2

What it means

Returned by VectorAttribSliceCmd.readReply (command.go:8814) when parsing a RESP2 reply from VSimWithArgsWithAttribs (VSIM ... WITHATTRIBS). The flat RESP2 array must contain [name, attribute] pairs; an odd element count breaks pairing. RESP3 returns a map and never reaches this check.

Source

Thrown at command.go:8814

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

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

func (cmd *VectorAttribSliceCmd) Clone() Cmder {
	return &VectorAttribSliceCmd{

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Use RESP3 (Protocol: 3) so VSIM returns a structured map reply
  2. Upgrade the Redis VectorSet module to a version matching this go-redis
  3. Verify WITHATTRIBS is supported by the server

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.VSimWithArgsWithAttribs(ctx, key, vec, args).Result()
if err != nil && strings.Contains(err.Error(), "wanted a multiple of 2") {
    log.Error("VSIM WITHATTRIBS RESP2 format mismatch; use Protocol:3")
}

Prevention

When it happens

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

Common situations: RESP2 protocol with an incompatible VectorSet module version; proxy corrupting the array structure; server-side format change.

Related errors


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