{"record":{"id":"4a0439a1ebe56733","repo":"apache/beam","slug":"expected-image-content-in-type-item-name-item-id-got-none-4a0439","errorCode":null,"errorMessage":"Expected image content in {type(item).__name__} {item.id}, got None","messagePattern":"Expected image content in (.+?) (.+?), got None","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/rag/embeddings/vertex_ai.py","lineNumber":112,"sourceCode":"        credentials=self.credentials,\n    )\n\n  def get_ptransform_for_processing(\n      self, **kwargs\n  ) -> beam.PTransform[beam.PCollection[EmbeddableItem],\n                       beam.PCollection[EmbeddableItem]]:\n    \"\"\"Returns PTransform that uses the RAG adapter.\"\"\"\n    return RunInference(\n        model_handler=_TextEmbeddingHandler(self),\n        inference_args=self.inference_args).with_output_types(EmbeddableItem)\n\n\ndef _extract_images(items: Sequence[EmbeddableItem]) -> list:\n  \"\"\"Extract images from items and convert to vertexai Image objects.\"\"\"\n  images = []\n  for item in items:\n    if not item.content.image:\n      raise ValueError(\n          \"Expected image content in \"\n          f\"{type(item).__name__} {item.id}, \"\n          \"got None\")\n    img_data = item.content.image\n    if isinstance(img_data, bytes):\n      images.append(Image(image_bytes=img_data))\n    else:\n      images.append(Image.load_from_file(img_data))\n  return images\n\n\ndef _create_image_adapter(\n) -> EmbeddingTypeAdapter[EmbeddableItem, EmbeddableItem]:\n  \"\"\"Creates adapter for Vertex AI image embedding.\n\n  Extracts content.image from EmbeddableItems and converts\n  to vertexai.vision_models.Image objects. Supports both\n  raw bytes and file paths/URIs.","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/rag/embeddings/vertex_ai.py#L94-L130","documentation":"VertexAIImageEmbeddings processes items that must carry image data in item.content.image. _extract_images iterates over a batch of EmbeddableItem objects and raises ValueError when any item's content.image is None, because a vertexai Image object cannot be constructed from missing data. This is a fail-fast check so a bad item does not silently produce an empty embedding.","triggerScenarios":"Calling VertexAIImageEmbeddings via RunInference/EmbeddingsManager over a PCollection of EmbeddableItem where at least one item has content set to text-only or content.image is None (e.g. items built from text chunks, or image bytes never populated in the pipeline).","commonSituations":"Mixed-text/image datasets where text items flow into an image embedder; a parse/ingestion step that fails to set image bytes; using the wrong embedder class (VertexAITextEmbeddings vs VertexAIImageEmbeddings) for the data.","solutions":["Populate item.content.image with valid image bytes before the embedding step.","Filter or partition the PCollection so only items with non-None content.image reach VertexAIImageEmbeddings.","Use VertexAITextEmbeddings for text-only items.","Wrap extraction with a pre-check that drops/logs items missing image content instead of failing the whole batch."],"exampleFix":"// before\nitems = [EmbeddableItem(id='a', content=Content(image=None))]\nembeddings = VertexAIImageEmbeddings(...)\n// after\nitems = [EmbeddableItem(id='a', content=Content(image=img_bytes))]\n# or filter:\nitems = [it for it in items if it.content.image is not None]\nembeddings = VertexAIImageEmbeddings(...)","handlingStrategy":"validation","validationCode":"def has_image(item):\n    return item.content is not None and item.content.image is not None\nvalid_items = [it for it in items if has_image(it)]","typeGuard":"def is_embeddable_image(item) -> bool:\n    try:\n        return isinstance(item.content.image, (bytes, bytearray))\n    except AttributeError:\n        return False","tryCatchPattern":"try:\n    results = embedder.expand(pcoll)\nexcept ValueError as e:\n    if 'Expected image content' in str(e):\n        logging.error('Non-image item in image embedding batch: %s', e)\n        raise","preventionTips":["Filter text items away from image embedders with a separate branch in the pipeline.","Assert image bytes are populated right after the ingestion transform.","Use VertexAITextEmbeddings for text content."],"tags":["python","apache-beam","rag","vertex-ai","validation"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}