{"record":{"id":"633efaf29a962b86","repo":"deepset-ai/haystack","slug":"name-must-not-be-empty","errorCode":null,"errorMessage":"{name} must not be empty.","messagePattern":"(.+?) must not be empty\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/mock_utils.py","lineNumber":52,"sourceCode":"    \"\"\"\n    digest = hashlib.sha256(text.encode(\"utf-8\")).digest()\n    seed = int.from_bytes(digest[:8], \"big\")\n    rng = random.Random(seed)\n    vector = [rng.uniform(-1.0, 1.0) for _ in range(dimension)]\n    return _l2_normalize(vector)\n\n\ndef _coerce_embedding(value: object, *, name: str) -> list[float]:\n    \"\"\"\n    Validate that `value` is a non-empty sequence of numbers and coerce it into a list of floats.\n\n    :param value: The value to validate, e.g. a user-provided fixed embedding or the output of an `embedding_fn`.\n    :param name: How to refer to `value` in error messages, e.g. ``\"'embedding'\"``.\n    \"\"\"\n    if not isinstance(value, (list, tuple)) or not all(isinstance(item, (int, float)) for item in value):\n        raise TypeError(f\"{name} must be a sequence of numbers, got {type(value)}.\")\n    if len(value) == 0:\n        raise ValueError(f\"{name} must not be empty.\")\n    return [float(item) for item in value]\n\n\ndef _estimate_usage(texts: list[str]) -> dict[str, int]:\n    \"\"\"\n    Roughly estimate token usage as whitespace-separated word counts.\n\n    This is an approximation (not real tokenization) intended to give downstream code realistic-looking metadata.\n    \"\"\"\n    prompt_tokens = sum(len(text.split()) for text in texts)\n    return {\"prompt_tokens\": prompt_tokens, \"total_tokens\": prompt_tokens}\n","sourceCodeStart":34,"sourceCodeEnd":64,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_utils.py#L34-L64","documentation":"`_coerce_embedding` rejects empty sequences: an embedding with zero components is meaningless and would break downstream vector comparisons, so passing `embedding=[]` (or an `embedding_fn` returning `[]`) raises this ValueError. The `name` placeholder identifies which argument was empty.","triggerScenarios":"`MockTextEmbedder(embedding=[])`, `MockDocumentEmbedder(embedding=())`, or `embedding_fn=lambda t: []` returning an empty list at embed time.","commonSituations":"Building the embedding from an empty collection (e.g. splitting an empty string); a config file with `\"embedding\": []`; a fixture that filters out all values; an embedding_fn hitting an empty branch.","solutions":["Provide a non-empty embedding, e.g. `embedding=[0.1, 0.2, 0.3]`","If the vector is computed, guard with a length check and raise/default before constructing","Ensure `embedding_fn` always returns at least one number"],"exampleFix":"// before\nparts = value.split(\",\")\nMockTextEmbedder(embedding=[float(p) for p in parts])  # crashes when value == \"\"\n// after\nembedding = [float(p) for p in value.split(\",\")] if value else [0.0]\nMockTextEmbedder(embedding=embedding)","handlingStrategy":"validation","validationCode":"if not embedding:\n    embedding = [0.0]\nembedder = MockDocumentEmbedder(embedding=embedding)","typeGuard":"def is_non_empty_embedding(value) -> bool:\n    return isinstance(value, (list, tuple)) and len(value) > 0","tryCatchPattern":"try:\n    embedder = MockDocumentEmbedder(embedding=embedding)\nexcept ValueError:\n    embedder = MockDocumentEmbedder(embedding=[0.0] * fallback_dimension)","preventionTips":["Check for empty lists before passing computed embeddings","Give embedding_fn a guaranteed non-empty return path","Fix fixtures that parse empty strings into empty embedding lists"],"tags":["validation","mock","embedding","empty-value"],"backgroundTag":"empty-collection-argument","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}