{"record":{"id":"2ea86fedcf20f348","repo":"deepset-ai/haystack","slug":"name-must-be-a-sequence-of-numbers-got-type-va","errorCode":null,"errorMessage":"{name} must be a sequence of numbers, got {type(value)}.","messagePattern":"(.+?) must be a sequence of numbers, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/mock_utils.py","lineNumber":50,"sourceCode":"    :param dimension: The number of dimensions of the resulting embedding.\n    :returns: A deterministic, L2-normalized embedding of length `dimension`.\n    \"\"\"\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":32,"sourceCodeEnd":64,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_utils.py#L32-L64","documentation":"`_coerce_embedding` validates that a value used as an embedding (either a fixed `embedding` argument or the return value of an `embedding_fn`) is a non-empty list or tuple of int/float. Anything else raises this TypeError, with `name` telling you which parameter failed. This catches bad mock configuration early instead of producing corrupt embeddings.","triggerScenarios":"`MockTextEmbedder(embedding=\"abc\")`, `embedding=0.5` (scalar, not a sequence), `embedding_fn=lambda t: [\"a\", \"b\"]` (non-numeric items), or `embedding=np.array([...])` if numpy arrays are not list/tuple — passed via `MockDocumentEmbedder`/`MockTextEmbedder` `__init__` or returned from `_embed`.","commonSituations":"Passing a numpy array or torch tensor as a fixed embedding (not list/tuple); embedding_fn returning strings or nested lists; a JSON config providing a string instead of a numeric array.","solutions":["Convert to a plain list of numbers first: `embedding=[float(x) for x in np.array_value]`","Ensure `embedding_fn` returns a flat list/tuple of int/float, not strings, None, or nested lists","Check the config/fixture supplying the embedding — it must be a JSON array of numbers"],"exampleFix":"// before\nMockDocumentEmbedder(embedding=np.zeros(768))\n// after\nMockDocumentEmbedder(embedding=[0.0] * 768)","handlingStrategy":"type-guard","validationCode":"def _valid_embedding(v):\n    return isinstance(v, (list, tuple)) and len(v) > 0 and all(isinstance(x, (int, float)) for x in v)\nassert _valid_embedding(embedding)\nembedder = MockDocumentEmbedder(embedding=embedding)","typeGuard":"def is_numeric_sequence(value) -> bool:\n    return isinstance(value, (list, tuple)) and all(isinstance(item, (int, float)) for item in value)","tryCatchPattern":"try:\n    embedder = MockDocumentEmbedder(embedding=embedding)\nexcept TypeError:\n    embedding = [float(x) for x in embedding]  # e.g. numpy array or tensor\n    embedder = MockDocumentEmbedder(embedding=embedding)","preventionTips":["Convert numpy/torch arrays with .tolist() before passing as embedding","Ensure embedding_fn returns a flat list of numbers, never strings or nested lists","Validate JSON fixtures load embeddings as numeric arrays, not strings"],"tags":["type-error","validation","mock","embedding"],"backgroundTag":"invalid-embedding-format","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}