microsoft/autogen · error · ValueError
Image content cannot be converted to text
Error message
Image content cannot be converted to text
What it means
ChromaDBVectorMemory stores documents as plain text, so when you add or query with a MemoryContent whose payload is an Image, _extract_text refuses to serialize it and raises ValueError. ChromaDB's embedding pipeline only accepts strings, so image bytes have no representation in this backend. Use a memory backend that supports multimodal content or omit image items.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py:300
raise
def _extract_text(self, content_item: str | MemoryContent) -> str:
"""Extract searchable text from content."""
if isinstance(content_item, str):
return content_item
content = content_item.content
mime_type = content_item.mime_type
if mime_type in [MemoryMimeType.TEXT, MemoryMimeType.MARKDOWN]:
return str(content)
elif mime_type == MemoryMimeType.JSON:
if isinstance(content, dict):
# Store original JSON string representation
return str(content).lower()
raise ValueError("JSON content must be a dict")
elif isinstance(content, Image):
raise ValueError("Image content cannot be converted to text")
else:
raise ValueError(f"Unsupported content type: {mime_type}")
def _calculate_score(self, distance: float) -> float:
"""Convert ChromaDB distance to a similarity score."""
if self._config.distance_metric == "cosine":
return 1.0 - (distance / 2.0)
return 1.0 / (1.0 + distance)
async def update_context(
self,
model_context: ChatCompletionContext,
) -> UpdateContextResult:
messages = await model_context.get_messages()
if not messages:
return UpdateContextResult(memories=MemoryQueryResult(results=[]))
# Extract query from last messageView on GitHub (pinned to 027ecf0a37)
Solutions
- Filter out Image contents before adding to ChromaDBVectorMemory: check isinstance(content, Image) (or content is not str/dict) and skip or store a text caption instead.
- If you need image memory, use a different Memory implementation or persist a textual description (e.g. an LLM-generated caption) as MemoryMimeType.TEXT.
- If you expected text, verify you did not wrap the string in Image accidentally and that mime_type matches the payload type.
Example fix
// before
await memory.add(MemoryContent(content=Image.from_pil(img), mime_type=MemoryMimeType.IMAGE))
// after
if isinstance(content, Image):
caption = await describe_image(content) # text fallback
await memory.add(MemoryContent(content=caption, mime_type=MemoryMimeType.TEXT))
else:
await memory.add(MemoryContent(content=content, mime_type=MemoryMimeType.TEXT)) Defensive patterns
Strategy: type-guard
Validate before calling
from autogen_core.memory import MemoryContent, MemoryMimeType
from autogen_core import Image
def is_text_storable(item: MemoryContent) -> bool:
return not isinstance(item.content, Image) Type guard
def is_image_content(item: MemoryContent) -> bool:
return isinstance(item.content, Image) Try / catch
try:
await memory.add(item)
except ValueError as e:
if 'Image content' in str(e):
logger.warning('skipping image memory item')
else:
raise Prevention
- Filter isinstance(content, Image) before every add() to ChromaDBVectorMemory
- Store text captions for multimodal items instead of raw images
- Keep one content-normalization helper for all memory writes
When it happens
Trigger: Calling chroma_memory.add(MemoryContent(content=Image.frompil(img), ...)) or query(MemoryContent(content=Image(...))). Also triggered when a MemoryContent was constructed with mime_type=TEXT but the content is an Image instance (the isinstance(content, Image) check fires before the mime-type fallback).
Common situations: Porting an agent from a multimodal context (where messages legitimately contain Image parts) into ChromaDB memory; copying MemoryContent objects straight from a ChatCompletionContext that contains images; filtering only on mime_type instead of the actual payload type.
Related errors
- Image content cannot be converted to text
- JSON content must be a dict
- Unsupported content type: {mime_type}
- Invalid aggregate message {reason}
- Unsupported content type {item.GetType()}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/15ae8948d73bd967.
Report an issue: GitHub.