dgraph-io/dgraph · error

Expected a float32vector but got %v

Error message

Expected a float32vector but got %v

What it means

parseValue parses variables of type "float32vector" using types.ParseVFloat, which converts a bracketed list of numbers into a []float32 (used for vector/predicate search). If the string isn't a well-formed vector of floats, the error is wrapped with 'Expected a float32vector but got %v'.

Source

Thrown at dql/parser.go:352

					Value: i,
				}, nil
			}
		}
	case "bool":
		{
			if i, err := strconv.ParseBool(v.Value); err != nil {
				return types.Val{}, errors.Wrapf(err, "Expected a bool but got %v", v.Value)
			} else {
				return types.Val{
					Tid:   types.BoolID,
					Value: i,
				}, nil
			}
		}
	case "float32vector":
		{
			if i, err := types.ParseVFloat(v.Value); err != nil {
				return types.Val{}, errors.Wrapf(err, "Expected a float32vector but got %v", v.Value)
			} else {
				return types.Val{
					Tid:   types.VFloatID,
					Value: i,
				}, nil
			}
		}
	case "string": // Value is a valid string. No checks required.
		return types.Val{
			Tid:   types.StringID,
			Value: v.Value,
		}, nil
	default:
		return types.Val{}, errors.Errorf("Type %q not supported", typ)
	}
}

func checkValueType(vm varMap) error {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Serialize the vector as a bracketed comma-separated float list, e.g. "[0.1,0.2,0.3]"
  2. Verify every element parses as a float and brackets are balanced before submitting
  3. Re-encode the embedding on the client from the []float32 source instead of hand-formatting strings
  4. Check that the vector wasn't truncated or corrupted by logging/size limits in your pipeline

Example fix

// before
vars := map[string]string{"$vec": "0.1, 0.2, 0.3"}
// after
vars := map[string]string{"$vec": "[0.1, 0.2, 0.3]"}
Defensive patterns

Strategy: validation

Validate before calling

func validVFloat(s string) bool {
  s = strings.TrimSpace(s)
  if !strings.HasPrefix(s, "[") || !strings.HasSuffix(s, "]") { return false }
  inner := strings.Trim(s, "[]")
  if inner == "" { return true }
  for _, part := range strings.Split(inner, ",") {
    if _, err := strconv.ParseFloat(strings.TrimSpace(part), 32); err != nil { return false }
  }
  return true
}

Prevention

When it happens

Trigger: Passing a variable with Type "float32vector" whose Value is not a parseable float vector — e.g. "[0.1, 0.2" (unclosed bracket), "[a, b]" (non-numeric elements), or a plain number without brackets.

Common situations: Embedding/similarity-search workloads where embeddings are serialized incorrectly (wrong separator, JSON array with mismatched format); truncating large vectors when building query strings; clients sending nested arrays or comma strings without brackets.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/42b140229edf983f. Report an issue: GitHub.