deepset-ai/haystack · error
query_embedding should be a non-empty list of floats.
Error message
query_embedding should be a non-empty list of floats.
What it means
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.
Source
Thrown at haystack/document_stores/in_memory/document_store.py:816
top_k: int = 10,
scale_score: bool = False,
return_embedding: bool | None = False,
) -> list[Document]:
"""
Retrieves documents that are most similar to the query embedding using a vector similarity metric.
:param query_embedding: Embedding of the query.
:param filters: A dictionary with filters to narrow down the search space.
:param top_k: The number of top documents to retrieve. Default is 10.
:param scale_score: Whether to scale the scores of the retrieved Documents. Default is False.
:param return_embedding: Whether to return the embedding of the retrieved Documents.
If not provided, the value of the `return_embedding` parameter set at component
initialization will be used. Default is False.
:returns: A list of the top_k documents most relevant to the query.
:raises ValueError: if filters have invalid syntax.
"""
if len(query_embedding) == 0 or not isinstance(query_embedding[0], float):
raise ValueError("query_embedding should be a non-empty list of floats.")
if filters:
InMemoryDocumentStore._validate_filters(filters)
all_documents = [
doc
for doc in self.storage.values()
if document_matches_filter(
filters=filters, document=doc, strict_datetime_comparison=self.strict_datetime_comparison
)
]
else:
all_documents = list(self.storage.values())
documents_with_embeddings = [doc for doc in all_documents if doc.embedding is not None]
if len(documents_with_embeddings) == 0:
logger.warning(
"No Documents found with embeddings. Returning empty list. "
"To generate embeddings, use a DocumentEmbedder."View on GitHub (pinned to e318778c9b)
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
Example fix
// before embedding = model.encode(text) # numpy array of np.float32 results = store.embedding_retrieval(query_embedding=embedding) // after results = store.embedding_retrieval(query_embedding=embedding.tolist())
Defensive patterns
Strategy: validation
Validate before calling
def is_valid_query_embedding(e) -> bool:
return bool(e) and isinstance(e, list) and all(isinstance(x, float) for x in e)
if not is_valid_query_embedding(query_embedding):
query_embedding = [float(x) for x in query_embedding] # normalize (also converts numpy floats) Type guard
def is_float_list(x) -> bool:
return isinstance(x, list) and len(x) > 0 and isinstance(x[0], float) Try / catch
try:
docs = store.embedding_retrieval(query_embedding=query_embedding)
except ValueError as e:
if "query_embedding should be a non-empty list of floats" in str(e):
docs = store.embedding_retrieval(query_embedding=[float(x) for x in query_embedding])
else:
raise Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Query should be a non-empty string
- The embedding size of the query should be the same as the em
- Hook of type '{type(h).__name__}' is registered under hook p
- Tool execution requires at least one tool.
- The following tool names are not valid: {invalid_tool_names}
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/156ea530e6a55060.
Report an issue: GitHub.