{"record":{"id":"156ea530e6a55060","repo":"deepset-ai/haystack","slug":"query-embedding-should-be-a-non-empty-list-of-floa","errorCode":null,"errorMessage":"query_embedding should be a non-empty list of floats.","messagePattern":"query_embedding should be a non-empty list of floats\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/document_stores/in_memory/document_store.py","lineNumber":816,"sourceCode":"        top_k: int = 10,\n        scale_score: bool = False,\n        return_embedding: bool | None = False,\n    ) -> list[Document]:\n        \"\"\"\n        Retrieves documents that are most similar to the query embedding using a vector similarity metric.\n\n        :param query_embedding: Embedding of the query.\n        :param filters: A dictionary with filters to narrow down the search space.\n        :param top_k: The number of top documents to retrieve. Default is 10.\n        :param scale_score: Whether to scale the scores of the retrieved Documents. Default is False.\n        :param return_embedding: Whether to return the embedding of the retrieved Documents.\n            If not provided, the value of the `return_embedding` parameter set at component\n            initialization will be used. Default is False.\n        :returns: A list of the top_k documents most relevant to the query.\n        :raises ValueError: if filters have invalid syntax.\n        \"\"\"\n        if len(query_embedding) == 0 or not isinstance(query_embedding[0], float):\n            raise ValueError(\"query_embedding should be a non-empty list of floats.\")\n\n        if filters:\n            InMemoryDocumentStore._validate_filters(filters)\n            all_documents = [\n                doc\n                for doc in self.storage.values()\n                if document_matches_filter(\n                    filters=filters, document=doc, strict_datetime_comparison=self.strict_datetime_comparison\n                )\n            ]\n        else:\n            all_documents = list(self.storage.values())\n\n        documents_with_embeddings = [doc for doc in all_documents if doc.embedding is not None]\n        if len(documents_with_embeddings) == 0:\n            logger.warning(\n                \"No Documents found with embeddings. Returning empty list. \"\n                \"To generate embeddings, use a DocumentEmbedder.\"","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/document_stores/in_memory/document_store.py#L798-L834","documentation":"InMemoryDocumentStore.embedding_retrieval raises ValueError when query_embedding is an empty list or its first element is not a Python float. The check `not isinstance(query_embedding[0], float)` fails fast before any similarity computation.","triggerScenarios":"Passing query_embedding=[]; passing a list of ints (e.g. quantized embeddings); passing a list of numpy floats such as np.float32/np.float64 scalars from an embedder that returns numpy output, since np.floating is not a subclass of Python float.","commonSituations":"Embedder returning an empty list for empty input text, int8/binary quantized embeddings, forgetting to call .tolist() on a numpy array before passing it in.","solutions":["Call .tolist() on numpy arrays: store.embedding_retrieval(query_embedding=model_output.tolist())","Ensure the embedder returns Python floats and that the input text is non-empty","Cast explicitly: query_embedding=[float(x) for x in raw_embedding]","If using quantized/int embeddings, keep them as Python floats or convert per the store's expectations"],"exampleFix":"// before\nembedding = model.encode(text)  # numpy array of np.float32\nresults = store.embedding_retrieval(query_embedding=embedding)\n// after\nresults = store.embedding_retrieval(query_embedding=embedding.tolist())","handlingStrategy":"validation","validationCode":"def is_valid_query_embedding(e) -> bool:\n    return bool(e) and isinstance(e, list) and all(isinstance(x, float) for x in e)\n\nif not is_valid_query_embedding(query_embedding):\n    query_embedding = [float(x) for x in query_embedding]  # normalize (also converts numpy floats)","typeGuard":"def is_float_list(x) -> bool:\n    return isinstance(x, list) and len(x) > 0 and isinstance(x[0], float)","tryCatchPattern":"try:\n    docs = store.embedding_retrieval(query_embedding=query_embedding)\nexcept ValueError as e:\n    if \"query_embedding should be a non-empty list of floats\" in str(e):\n        docs = store.embedding_retrieval(query_embedding=[float(x) for x in query_embedding])\n    else:\n        raise","preventionTips":["Call .tolist() on numpy/torch embedder output before passing it to embedding_retrieval","Cast with float(x) if your embeddings may be ints or numpy scalars","Check the embedder returned a non-empty vector (non-empty input text)"],"tags":["embeddings","retrieval","validation","numpy"],"backgroundTag":"invalid-embedding-dtype","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}