lancedb/lancedb · error · ValueError

Each input should be either str, bytes, Path or Image.

Error message

Each input should be either str, bytes, Path or Image.

What it means

Voyage AI multimodal inputs must each be str, bytes, Path, or PIL Image; transform_input converts each item into the content dict Voyage expects. An item of any other type hits the else branch and raises ValueError listing the accepted types.

Solutions

  1. Convert image arrays with PIL.Image.fromarray(arr) before embedding
  2. Open bytes with PIL.Image.open(io.BytesIO(data))
  3. Filter or fix None/invalid entries in the input list
  4. Ensure Arrow columns are flattened to lists of str/bytes/Path/Image

Example fix

// before
embed(["text", np_img])  # ValueError
// after
embed(["text", Image.fromarray(np_img)])
Defensive patterns

Strategy: type-guard

Validate before calling

from pathlib import Path

def is_valid_voyage_item(x) -> bool:
    try:
        from PIL import Image
        return isinstance(x, (str, bytes, Path, Image.Image))
    except ImportError:
        return isinstance(x, (str, bytes, Path))

def validate_inputs(items):
    for x in items:
        if not is_valid_voyage_item(x):
            raise TypeError(f"Unsupported item type: {type(x)}")

Type guard

def coerce_voyage_item(x):
    from PIL import Image
    if isinstance(x, (str, bytes, Path, Image.Image)):
        return x
    if hasattr(x, "__array_interface__"):
        import numpy as np
        return Image.fromarray(np.asarray(x))
    raise TypeError(f"Unsupported item type: {type(x)}")

Try / catch

try:
    vectors = emb.compute_source_embeddings(inputs)
except ValueError as e:
    if "str, bytes, Path or Image" in str(e):
        inputs = [coerce_voyage_item(x) for x in inputs]
        vectors = emb.compute_source_embeddings(inputs)
    else:
        raise

Prevention

When it happens

Trigger: Calling compute_source_embeddings / embed with an input list containing an unsupported element (numpy array, dict, list-of-lists, None) that sanitize_multimodal_input passes through to transform_input.

Common situations: Mixing numpy image arrays with text in a batch; passing None placeholders; nested lists from misshaped Arrow columns; passing torch tensors.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of lancedb/lancedb@c7b051aff7 (2026-09-08). Data as JSON: /api/errors/de5c4dad8d9a888c. Report an issue: GitHub.

Appendix: source

Thrown at python/python/lancedb/embeddings/voyageai.py:113

            # Read video file and encode as base64
            with open(input_data, "rb") as f:
                video_bytes = f.read()
            video_str = base64.b64encode(video_bytes).decode("utf-8")
            content = {
                "type": "video_base64",
                "video_base64": video_str,
            }
        else:
            img = PIL_Image.open(input_data)
            buffered = BytesIO()
            img.save(buffered, format="JPEG")
            img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
            content = {
                "type": "image_base64",
                "image_base64": "data:image/jpeg;base64," + img_str,
            }
    else:
        raise ValueError("Each input should be either str, bytes, Path or Image.")

    return {"content": [content]}


def sanitize_multimodal_input(inputs: Union[TEXT, IMAGES]) -> List[Any]:
    """
    Sanitize the input to the embedding function.
    """
    PIL_Image = attempt_import_or_raise("PIL.Image", "pillow")
    if isinstance(inputs, (str, bytes, Path, PIL_Image.Image)):
        inputs = [inputs]
    elif isinstance(inputs, list):
        pass  # Already a list, use as-is
    elif isinstance(inputs, pa.Array):
        inputs = inputs.to_pylist()
    elif isinstance(inputs, pa.ChunkedArray):
        inputs = inputs.combine_chunks().to_pylist()
    else:

View on GitHub (pinned to c7b051aff7)