{"record":{"id":"d91a93b52410e37d","repo":"deepset-ai/haystack","slug":"the-threshold-parameter-must-be-between-0-and-1","errorCode":null,"errorMessage":"The threshold parameter must be between 0 and 1.","messagePattern":"The threshold parameter must be between 0 and 1\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/retrievers/auto_merging_retriever.py","lineNumber":75,"sourceCode":"    retrieved_docs = retriever.run(leaf_docs[4:6])\n    print(retrieved_docs[\"documents\"])\n    # [Document(id=538..),\n    # content: 'warm glow over the trees. Birds began to sing.',\n    # meta: {'block_size': 10, 'parent_id': '835..', 'children_ids': ['c17...', '3ff...', '352...'], 'level': 1, 'source_id': '835...',\n    # 'page_number': 1, 'split_id': 1, 'split_idx_start': 45})]}\n    ```\n    \"\"\"  # noqa: E501\n\n    def __init__(self, document_store: DocumentStore, threshold: float = 0.5) -> None:\n        \"\"\"\n        Initialize the AutoMergingRetriever.\n\n        :param document_store: DocumentStore from which to retrieve the parent documents\n        :param threshold: Threshold to decide whether the parent instead of the individual documents is returned\n        \"\"\"\n\n        if not 0 < threshold < 1:\n            raise ValueError(\"The threshold parameter must be between 0 and 1.\")\n\n        self.document_store = document_store\n        self.threshold = threshold\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"\n        Serializes the component to a dictionary.\n\n        :returns:\n            Dictionary with serialized data.\n        \"\"\"\n        return default_to_dict(self, document_store=self.document_store, threshold=self.threshold)\n\n    @classmethod\n    def from_dict(cls, data: dict[str, Any]) -> \"AutoMergingRetriever\":\n        \"\"\"\n        Deserializes the component from a dictionary.\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/retrievers/auto_merging_retriever.py#L57-L93","documentation":"AutoMergingRetriever uses `threshold` as the fraction of leaf documents under a parent that must be matched before the parent document replaces them. Since it is a proportion, it is strictly validated to lie between 0 and 1 (exclusive) in __init__.","triggerScenarios":"AutoMergingRetriever(document_store=store, threshold=1) or threshold=0 or threshold=5 or negative values — any value where `not 0 < threshold < 1`.","commonSituations":"Configuring threshold as a percentage (e.g. 75 instead of 0.75), or off-by-one boundary values 0 and 1 which are rejected.","solutions":["Pass a float strictly between 0 and 1, e.g. 0.5","Convert percentage configs to fractions (75 -> 0.75)","Check pipeline YAML/env for integer threshold values"],"exampleFix":"// before\nretriever = AutoMergingRetriever(document_store=store, threshold=75)\n// after\nretriever = AutoMergingRetriever(document_store=store, threshold=0.75)","handlingStrategy":"validation","validationCode":"if not (isinstance(threshold, float) and 0 < threshold < 1):\n    raise ValueError(f\"threshold must be a float strictly between 0 and 1, got {threshold}\")","typeGuard":"def is_valid_threshold(t: object) -> bool:\n    return isinstance(t, (int, float)) and 0 < t < 1","tryCatchPattern":"try:\n    retriever = AutoMergingRetriever(document_store=store, threshold=cfg[\"threshold\"])\nexcept ValueError as e:\n    logger.error(\"Bad threshold: %s\", e)\n    retriever = AutoMergingRetriever(document_store=store, threshold=0.5)","preventionTips":["Store thresholds as fractions, never percentages","Clamp/validate config values at load time","Add a pipeline-config schema check"],"tags":["validation","retriever","threshold","config"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}