OpenBMB/ChatDev · error · ConfigError

similarity_threshold must be numeric

Error message

similarity_threshold must be numeric

What it means

MemoryRetrieveConfig.from_dict requires 'similarity_threshold' (default -1.0) to be an int or float (bool excluded in practice by intent, though bool is an int subclass). Any string, list, null-adjacent, or other non-numeric value raises this ConfigError.

Source

Thrown at entity/configs/node/memory.py:460

            stage_list = ensure_list(stages_raw)
            parsed: List[AgentExecFlowStage] = []
            for idx, item in enumerate(stage_list):
                try:
                    parsed.append(AgentExecFlowStage(item))
                except ValueError as exc:
                    raise ConfigError(
                        f"retrieve_stage entries must be one of {[stage.value for stage in AgentExecFlowStage]}",
                        extend_path(path, f"retrieve_stage[{idx}]"),
                    ) from exc
            stages = parsed

        top_k_value = mapping.get("top_k", 3)
        if not isinstance(top_k_value, int) or top_k_value <= 0:
            raise ConfigError("top_k must be a positive integer", extend_path(path, "top_k"))

        threshold_value = mapping.get("similarity_threshold", -1.0)
        if not isinstance(threshold_value, (int, float)):
            raise ConfigError("similarity_threshold must be numeric", extend_path(path, "similarity_threshold"))

        read_value = mapping.get("read", True)
        if not isinstance(read_value, bool):
            raise ConfigError("read must be boolean", extend_path(path, "read"))

        write_value = mapping.get("write", True)
        if not isinstance(write_value, bool):
            raise ConfigError("write must be boolean", extend_path(path, "write"))

        return cls(
            name=name,
            retrieve_stage=stages,
            top_k=top_k_value,
            similarity_threshold=float(threshold_value),
            read=read_value,
            write=write_value,
            path=path,
        )

View on GitHub (pinned to 4fb2db0ea9)

Solutions

  1. Remove quotes around the number so YAML/JSON parses it as numeric
  2. Convert values with float(...) before building the mapping
  3. Omit the key to use the default -1.0

Example fix

# before
similarity_threshold: '0.7'
# after
similarity_threshold: 0.7
Defensive patterns

Strategy: validation

Validate before calling

th = cfg.get('similarity_threshold', -1.0)
assert isinstance(th, (int, float)) and not isinstance(th, bool)

Type guard

def is_valid_threshold(v) -> bool:
    return isinstance(v, (int, float)) and not isinstance(v, bool)

Try / catch

try:
    MemoryRetrieveConfig.from_dict(d, path='retrieve')
except ConfigError as e:
    if 'similarity_threshold' in str(e):
        d['similarity_threshold'] = float(d['similarity_threshold'])
        MemoryRetrieveConfig.from_dict(d, path='retrieve')

Prevention

When it happens

Trigger: Setting similarity_threshold: '0.7' (string) or [0.7] in the retrieve config mapping.

Common situations: String values from environment variables or template interpolation not converted to numbers; YAML quoting the number; JSON configs where the value was serialized as a string.

Related errors


AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27). Data as JSON: /api/errors/e0ebaac45ce13b29. Report an issue: GitHub.