Skip to content

Preserve Oracle vector store metadata - #6702

Open
HuitaePark wants to merge 1 commit into
spring-projects:mainfrom
HuitaePark:fix/oracle-vectorstore-metadata-roundtrip
Open

Preserve Oracle vector store metadata#6702
HuitaePark wants to merge 1 commit into
spring-projects:mainfrom
HuitaePark:fix/oracle-vectorstore-metadata-roundtrip

Conversation

@HuitaePark

@HuitaePark HuitaePark commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #3838

Problem

OracleVectorStore does not preserve user-defined metadata when a document returned by similaritySearch() is added to the vector store again.

When metadata is initially added, values such as strings are represented using standard Java types:

Map.of("conversationId", "conversation-123")

After the document is stored in Oracle and retrieved through similaritySearch(), metadata values read from the Oracle JSON column are represented as OracleJsonValue implementations.

For example, a string metadata value is returned as an Oracle JSON string value rather than a standard Java String.

When the retrieved Document is added again, OracleVectorStore.toJson() only serializes a limited set of Java scalar types:

  • String
  • Integer
  • Float
  • Double
  • Boolean

Because OracleJsonValue was not handled, those metadata entries were silently skipped during serialization.

As a result, the following round trip removed the original user-defined metadata:

Add document
→ Retrieve document from Oracle
→ Add the retrieved document again
→ Retrieve it again

Before this change, the second retrieval contained only generated metadata such as:

{"distance"=0.0}

The original conversationId entry was no longer present.

Changes

This change adds support for serializing OracleJsonValue instances directly through OracleJsonGenerator.

else if (o instanceof OracleJsonValue oracleJsonValue) {
    gen.write(key, oracleJsonValue);
}

This allows metadata returned by Oracle to be written back without being silently discarded.

Testing

Added an integration test that:

  1. Stores a document with user-defined metadata.
  2. Retrieves the document through similaritySearch().
  3. Verifies that the metadata was returned as an OracleJsonValue.
  4. Adds the retrieved document to OracleVectorStore again.
  5. Retrieves the document a second time.
  6. Verifies that the original metadata is still present.

The regression test fails before the fix because the metadata is removed, and passes after OracleJsonValue serialization is supported.

Serialize OracleJsonValue metadata when re-adding documents returned by
OracleVectorStore. Add an integration test covering the metadata
retrieve-and-add round trip.

Fixes spring-projects#3838

Signed-off-by: HuitaePark <qkrgmlxo3174@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oracle Vector Store - METADATA IGNORED

2 participants