{"record":{"id":"a30766c75ab7ae81","repo":"deepset-ai/haystack","slug":"pass-either-embedding-or-embedding-fn-not-bot-a30766","errorCode":null,"errorMessage":"Pass either 'embedding' or 'embedding_fn', not both.","messagePattern":"Pass either 'embedding' or 'embedding_fn', not both\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/mock_text_embedder.py","lineNumber":78,"sourceCode":"        Creates an instance of MockTextEmbedder.\n\n        :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,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_text_embedder.py#L60-L96","documentation":"MockTextEmbedder accepts either a fixed `embedding` or an `embedding_fn`, not both. Supplying both is ambiguous, so the constructor raises this ValueError. This keeps the mock's embedding source deterministic and explicit.","triggerScenarios":"`MockTextEmbedder(embedding=[0.1], embedding_fn=lambda text: [0.1])` — both arguments non-None in one constructor call.","commonSituations":"Combining a base config with an override so both fields end up populated; switching from a fixed vector to a callable during refactoring and leaving the old argument; copy-pasting fixture code that already set `embedding`.","solutions":["Keep only one of `embedding` / `embedding_fn` in the constructor call","Delete the static `embedding` if the callable should drive values, or drop `embedding_fn` for a fixed vector"],"exampleFix":"// before\nMockTextEmbedder(embedding=[0.1, 0.2], embedding_fn=lambda t: [0.1, 0.2])\n// after\nMockTextEmbedder(embedding=[0.1, 0.2])","handlingStrategy":"validation","validationCode":"if embedding is not None and embedding_fn is not None:\n    embedding = None  # keep embedding_fn\nembedder = MockTextEmbedder(embedding=embedding, embedding_fn=embedding_fn)","typeGuard":null,"tryCatchPattern":"try:\n    embedder = MockTextEmbedder(embedding=emb, embedding_fn=fn)\nexcept ValueError as e:\n    logging.warning(\"Both embedding sources given: %s\", e)\n    embedder = MockTextEmbedder(embedding_fn=fn)","preventionTips":["Pick one embedding source convention for your test suite and stick to it","When refactoring to embedding_fn, delete the old embedding argument in the same change","Lint fixtures for constructor calls passing both keys"],"tags":["configuration","mock","python","parameters"],"backgroundTag":"conflicting-parameters","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}