{"record":{"id":"e4e3b7c8fe1ec2fe","repo":"headroomlabs-ai/headroom","slug":"dedup-similarity-threshold-must-be-0-0-1-0-got-s","errorCode":null,"errorMessage":"dedup_similarity_threshold must be 0.0-1.0, got {self.dedup_similarity_threshold}","messagePattern":"dedup_similarity_threshold must be 0\\.0-1\\.0, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/bridge_config.py","lineNumber":66,"sourceCode":"    default_importance: float = 0.6\n    heading_importance_map: dict[int, float] = field(\n        default_factory=lambda: {1: 0.9, 2: 0.8, 3: 0.7, 4: 0.6, 5: 0.5, 6: 0.4}\n    )\n    sync_state_path: Path = field(default_factory=_paths.bridge_state_path)\n    auto_import_on_startup: bool = False\n    export_path: Path | None = None\n    export_format: MarkdownFormat = MarkdownFormat.GENERIC\n    extract_entities: bool = True\n    chunk_by_section: bool = True\n    dedup_similarity_threshold: float = 0.92\n    source_tag: str = \"memory_bridge\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate configuration.\"\"\"\n        if not 0.0 <= self.default_importance <= 1.0:\n            raise ValueError(f\"default_importance must be 0.0-1.0, got {self.default_importance}\")\n        if not 0.0 <= self.dedup_similarity_threshold <= 1.0:\n            raise ValueError(\n                f\"dedup_similarity_threshold must be 0.0-1.0, got {self.dedup_similarity_threshold}\"\n            )\n        self.md_paths = [Path(p) if isinstance(p, str) else p for p in self.md_paths]\n        if isinstance(self.sync_state_path, str):\n            self.sync_state_path = Path(self.sync_state_path)\n        if self.export_path and isinstance(self.export_path, str):\n            self.export_path = Path(self.export_path)\n","sourceCodeStart":48,"sourceCodeEnd":74,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/bridge_config.py#L48-L74","documentation":"ValueError raised in MemoryBridgeConfig.__post_init__ when dedup_similarity_threshold is outside [0.0, 1.0]. This threshold drives near-duplicate detection during markdown imports (default 0.92 cosine similarity); it is a similarity fraction, so the guard ensures a valid range at construction time.","triggerScenarios":"MemoryBridgeConfig(dedup_similarity_threshold=92) (percentage confusion) or any negative / >1 value; fires instantly in __post_init__ when the dataclass is created.","commonSituations":"Config authored as a percent (95 instead of 0.95); values copied from a system using distance (0.1) where similarity (0.9) was expected — note the semantic flip too.","solutions":["Express it as a fraction: dedup_similarity_threshold=0.95","If migrating from a percent-based config, divide by 100","Remember it is a SIMILARITY threshold (higher = stricter dedup), not a distance threshold"],"exampleFix":"# before\ncfg = MemoryBridgeConfig(dedup_similarity_threshold=95)  # ValueError\n\n# after\ncfg = MemoryBridgeConfig(dedup_similarity_threshold=0.95)","handlingStrategy":"validation","validationCode":"def clamp_fraction(name: str, value: float) -> float:\n    if not 0.0 <= value <= 1.0:\n        raise ValueError(f'{name} must be in [0,1], got {value}')\n    return value\n\ncfg = MemoryBridgeConfig(\n    dedup_similarity_threshold=clamp_fraction('dedup_similarity_threshold', raw_threshold),\n)","typeGuard":"def is_valid_threshold(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= v <= 1.0","tryCatchPattern":"try:\n    cfg = MemoryBridgeConfig(dedup_similarity_threshold=raw)\nexcept ValueError:\n    cfg = MemoryBridgeConfig()  # default 0.92","preventionTips":["Remember it is similarity (higher = stricter dedup), not distance","Reject percent-scale values (>= 1.1) in config parsers with a helpful message","Keep a unit test asserting the default 0.92 stays valid"],"tags":["python","config","validation","range-check","dedup","memory-bridge"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}