Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Serialization Failure with Embedding and TextSegment Classes in Redis Cache Using Various JSON Serializers #970

Open
juinjonn opened this issue Apr 18, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@juinjonn
Copy link

Description:

When attempting to serialize the Embedding and TextSegment classes for Redis caching, serialization continuously fails due to the absence of getter and setter methods. I have tried using FastJson, Jackson, and Gson, but all attempts result in serialization errors. Below is the specific error encountered with Gson deserialization.

Environment:

Language/Framework: Java with Spring Framework
Libraries: Gson, Jackson, FastJson (latest versions)
Database: Redis
Error Message:

Java

java.util.concurrent.ExecutionException: java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to dev.langchain4j.data.embedding.Embedding
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1928)
	... (additional stack trace)

Steps to Reproduce:

Configure Redis caching in a Spring application.
Attempt to cache an instance of Embedding or TextSegment using Gson for serialization.
Observe the failure in serialization with a ClassCastException.
Expected Behavior:
The classes should serialize and deserialize without errors, allowing them to be cached and retrieved from Redis.

Actual Behavior:
Serialization fails, throwing a ClassCastException when attempting to deserialize using Gson, and similar issues occur with FastJson and Jackson.

Additional Information:

The Embedding class contains an array of floats and does not have explicit getter and setter methods, which might be contributing to the serialization issues.
The TextSegment class similarly lacks getter and setter methods for its fields.
Possible Solutions Tried:

Adding getter and setter methods to the classes.
Using different configurations for serializers.
Questions:

Are there recommended practices for serializing complex objects like these for Redis caching that might circumvent these issues?
Is there a need for custom serializers or configurations that can handle the absence of traditional getter and setter methods?

@juinjonn juinjonn added the enhancement New feature or request label Apr 18, 2024
@langchain4j
Copy link
Owner

@juinjonn could you please clarify your use case? Why/how do you cache that? Thanks!

@langchain4j
Copy link
Owner

langchain4j commented Apr 22, 2024

Just in case, there is a Redis integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants