{"record":{"id":"ce0a024eee9c5bb3","repo":"dgraph-io/dgraph","slug":"invalid-value-for-distance-threshold-in-similar","errorCode":null,"errorMessage":"Invalid value for 'distance_threshold' in similar_to: %q","messagePattern":"Invalid value for 'distance_threshold' in similar_to: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2810,"sourceCode":"\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}\n\t}\n\treturn nil\n}\n","sourceCodeStart":2792,"sourceCodeEnd":2823,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2792-L2823","documentation":"The 'distance_threshold' similar_to option must parse as a float64 via strconv.ParseFloat. If the value is not a valid float literal (e.g. 'distance_threshold: near', 'distance_threshold: 0,5' with comma decimal separator), this error is returned and the threshold is not stored in fc.vsDistanceThreshold.","triggerScenarios":"similar_to option string contains 'distance_threshold' with a non-float value: 'distance_threshold: auto', 'distance_threshold: 0.1.2', 'distance_threshold:' (empty), or a locale-formatted number like 'distance_threshold: 0,75'.","commonSituations":"Locale formatting where the decimal comma was not converted to a dot; string concatenation that produced a malformed number; placeholder text left in a hand-edited query.","solutions":["Provide a valid decimal float such as 'distance_threshold: 0.5'.","Convert locale-formatted numbers (comma decimal separator) to dot notation before building the query.","Validate with strconv.ParseFloat client-side before sending."],"exampleFix":"// before\n\"distance_threshold: 0,75\"\n// after\n\"distance_threshold: 0.75\"","handlingStrategy":"validation","validationCode":"f := \"0,75\"\nif _, err := strconv.ParseFloat(strings.ReplaceAll(f, \",\", \".\"), 64); err != nil {\n    return fmt.Errorf(\"distance_threshold must be a float, got %q\", f)\n}","typeGuard":null,"tryCatchPattern":"if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), \"Invalid value for 'distance_threshold'\") {\n    return fmt.Errorf(\"distance_threshold must be a decimal float: %w\", err)\n}","preventionTips":["Normalize locale decimal commas to dots before building the query.","Use strconv.FormatFloat to serialize thresholds.","Validate the option string with ParseFloat before sending."],"tags":["dql","vector-search","parsing","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}