Open tylerhutcherson opened 2 years ago
Hi! So HashModel extends from BaseModel which means that if isinstance()
actually should pass - we'll take a look at some of the json_encoder stuff and check it out!
It looks like the model.save()
method converts to a dictionary first before it passes to the encoder. This may be ok. I think the piece that's missing here, and the big picture feature request, is support for the vector data types so we can use this library for https://redis.io/docs/stack/search/reference/vectors/
That said - I am ok if we want to just close this thread and use it as a reference for future work on supporting vectors!
Hi!
Working with a
HashModel
that contains some bytes data (for Vector data fields).I need to update the default
jsonable_encoder
with a custom encoder forbytes
.However, I noticed that my
HashModel
would not override theConfig
class from Pydantic. Example:After looking through the src code a bit - I believe I found the culprit. When a model calls the
.save()
method, it first converts itself to a dictionary and then does the encoding: https://github.com/redis/redis-om-python/blob/a00a68b414d50b7a096a98f8d00ee10ddd8cd99f/aredis_om/model/model.py#L1320The issue here is that the
jsonable_encoder
method doesn't properly pass through the custom encoder when this happens. It only passes through custom encoders when the instance is of typeBaseModel
: https://github.com/redis/redis-om-python/blob/a00a68b414d50b7a096a98f8d00ee10ddd8cd99f/aredis_om/model/encoders.py#L72I'd love to be able to change the underlying model config so that when the object is serialized, it works with special data types that need more care :)