Skip to content

fix(embedder): or-chain on numpy array raises 'truth value ambiguous' ValueError -- crashes every BgeM3 embed call #287

Closed

Description

@piyushmakhija28

Summary

BgeM3Embedder.embed() at line 232 uses: dense = result.get("dense_vecs") or result.get("dense") or result.get("embeddings"). When FlagEmbedding returns dense_vecs as a non-empty 2D numpy array (which it does on success), Python evaluates bool(numpy_2d_array) for the or short-circuit, raising ValueError: The truth value of an array with more than one element is ambiguous. This makes every successful embed call crash.

Root cause

Fix #245 added the or-chain to probe multiple output keys. The or operator requires bool() evaluation which is ambiguous for multi-element numpy arrays.

Fix

ingestion/embedder.py line 232: use explicit None check instead of or:
dense = next((v for k in ("dense_vecs", "dense", "embeddings") if (v := result.get(k)) is not None), None)

Impact

Every document ingestion using BgeM3Embedder crashes with ValueError when FlagEmbedding returns numpy arrays (which is the default return type).

Activity

  1. piyushmakhija28 commented on Jun 21, 2026

    @piyushmakhija28
    ContributorAuthor

    Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode-reviewFound via automated code reviewpriority: criticalBlocks all requests or crashes startup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions