RyanCodrai/turbovec · error · ValueError

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

Raised in embedding_retrieval when query_embedding is empty or its first element is not a Real number. Matches the reference store's up-front validation (issue #301): a bad query vector is a caller error even if the store is empty. Real (not float) is accepted so numpy scalars and ints work.

Source

Thrown at turbovec-python/python/turbovec/haystack.py:614

        when the filter is selective.

        :raises ValueError: if ``query_embedding`` is empty or does not
            hold numbers, if its dim does not match the store's, or if
            ``top_k`` is negative. (``top_k=-1`` is rejected here where
            ``InMemoryDocumentStore`` returns ``n - 1`` documents — a
            negative count is a caller bug, not a request.)
        """
        # `return_embedding` is accepted but we never have the full
        # embedding to populate; left as-is for signature parity.
        _ = return_embedding  # noqa: F841

        # Up-front validation, matching the reference: an empty or
        # non-numeric query embedding is a caller error regardless of
        # whether the store happens to be empty (issue #301). `Real`
        # rather than the reference's `isinstance(..., float)` so numpy
        # scalars and ints are accepted.
        if len(query_embedding) == 0 or not isinstance(query_embedding[0], Real):
            raise ValueError("query_embedding should be a non-empty list of floats.")

        if self.count_documents() == 0:
            return []

        qvec = np.asarray(query_embedding, dtype=np.float32)
        if qvec.ndim == 1:
            qvec = qvec[None, :]
        # By this point n_documents > 0, so the index has a committed dim.
        expected_dim = self._index.dim
        if qvec.shape[1] != expected_dim:
            raise ValueError(
                f"query_embedding dim {qvec.shape[1]} does not match store dim {expected_dim}"
            )
        # Cosine mode: normalize the query so the raw score against unit
        # document vectors is true cosine similarity.
        if self._vectors_normalized:
            qvec = l2_normalize_rows(qvec)
        if not qvec.flags["C_CONTIGUOUS"]:

View on GitHub (pinned to ccab9f325e)

Solutions

  1. Pass a non-empty list of numeric floats — the output of the embedder's run() on the query text.
  2. Check the embedding pipeline: an empty or non-numeric result means the embedder failed or was fed the wrong input.
  3. Catch the ValueError in retrieval components to distinguish caller errors from empty-result cases (an empty store returns []).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at turbovec-python/python/turbovec/haystack.py:614 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of RyanCodrai/turbovec@ccab9f325e (2026-09-06). Data as JSON: /api/errors/8c24fffcd5938759. Report an issue: GitHub.