{"record":{"id":"6ec7c84ec90fa7d7","repo":"deepset-ai/haystack","slug":"dimension-must-be-a-positive-integer","errorCode":null,"errorMessage":"'dimension' must be a positive integer.","messagePattern":"'dimension' must be a positive integer\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/mock_document_embedder.py","lineNumber":91,"sourceCode":"            embedding as a list of floats. Mutually exclusive with `embedding`. To support serialization, pass a\n            named function (lambdas and nested functions cannot be serialized).\n        :param dimension: The number of dimensions of the deterministic embedding. Ignored when `embedding` or\n            `embedding_fn` is provided, since their length is determined by the value or callable.\n        :param model: The model name reported in the metadata. Purely cosmetic; no model is loaded.\n        :param meta: Additional metadata merged into the output `meta`.\n        :param prefix: A string to add at the beginning of each text before embedding.\n        :param suffix: A string to add at the end of each text before embedding.\n        :param meta_fields_to_embed: List of metadata fields to embed along with the document text.\n        :param embedding_separator: Separator used to concatenate the metadata fields to the document text.\n        :param progress_bar: Accepted for interface compatibility with real Document Embedders and ignored.\n        :raises ValueError: If both `embedding` and `embedding_fn` are provided, if `dimension` is not positive, or\n            if `embedding` is an empty list.\n        :raises TypeError: If `embedding` is not a sequence of numbers.\n        \"\"\"\n        if embedding is not None and embedding_fn is not None:\n            raise ValueError(\"Pass either 'embedding' or 'embedding_fn', not both.\")\n        if dimension <= 0:\n            raise ValueError(\"'dimension' must be a positive integer.\")\n\n        self.embedding = _coerce_embedding(embedding, name=\"'embedding'\") if embedding is not None else None\n        self.embedding_fn = embedding_fn\n        self.dimension = dimension\n        self.model = model\n        self.meta = meta or {}\n        self.prefix = prefix\n        self.suffix = suffix\n        self.meta_fields_to_embed = meta_fields_to_embed or []\n        self.embedding_separator = embedding_separator\n        self.progress_bar = progress_bar\n        self._is_warmed_up = False\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"Serialize the component to a dictionary.\"\"\"\n        embedding_fn = serialize_callable(self.embedding_fn) if self.embedding_fn is not None else None\n        return default_to_dict(\n            self,","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_document_embedder.py#L73-L109","documentation":"MockDocumentEmbedder validates that `dimension` is a positive integer because generated embeddings must have at least one component. A dimension of zero or negative is nonsensical, so the constructor raises this ValueError immediately rather than producing broken embeddings later.","triggerScenarios":"`MockDocumentEmbedder(dimension=0)` or `MockDocumentEmbedder(dimension=-8)` (also non-integer numerics like 0.0 that satisfy `<= 0`).","commonSituations":"Computing the dimension from a variable that defaults to 0 or from an empty collection; typos like `dim=-1` intending 'auto'; reading dimension from config where the key is missing/zero.","solutions":["Pass a positive integer, e.g. `dimension=768`","If the dimension comes from config, validate/default it before constructing: `dimension = configured or 768`","Check upstream variables that compute the dimension for off-by-one or empty-input bugs"],"exampleFix":"// before\nMockDocumentEmbedder(dimension=len(configured_embeddings) - 1)\n// after\nMockDocumentEmbedder(dimension=max(1, len(configured_embeddings)))","handlingStrategy":"validation","validationCode":"dimension = int(dimension)\nif dimension <= 0:\n    dimension = 768\nembedder = MockDocumentEmbedder(dimension=dimension)","typeGuard":"def is_valid_dimension(d) -> bool:\n    return isinstance(d, int) and d > 0","tryCatchPattern":"try:\n    embedder = MockDocumentEmbedder(dimension=dimension)\nexcept ValueError:\n    embedder = MockDocumentEmbedder(dimension=768)","preventionTips":["Never leave dimension at 0 as a placeholder; use a realistic value like 384/768/1536","Validate config values before constructing components","Compute dimension from a non-empty source and add an assert len(...) > 0"],"tags":["configuration","validation","mock","python"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}