{"record":{"id":"abdaa3a5fef15938","repo":"dgraph-io/dgraph","slug":"invalid-value-for-ef-in-similar-to-q","errorCode":null,"errorMessage":"Invalid value for 'ef' in similar_to: %q","messagePattern":"Invalid value for 'ef' in similar_to: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2801,"sourceCode":"\t\tk := strings.ToLower(strings.TrimSpace(args[i]))\n\t\tv := strings.TrimSpace(args[i+1])\n\t\tif strings.HasSuffix(k, \":\") {\n\t\t\tk = strings.TrimSuffix(k, \":\")\n\t\t}\n\t\tif len(k) == 0 {\n\t\t\treturn errors.Errorf(\"Malformed option in similar_to: empty key\")\n\t\t}\n\t\tif _, dup := seen[k]; dup {\n\t\t\treturn errors.Errorf(\"Duplicate key in similar_to options: %q\", k)\n\t\t}\n\t\tseen[k] = struct{}{}\n\n\t\tv = strings.Trim(v, \"\\\"'\")\n\t\tswitch k {\n\t\tcase \"ef\":\n\t\t\tn, perr := strconv.ParseInt(v, 10, 32)\n\t\t\tif perr != nil {\n\t\t\t\treturn errors.Errorf(\"Invalid value for 'ef' in similar_to: %q\", v)\n\t\t\t}\n\t\t\tif n <= 0 {\n\t\t\t\treturn errors.Errorf(\"Value for 'ef' must be positive, got: %d\", n)\n\t\t\t}\n\t\t\tfc.vsEfOverride = int(n)\n\t\tcase \"distance_threshold\":\n\t\t\tf, perr := strconv.ParseFloat(v, 64)\n\t\t\tif perr != nil {\n\t\t\t\treturn errors.Errorf(\"Invalid value for 'distance_threshold' in similar_to: %q\", v)\n\t\t\t}\n\t\t\tif f < 0 {\n\t\t\t\treturn errors.Errorf(\"Value for 'distance_threshold' must be non-negative, got: %v\", f)\n\t\t\t}\n\t\t\tfc.vsDistanceThreshold = new(float64)\n\t\t\t*fc.vsDistanceThreshold = f\n\t\tdefault:\n\t\t\treturn errors.Errorf(\"Unknown option in similar_to: %q\", k)\n\t\t}","sourceCodeStart":2783,"sourceCodeEnd":2819,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2783-L2819","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\n\"similar_to: \\\"vec; ef: 100.5\\\"\"\n// after\n\"similar_to: \\\"vec; ef: 100\\\"\"","handlingStrategy":"validation","validationCode":"v := \"100.5\" // value destined for ef\nif _, err := strconv.ParseInt(v, 10, 32); err != nil {\n    return fmt.Errorf(\"ef must be an int32, got %q\", v)\n}","typeGuard":null,"tryCatchPattern":"if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), \"Invalid value for 'ef'\") {\n    return fmt.Errorf(\"ef must be a positive base-10 integer: %w\", err)\n}","preventionTips":["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."],"tags":["dql","query-options","parsing","vector-search"],"backgroundTag":"invalid-enum-value","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}