{"record":{"id":"672035eb186e8a80","repo":"dgraph-io/dgraph","slug":"value-for-ef-must-be-positive-got-d","errorCode":null,"errorMessage":"Value for 'ef' must be positive, got: %d","messagePattern":"Value for 'ef' must be positive, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2804,"sourceCode":"\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}\n\t}\n\treturn nil\n}","sourceCodeStart":2786,"sourceCodeEnd":2822,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2786-L2822","documentation":"After 'ef' parses as an integer, the parser requires it to be strictly positive because ef controls the HNSW search candidate list size and zero/negative values are meaningless. A parsed value <= 0 triggers this error and aborts applying the similar_to options.","triggerScenarios":"similar_to option string like 'ef: 0' or 'ef: -5'. The value parses as an int32 but fails the n <= 0 check.","commonSituations":"Default-value placeholders left at 0 in a query template; sign errors when computing ef from a formula; UI form allowing 0 as 'unset' which is then serialized literally.","solutions":["Use a positive ef value (e.g. 'ef: 10' or higher); omit the 'ef' option entirely if you want the index default.","Guard client-side: only emit the ef option when the computed value is > 0.","Treat 0 as 'not set' in your builder and drop the key."],"exampleFix":"// before\nif ef > -1 { opts += \"; ef: \" + strconv.Itoa(ef) }\n// after\nif ef > 0 { opts += \"; ef: \" + strconv.Itoa(ef) }","handlingStrategy":"validation","validationCode":"if ef <= 0 { ef = defaultEf } // drop or substitute before serializing\nopts := fmt.Sprintf(\"; ef: %d\", ef)","typeGuard":null,"tryCatchPattern":"if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), \"'ef' must be positive\") {\n    return retryWithDefaultEf(ctx)\n}","preventionTips":["Treat 0/negative ef as 'unset' and omit the key instead of serializing it.","Clamp computed ef values to a minimum of 1.","In UIs, restrict ef inputs to positive integers."],"tags":["dql","vector-search","validation","hnsw"],"backgroundTag":"invalid-enum-value","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}