diff --git a/spring-ai-core/src/main/java/org/springframework/ai/document/Document.java b/spring-ai-core/src/main/java/org/springframework/ai/document/Document.java index 3a1df9b2f..fee6e38a7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/document/Document.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/document/Document.java @@ -34,10 +34,9 @@ import org.springframework.util.StringUtils; /** * A document is a container for the content and metadata of a document. It also contains - * the document's unique ID and an optional embedding. + * the document's unique ID. * - * A Document can hold either text content or media content, but not both. This ensures - * clear content type handling and processing. + * A Document can hold either text content or media content, but not both. * * It is intended to be used to take data from external sources as part of spring-ai's ETL * pipeline and create an embedding for the text or media and store that embedding in a @@ -122,12 +121,6 @@ public class Document { @Nullable private final Double score; - /** - * Embedding of the document. Note: ephemeral field. - */ - @JsonProperty(index = 100) - private float[] embedding = new float[0]; - /** * Mutable, ephemeral, content to text formatter. Defaults to Document text. */ @@ -260,22 +253,6 @@ public class Document { return this.score; } - /** - * Return the embedding that were calculated. - * @deprecated We are considering getting rid of this, please comment on - * https://github.com/spring-projects/spring-ai/issues/1781 - * @return the embeddings - */ - @Deprecated(since = "1.0.0-M4") - public float[] getEmbedding() { - return this.embedding; - } - - public void setEmbedding(float[] embedding) { - Assert.notNull(embedding, "embedding must not be null"); - this.embedding = embedding; - } - /** * Returns the content formatter associated with this document. * @deprecated We are considering getting rid of this, please comment on @@ -332,8 +309,6 @@ public class Document { private Map metadata = new HashMap<>(); - private float[] embedding = new float[0]; - @Nullable private Double score; @@ -406,12 +381,6 @@ public class Document { return this; } - public Builder embedding(float[] embedding) { - Assert.notNull(embedding, "embedding cannot be null"); - this.embedding = embedding; - return this; - } - /** * Sets a score value for this document. *

@@ -436,9 +405,7 @@ public class Document { if (!StringUtils.hasText(this.id)) { this.id = this.idGenerator.generateId(this.text, this.metadata); } - var document = new Document(this.id, this.text, this.media, this.metadata, this.score); - document.setEmbedding(this.embedding); - return document; + return new Document(this.id, this.text, this.media, this.metadata, this.score); } } diff --git a/spring-ai-core/src/test/java/org/springframework/ai/document/DocumentTests.java b/spring-ai-core/src/test/java/org/springframework/ai/document/DocumentTests.java index b7089afe5..90b83192b 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/document/DocumentTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/document/DocumentTests.java @@ -16,18 +16,17 @@ package org.springframework.ai.document; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + import org.junit.jupiter.api.Test; import org.springframework.ai.document.id.IdGenerator; import org.springframework.ai.model.Media; import org.springframework.util.MimeTypeUtils; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -211,20 +210,6 @@ public class DocumentTests { assertThat(document.getMetadata()).containsEntry("key1", "value1").containsEntry("key2", "value2"); } - @Test - void testEmbeddingOperations() { - float[] embedding = new float[] { 0.1f, 0.2f, 0.3f }; - - Document document = Document.builder().text("test").embedding(embedding).build(); - - assertThat(document.getEmbedding()).isEqualTo(embedding); - } - - @Test - void testNullEmbeddingThrowsException() { - assertThrows(IllegalArgumentException.class, () -> Document.builder().text("test").embedding(null).build()); - } - private static Media getMedia() { try { URL mediaUrl1 = new URL("http://type1");