{"record":{"id":"8cfcaa5b637e8082","repo":"OpenBMB/ChatDev","slug":"top-k-must-be-a-positive-integer","errorCode":null,"errorMessage":"top_k must be a positive integer","messagePattern":"top_k must be a positive integer","errorType":"validation","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"entity/configs/node/memory.py","lineNumber":456,"sourceCode":"\n        stages_raw = mapping.get(\"retrieve_stage\")\n        stages: List[AgentExecFlowStage] | None = None\n        if stages_raw is not None:\n            stage_list = ensure_list(stages_raw)\n            parsed: List[AgentExecFlowStage] = []\n            for idx, item in enumerate(stage_list):\n                try:\n                    parsed.append(AgentExecFlowStage(item))\n                except ValueError as exc:\n                    raise ConfigError(\n                        f\"retrieve_stage entries must be one of {[stage.value for stage in AgentExecFlowStage]}\",\n                        extend_path(path, f\"retrieve_stage[{idx}]\"),\n                    ) from exc\n            stages = parsed\n\n        top_k_value = mapping.get(\"top_k\", 3)\n        if not isinstance(top_k_value, int) or top_k_value <= 0:\n            raise ConfigError(\"top_k must be a positive integer\", extend_path(path, \"top_k\"))\n\n        threshold_value = mapping.get(\"similarity_threshold\", -1.0)\n        if not isinstance(threshold_value, (int, float)):\n            raise ConfigError(\"similarity_threshold must be numeric\", extend_path(path, \"similarity_threshold\"))\n\n        read_value = mapping.get(\"read\", True)\n        if not isinstance(read_value, bool):\n            raise ConfigError(\"read must be boolean\", extend_path(path, \"read\"))\n\n        write_value = mapping.get(\"write\", True)\n        if not isinstance(write_value, bool):\n            raise ConfigError(\"write must be boolean\", extend_path(path, \"write\"))\n\n        return cls(\n            name=name,\n            retrieve_stage=stages,\n            top_k=top_k_value,\n            similarity_threshold=float(threshold_value),","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/entity/configs/node/memory.py#L438-L474","documentation":"MemoryRetrieveConfig.from_dict validates that 'top_k' (default 3) is an int greater than zero. Non-int values (including floats like 3.0, bools, or strings) and values <= 0 raise this ConfigError.","triggerScenarios":"Setting top_k: 3.5, top_k: 0, top_k: -1, or top_k: '3' in a memory retrieve config.","commonSituations":"YAML floats (3.0) instead of ints; tuning scripts computing top_k as a float; reusing a threshold-style value for top_k; passing booleans (True is an int subclass but fails positivity only when 0/False cases arise — note isinstance(True, int) is True so True passes, but 0 fails).","solutions":["Set top_k to a positive integer literal, e.g. 5","Cast computed values with int(...) before building config","Omit top_k to use the default of 3"],"exampleFix":"# before\ntop_k: 3.0\n# after\ntop_k: 3","handlingStrategy":"validation","validationCode":"tk = cfg.get('top_k', 3)\nassert isinstance(tk, int) and not isinstance(tk, bool) and tk > 0, 'top_k invalid'","typeGuard":"def is_valid_top_k(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    MemoryRetrieveConfig.from_dict(d, path='retrieve')\nexcept ConfigError as e:\n    if 'top_k' in str(e):\n        d['top_k'] = int(d['top_k']) or 3\n        MemoryRetrieveConfig.from_dict(d, path='retrieve')","preventionTips":["int() cast computed top_k values","Use integer literals in configs"],"tags":["config","validation","memory"],"backgroundTag":"invalid-config-value-type","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}