Skip to content

Commit 0239619

Browse files
committed
Remove embedding from Document
- This PR removes the reference of `embedding` from the `Document` object. - The Document is designed to contain the content and its metadata but not the embedding representation of its content. This provides clear separation of concern. - Prior to this change, all the vector stores are updated by not depending on the embedding from Document. Instead, use the embedding values returned by the Embedding Models directly: #1826 Resolves #1781
1 parent 69cd317 commit 0239619

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

spring-ai-core/src/main/java/org/springframework/ai/document/Document.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ public class Document {
122122
@Nullable
123123
private final Double score;
124124

125-
/**
126-
* Embedding of the document. Note: ephemeral field.
127-
*/
128-
@JsonProperty(index = 100)
129-
private float[] embedding = new float[0];
130-
131125
/**
132126
* Mutable, ephemeral, content to text formatter. Defaults to Document text.
133127
*/
@@ -260,22 +254,6 @@ public Double getScore() {
260254
return this.score;
261255
}
262256

263-
/**
264-
* Return the embedding that were calculated.
265-
* @deprecated We are considering getting rid of this, please comment on
266-
* https://github.com/spring-projects/spring-ai/issues/1781
267-
* @return the embeddings
268-
*/
269-
@Deprecated(since = "1.0.0-M4")
270-
public float[] getEmbedding() {
271-
return this.embedding;
272-
}
273-
274-
public void setEmbedding(float[] embedding) {
275-
Assert.notNull(embedding, "embedding must not be null");
276-
this.embedding = embedding;
277-
}
278-
279257
/**
280258
* Returns the content formatter associated with this document.
281259
* @deprecated We are considering getting rid of this, please comment on
@@ -436,9 +414,7 @@ public Document build() {
436414
if (!StringUtils.hasText(this.id)) {
437415
this.id = this.idGenerator.generateId(this.text, this.metadata);
438416
}
439-
var document = new Document(this.id, this.text, this.media, this.metadata, this.score);
440-
document.setEmbedding(this.embedding);
441-
return document;
417+
return new Document(this.id, this.text, this.media, this.metadata, this.score);
442418
}
443419

444420
}

spring-ai-core/src/test/java/org/springframework/ai/document/DocumentTests.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616

1717
package org.springframework.ai.document;
1818

19+
import java.net.MalformedURLException;
20+
import java.net.URL;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
1924
import org.junit.jupiter.api.Test;
2025

2126
import org.springframework.ai.document.id.IdGenerator;
2227
import org.springframework.ai.model.Media;
2328
import org.springframework.util.MimeTypeUtils;
2429

25-
import java.net.MalformedURLException;
26-
import java.net.URL;
27-
import java.util.HashMap;
28-
import java.util.List;
29-
import java.util.Map;
30-
3130
import static org.assertj.core.api.Assertions.assertThat;
3231
import static org.junit.jupiter.api.Assertions.assertThrows;
3332

@@ -211,15 +210,6 @@ void testMetadataKeyValueAddition() {
211210
assertThat(document.getMetadata()).containsEntry("key1", "value1").containsEntry("key2", "value2");
212211
}
213212

214-
@Test
215-
void testEmbeddingOperations() {
216-
float[] embedding = new float[] { 0.1f, 0.2f, 0.3f };
217-
218-
Document document = Document.builder().text("test").embedding(embedding).build();
219-
220-
assertThat(document.getEmbedding()).isEqualTo(embedding);
221-
}
222-
223213
@Test
224214
void testNullEmbeddingThrowsException() {
225215
assertThrows(IllegalArgumentException.class, () -> Document.builder().text("test").embedding(null).build());

0 commit comments

Comments
 (0)