{"record":{"id":"e29b27313d5c414e","repo":"infiniflow/ragflow","slug":"101-e29b27","errorCode":"101","errorMessage":"top_k must be integer and score_threshold must be numeric","messagePattern":"top_k must be integer and score_threshold must be numeric","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"api/apps/restful_apis/dify_retrieval_api.py","lineNumber":61,"sourceCode":"        method = request.method\n    except RuntimeError:\n        # Unit tests may call the handler directly without a request context.\n        method = \"POST\"\n    if method == \"GET\":\n        query_args = request.args\n        retrieval_setting = {}\n        knowledge_id = query_args.get(\"knowledge_id\")\n        query = query_args.get(\"query\")\n        use_kg = str(query_args.get(\"use_kg\", \"\")).lower() in {\"1\", \"true\", \"yes\", \"on\"}\n        top_k = query_args.get(\"top_k\")\n        score_threshold = query_args.get(\"score_threshold\")\n        try:\n            if top_k not in (None, \"\"):\n                retrieval_setting[\"top_k\"] = int(top_k)\n            if score_threshold not in (None, \"\"):\n                retrieval_setting[\"score_threshold\"] = float(score_threshold)\n        except (TypeError, ValueError):\n            raise ValueError(\"top_k must be integer and score_threshold must be numeric\")\n        safe_query = f\"len={len(query)}\" if isinstance(query, str) else \"len=0\"\n        logger.debug(\n            \"Dify retrieval GET normalization: knowledge_id=%s query=%s use_kg=%s top_k=%s score_threshold=%s\",\n            knowledge_id,\n            safe_query,\n            use_kg,\n            retrieval_setting.get(\"top_k\"),\n            retrieval_setting.get(\"score_threshold\"),\n        )\n\n        req = {\n            \"knowledge_id\": knowledge_id,\n            \"query\": query,\n            \"use_kg\": use_kg,\n            \"retrieval_setting\": retrieval_setting,\n        }\n        return req\n    req = await get_request_json()","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/apps/restful_apis/dify_retrieval_api.py#L43-L79","documentation":"Raised while normalizing GET query parameters for the Dify-compatible retrieval endpoint: top_k could not be int()-converted or score_threshold could not be float()-converted. Empty/absent values are skipped, so this fires only when a non-empty non-numeric value is supplied.","triggerScenarios":"GET /api/v1/dify/retrieval?dataset_id=...&query=...&top_k=abc or score_threshold=high; also top_k=10.5 (int('10.5') raises ValueError) — note a decimal top_k triggers it too.","commonSituations":"Dify or custom clients sending thresholds as percentages (\"85%\"), localized decimals, or passing top_k with a fractional value; copy-pasting parameter examples with placeholder text.","solutions":["Send top_k as an integer literal (e.g. top_k=1024) and score_threshold as a decimal number (e.g. score_threshold=0.2).","Strip any % sign or unit and convert in the client before building the query string.","Omit the parameters entirely to use server defaults rather than sending placeholders."],"exampleFix":"# before\nGET /api/v1/dify/retrieval?...&top_k=10.5&score_threshold=0.2\n# after\nGET /api/v1/dify/retrieval?...&top_k=10&score_threshold=0.2","handlingStrategy":"validation","validationCode":"def normalize_get_params(query_args):\n    top_k = query_args.get(\"top_k\")\n    score = query_args.get(\"score_threshold\")\n    if top_k not in (None, \"\"):\n        top_k = int(str(top_k).strip())\n    if score not in (None, \"\"):\n        score = float(str(score).strip().rstrip(\"%\"))\n    return top_k, score","typeGuard":"const isIntParam = (v: unknown): v is number | string =>\n  typeof v === \"number\" && Number.isInteger(v) || /^-?\\d+$/.test(String(v).trim());","tryCatchPattern":"try:\n    r = requests.get(url, params=p)\nexcept requests.HTTPError as e:\n    if \"top_k must be integer\" in e.response.text:\n        p[\"top_k\"], p[\"score_threshold\"] = int(p[\"top_k\"]), float(p[\"score_threshold\"])\n        r = requests.get(url, params=p)\n    else:\n        raise","preventionTips":["Build GET query strings with pre-converted ints/floats, never raw form strings.","Reject fractional top_k client-side.","Strip units like '%' before sending thresholds."],"tags":["dify-api","retrieval","validation","query-params"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}