{"record":{"id":"5109fc2c30ccd814","repo":"deepset-ai/haystack","slug":"pass-either-embedding-or-embedding-fn-not-bot","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_document_embedder.py","lineNumber":89,"sourceCode":"            `embedding_fn`. If neither is provided, a deterministic embedding is derived from each document's text.\n        :param embedding_fn: An optional callable that receives the prepared text of a document and returns the\n            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","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_document_embedder.py#L71-L107","documentation":"MockDocumentEmbedder lets you supply either a fixed `embedding` (list of numbers) or an `embedding_fn` (callable producing embeddings), but the two are mutually exclusive — the constructor raises this ValueError if both are non-None. This is an intentional design guard so the source of the mock embedding is unambiguous.","triggerScenarios":"`MockDocumentEmbedder(embedding=[0.1, 0.2], embedding_fn=lambda texts: [[0.0]*2])` — both parameters provided in the same constructor call.","commonSituations":"Merging configuration from two sources (defaults plus overrides) so both end up set; copying an example that used `embedding_fn` while your own code already passes `embedding`; refactoring to a callable but leaving the static list in place.","solutions":["Remove either the `embedding` argument or the `embedding_fn` argument so only one is passed","If you need dynamic values, keep `embedding_fn` and delete the static `embedding`; for a fixed vector keep `embedding` only"],"exampleFix":"// before\nMockDocumentEmbedder(embedding=[0.1, 0.2], embedding_fn=lambda texts: [[0.1, 0.2]])\n// after\nMockDocumentEmbedder(embedding_fn=lambda texts: [[0.1, 0.2]])","handlingStrategy":"validation","validationCode":"if embedding is not None and embedding_fn is not None:\n    raise ValueError(\"Choose only one of embedding / embedding_fn\")\nembedder = MockDocumentEmbedder(embedding=embedding, embedding_fn=embedding_fn)","typeGuard":null,"tryCatchPattern":"try:\n    embedder = MockDocumentEmbedder(embedding=emb, embedding_fn=fn)\nexcept ValueError as e:\n    logging.error(\"Mock embedder misconfigured: %s\", e)\n    embedder = MockDocumentEmbedder(embedding_fn=fn if fn is not None else None) or MockDocumentEmbedder(embedding=emb)","preventionTips":["Only ever set one of the two parameters in your fixtures/config","If merging configs, explicitly drop one of the keys","Add a unit test constructing your standard mock embedder config"],"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"}