apache/beam · error · ValueError

Expected text content in {type(item).__name__} {item.id}, go

Error message

Expected text content in {type(item).__name__} {item.id}, got None

What it means

_extract_text in apache_beam.ml.rag.embeddings.base raises this ValueError when an EmbeddableItem in the batch has no content.text (None or empty). The helper collects text strings for embedding calls, and embedding APIs require non-empty text, so items lacking text are rejected with an error identifying the item's class and id. It runs inside the batching path of the embedding PTransform, so it surfaces at pipeline runtime on workers.

Source

Thrown at sdks/python/apache_beam/ml/rag/embeddings/base.py:55

  results back as Embedding objects.

  Returns:
      EmbeddingTypeAdapter configured for text embedding
  """
  return EmbeddingTypeAdapter(
      input_fn=_extract_text, output_fn=_add_embedding_fn)


# Backward compatibility alias.
create_rag_adapter = create_text_adapter


def _extract_text(items: Sequence[EmbeddableItem]) -> list[str]:
  """Extract text from items for embedding."""
  texts = []
  for item in items:
    if not item.content.text:
      raise ValueError(
          f"Expected text content in {type(item).__name__} {item.id}, "
          "got None")
    texts.append(item.content.text)
  return texts


def _add_embedding_fn(
    items: Sequence[EmbeddableItem],
    embeddings: Sequence[list[float]]) -> list[EmbeddableItem]:
  """Create Embeddings from items and embedding vectors."""
  for item, embedding in zip(items, embeddings):
    item.embedding = Embedding(dense_embedding=embedding)
  return list(items)

View on GitHub (pinned to 12126d8942)

Solutions

  1. Filter out or fill items with missing text before the embedding transform: beam.Filter(lambda x: x.content.text).
  2. Fix upstream extraction so content.text is populated for every item.
  3. Route image-only items to an image embeddings manager (e.g. HuggingfaceImageEmbeddings) instead of a text one.
  4. Log/inspect item.id from the error message to find the offending record at the source.

Example fix

// before
embedded = pcoll | embedder

// after
embedded = (pcoll
    | beam.Filter(lambda item: item.content.text)
    | embedder)
Defensive patterns

Strategy: validation

Validate before calling

import apache_beam as beam

def filter_items_without_text(pcoll):
    return pcoll | 'DropEmptyText' >> beam.Filter(
        lambda item: bool(item.content and item.content.text))

Type guard

def has_text(item) -> bool:
    content = getattr(item, 'content', None)
    return bool(content is not None and getattr(content, 'text', None))

Try / catch

try:
    result = pcoll | embedder
except ValueError as e:
    # e.g. 'Expected text content in EmbeddableItem <id>, got None'
    logging.error('Embedding input missing text: %s', e)
    raise

Prevention

When it happens

Trigger: Featuring an input document whose text field was never set (e.g. dict missing the mapped text key, or content.text=None) and passing it through an embeddings manager like VertexAITextEmbeddings or HuggingfaceTextEmbeddings; upstream transforms producing empty records; JSON/CSV rows with null text columns.

Common situations: ETL producing documents where the text field name changed (doc['content'] vs doc['contents']); filtered/empty records from a database; files that failed parsing upstream yielding empty text; passing image-only items to a text embeddings manager.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/36259174fcce47e2. Report an issue: GitHub.