Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ else if (o instanceof Double) {
else if (o instanceof Boolean) {
gen.write(key, (Boolean) o);
}
else if (o instanceof OracleJsonValue oracleJsonValue) {
gen.write(key, oracleJsonValue);
}
}
gen.writeEnd();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.sql.DataSource;

import oracle.jdbc.pool.OracleDataSource;
import oracle.sql.json.OracleJsonValue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down Expand Up @@ -289,6 +290,49 @@ public void documentUpdate(String distanceType) {
});
}

@Test
void shouldPreserveMetadataWhenRetrievedDocumentIsAddedAgain() {
this.contextRunner
.withPropertyValues("test.spring.ai.vectorstore.oracle.distanceType=COSINE",
"test.spring.ai.vectorstore.oracle.searchAccuracy=" + OracleVectorStore.DEFAULT_SEARCH_ACCURACY)
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);

Document original = new Document(UUID.randomUUID().toString(), "Spring AI Oracle metadata round trip",
Map.of("conversationId", "conversation-123"));

vectorStore.add(List.of(original));

SearchRequest searchRequest = SearchRequest.builder()
.query("Spring AI Oracle metadata round trip")
.topK(1)
.similarityThresholdAll()
.build();

List<Document> firstResults = vectorStore.similaritySearch(searchRequest);

assertThat(firstResults).hasSize(1);

Document retrieved = firstResults.get(0);

assertThat(retrieved.getId()).isEqualTo(original.getId());
assertThat(retrieved.getMetadata().get("conversationId")).isInstanceOfSatisfying(OracleJsonValue.class,
value -> assertThat(value.asJsonString().getString()).isEqualTo("conversation-123"));

// Re-add the document returned by OracleVectorStore.
vectorStore.add(List.of(retrieved));

List<Document> secondResults = vectorStore.similaritySearch(searchRequest);

assertThat(secondResults).hasSize(1);
assertThat(secondResults.get(0).getMetadata().get("conversationId")).isInstanceOfSatisfying(
OracleJsonValue.class,
value -> assertThat(value.asJsonString().getString()).isEqualTo("conversation-123"));

dropTable(context, ((OracleVectorStore) vectorStore).getTableName());
});
}

@ParameterizedTest(name = "{0} : {displayName} ")
@ValueSource(strings = { "COSINE", "DOT" })
public void searchWithThreshold(String distanceType) {
Expand Down
Loading