{"record":{"id":"de093b96e8207264","repo":"spring-projects/spring-ai","slug":"media-type-string-overrides-the-document-text-cont","errorCode":null,"errorMessage":"Media type String overrides the Document text content!","messagePattern":"Media type String overrides the Document text content!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java","lineNumber":183,"sourceCode":"\t\t\tinstanceBuilder.dimension(mergedOptions.getDimensions());\n\t\t}\n\n\t\t// optional text parameter\n\t\tString documentText = document.getText();\n\t\tif (StringUtils.hasText(documentText)) {\n\t\t\tinstanceBuilder.text(documentText);\n\t\t\tdocumentMetadata.put(ModalityType.TEXT,\n\t\t\t\t\tnew DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, documentText));\n\t\t}\n\n\t\tMedia media = document.getMedia();\n\t\tif (media != null) {\n\t\t\tif (media.getMimeType().isCompatibleWith(TEXT_MIME_TYPE)) {\n\t\t\t\tinstanceBuilder.text(media.getData().toString());\n\t\t\t\tdocumentMetadata.put(ModalityType.TEXT,\n\t\t\t\t\t\tnew DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, media.getData()));\n\t\t\t\tif (logger.isWarnEnabled() && StringUtils.hasText(documentText)) {\n\t\t\t\t\tlogger.warn(\"Media type String overrides the Document text content!\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (media.getMimeType().isCompatibleWith(IMAGE_MIME_TYPE)) {\n\t\t\t\tif (SUPPORTED_IMAGE_MIME_SUB_TYPES.contains(media.getMimeType())) {\n\t\t\t\t\tinstanceBuilder.image(ImageBuilder.of(media.getMimeType()).imageData(media.getData()).build());\n\t\t\t\t\tdocumentMetadata.put(ModalityType.IMAGE,\n\t\t\t\t\t\t\tnew DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));\n\t\t\t\t}\n\t\t\t\telse if (logger.isWarnEnabled()) {\n\t\t\t\t\tlogger.warn(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t\tthrow new IllegalArgumentException(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {\n\t\t\t\tinstanceBuilder.video(VideoBuilder.of(media.getMimeType())\n\t\t\t\t\t.videoData(media.getData())\n\t\t\t\t\t.startOffsetSec(mergedOptions.getVideoStartOffsetSec())\n\t\t\t\t\t.endOffsetSec(mergedOptions.getVideoEndOffsetSec())","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java#L165-L201","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew Document(text, Map.of(), List.of(Media.builder().mimeType(MimeTypeUtils.TEXT_PLAIN).data(text).build()));\n// after\nnew Document(Media.builder().mimeType(MimeTypeUtils.TEXT_PLAIN).data(text).build());","handlingStrategy":"validation","validationCode":"if (doc.getMedia() != null && StringUtils.hasText(doc.getText())\n        && doc.getMedia().getMimeType().isCompatibleWith(MimeTypeUtils.TEXT_PLAIN)) {\n    throw new IllegalArgumentException(\"Document has both text content and text media; pick one\");\n}","typeGuard":"boolean hasConflictingText(org.springframework.ai.document.Document d) {\n    return d.getMedia() != null\n        && d.getMedia().getMimeType().isCompatibleWith(MimeTypeUtils.TEXT_PLAIN)\n        && StringUtils.hasText(d.getText());\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["vertex-ai","embedding","multimodal","document","media"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}