spring-projects/spring-ai · warning
Media type String overrides the Document text content!
Error message
Media type String overrides the Document text content!
What it means
VertexAiMultimodalEmbeddingModel.doSingleDocumentPrediction (called from singleDocResponse) embeds a Document that carries both plain text content and text-typed media. When the document's Media is compatible with the TEXT mime type, the media data wins and the Document's own text content is discarded; this warning tells you the text content was overridden.
Source
Thrown at models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java:183
instanceBuilder.dimension(mergedOptions.getDimensions());
}
// optional text parameter
String documentText = document.getText();
if (StringUtils.hasText(documentText)) {
instanceBuilder.text(documentText);
documentMetadata.put(ModalityType.TEXT,
new DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, documentText));
}
Media media = document.getMedia();
if (media != null) {
if (media.getMimeType().isCompatibleWith(TEXT_MIME_TYPE)) {
instanceBuilder.text(media.getData().toString());
documentMetadata.put(ModalityType.TEXT,
new DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, media.getData()));
if (logger.isWarnEnabled() && StringUtils.hasText(documentText)) {
logger.warn("Media type String overrides the Document text content!");
}
}
else if (media.getMimeType().isCompatibleWith(IMAGE_MIME_TYPE)) {
if (SUPPORTED_IMAGE_MIME_SUB_TYPES.contains(media.getMimeType())) {
instanceBuilder.image(ImageBuilder.of(media.getMimeType()).imageData(media.getData()).build());
documentMetadata.put(ModalityType.IMAGE,
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
}
else if (logger.isWarnEnabled()) {
logger.warn("Unsupported image mime type: " + media.getMimeType());
throw new IllegalArgumentException("Unsupported image mime type: " + media.getMimeType());
}
}
else if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {
instanceBuilder.video(VideoBuilder.of(media.getMimeType())
.videoData(media.getData())
.startOffsetSec(mergedOptions.getVideoStartOffsetSec())
.endOffsetSec(mergedOptions.getVideoEndOffsetSec())View on GitHub (pinned to 98a7beda4f)
Solutions
- Set the Document content to empty or rely solely on the Media field so only one text source exists.
- Drop the Media when the text you want embedded is the Document content.
- Verify the Media MimeType is correct; if the data is not really text, use the proper mime type so the intended branch runs.
Example fix
// before new Document(text, Map.of(), List.of(Media.builder().mimeType(MimeTypeUtils.TEXT_PLAIN).data(text).build())); // after new Document(Media.builder().mimeType(MimeTypeUtils.TEXT_PLAIN).data(text).build());
Defensive patterns
Strategy: validation
Validate before calling
if (doc.getMedia() != null && StringUtils.hasText(doc.getText())
&& doc.getMedia().getMimeType().isCompatibleWith(MimeTypeUtils.TEXT_PLAIN)) {
throw new IllegalArgumentException("Document has both text content and text media; pick one");
} Type guard
boolean hasConflictingText(org.springframework.ai.document.Document d) {
return d.getMedia() != null
&& d.getMedia().getMimeType().isCompatibleWith(MimeTypeUtils.TEXT_PLAIN)
&& StringUtils.hasText(d.getText());
} Prevention
- Construct Documents with either text content or text Media, never both.
- Clear the original text after attaching equivalent text media in ETL pipelines.
- Validate mime types before building Media.
When it happens
Trigger: Embedding a Document that has both non-empty text (documentText) and a Media field whose MimeType is compatible with text/plain, e.g. Media constructed from a string with MimeTypeUtils.TEXT_PLAIN.
Common situations: ETL pipelines that attach media to documents while keeping the original text; loaders that set both content and media; copying Document instances where the original text was left in place after media was added.
Related errors
- Unsupported image mime type: ${mimeType}
- Unsupported media type: ${mimeType}
- Unsupported media data type:
- Unsupported media data type:
- Required properties for TitanEmbeddingBedrockApi are missing
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/de093b96e8207264.
Report an issue: GitHub.