dgraph-io/dgraph · error
Invalid value for 'ef' in similar_to: %q
Error message
Invalid value for 'ef' in similar_to: %q
What it means
The 'ef' option of similar_to must be a 32-bit integer parsed with strconv.ParseInt. When the value string cannot be parsed as an integer (e.g. 'ef: abc', 'ef: 10.5', 'ef: "1e2"'), the parser returns this error instead of applying the override to fc.vsEfOverride.
Source
Thrown at worker/task.go:2801
k := strings.ToLower(strings.TrimSpace(args[i]))
v := strings.TrimSpace(args[i+1])
if strings.HasSuffix(k, ":") {
k = strings.TrimSuffix(k, ":")
}
if len(k) == 0 {
return errors.Errorf("Malformed option in similar_to: empty key")
}
if _, dup := seen[k]; dup {
return errors.Errorf("Duplicate key in similar_to options: %q", k)
}
seen[k] = struct{}{}
v = strings.Trim(v, "\"'")
switch k {
case "ef":
n, perr := strconv.ParseInt(v, 10, 32)
if perr != nil {
return errors.Errorf("Invalid value for 'ef' in similar_to: %q", v)
}
if n <= 0 {
return errors.Errorf("Value for 'ef' must be positive, got: %d", n)
}
fc.vsEfOverride = int(n)
case "distance_threshold":
f, perr := strconv.ParseFloat(v, 64)
if perr != nil {
return errors.Errorf("Invalid value for 'distance_threshold' in similar_to: %q", v)
}
if f < 0 {
return errors.Errorf("Value for 'distance_threshold' must be non-negative, got: %v", f)
}
fc.vsDistanceThreshold = new(float64)
*fc.vsDistanceThreshold = f
default:
return errors.Errorf("Unknown option in similar_to: %q", k)
}View on GitHub (pinned to 759e242be6)
Solutions
- Set 'ef' to a positive base-10 integer, e.g. 'ef: 100'.
- If a float was computed, truncate/round to int before building the option string.
- Validate the value with strconv.ParseInt on the client before sending the query.
Example fix
// before "similar_to: \"vec; ef: 100.5\"" // after "similar_to: \"vec; ef: 100\""
Defensive patterns
Strategy: validation
Validate before calling
v := "100.5" // value destined for ef
if _, err := strconv.ParseInt(v, 10, 32); err != nil {
return fmt.Errorf("ef must be an int32, got %q", v)
} Try / catch
if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), "Invalid value for 'ef'") {
return fmt.Errorf("ef must be a positive base-10 integer: %w", err)
} Prevention
- Always format ef with strconv.Itoa, never %v on a float.
- Validate option values with ParseInt before embedding them in DQL.
- Avoid locale or unit-suffixed numbers in option strings.
When it happens
Trigger: similar_to option string contains 'ef' with a non-integer value: 'ef: fast', 'ef: 100.0', 'ef: 1e3', or an empty value 'ef:'. Quotes around the value are trimmed, so "ef: \"50\"" is fine, but any decimal or textual value fails.
Common situations: Copy-pasted config where ef was written as a float or with units ('ef: 100ms'); templating that substituted a float Go value (e.g. fmt.Sprintf("ef: %v", 100.5)); typos like 'ef: 1OO' (letter O).
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Duplicate key in similar_to options: %q
- Invalid value for 'distance_threshold' in similar_to: %q
- Unknown option in similar_to: %q
- Value for 'ef' must be positive, got: %d
- Value for 'distance_threshold' must be non-negative, got: %v
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/abdaa3a5fef15938.
Report an issue: GitHub.