{"record":{"id":"7e00c49e19fe18d2","repo":"deepset-ai/haystack","slug":"dimension-must-be-a-positive-integer-7e00c4","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_text_embedder.py","lineNumber":80,"sourceCode":"        :param embedding: An optional fixed embedding returned for every input. Mutually exclusive with\n            `embedding_fn`. If neither is provided, a deterministic embedding is derived from the input text.\n        :param embedding_fn: An optional callable that receives the prepared text (after `prefix`/`suffix` are\n            applied) and returns the embedding as a list of floats. Mutually exclusive with `embedding`. To support\n            serialization, pass a 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 the text before embedding.\n        :param suffix: A string to add at the end of the text before embedding.\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._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,\n            embedding=self.embedding,\n            embedding_fn=embedding_fn,\n            dimension=self.dimension,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_text_embedder.py#L62-L98","documentation":"MockTextEmbedder requires `dimension` to be a positive integer, since every produced embedding must have at least one element. Zero or negative values raise this ValueError in `__init__`.","triggerScenarios":"`MockTextEmbedder(dimension=0)` or `MockTextEmbedder(dimension=-3)`; also computed values like `dimension=len([])` that evaluate to 0.","commonSituations":"Dimension read from an empty or unset config entry; arithmetic producing 0 (e.g. subtracting from a length); placeholder values left in tests intending to be filled in later.","solutions":["Pass a positive integer, e.g. `MockTextEmbedder(dimension=384)`","Sanitize the source value: `dimension = value if value and value > 0 else 384`","Trace where the dimension is computed and fix the calculation"],"exampleFix":"// before\nMockTextEmbedder(dimension=len(sizes) - 1)\n// after\nMockTextEmbedder(dimension=len(sizes) or 384)","handlingStrategy":"validation","validationCode":"if not isinstance(dimension, int) or dimension <= 0:\n    dimension = 384\nembedder = MockTextEmbedder(dimension=dimension)","typeGuard":"def is_valid_dimension(d) -> bool:\n    return isinstance(d, int) and d > 0","tryCatchPattern":"try:\n    embedder = MockTextEmbedder(dimension=dimension)\nexcept ValueError:\n    embedder = MockTextEmbedder(dimension=384)","preventionTips":["Use a default like 1536 when config values are missing/zero","Guard arithmetic that derives dimension from lengths","Add config schema validation (dimension: positive int) before app startup"],"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"}