You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys, I try to understand what is the different of EmbeddedJsonModel and JsonModel and when to use it, i try some example to clarify but cannot find anything.
fromredis.asyncioimportRedisfromuuid_extensionsimportuuid7frompydanticimportAnyUrl, Field, BaseModelfromaredis_omimportJsonModel, EmbeddedJsonModel, Migrator, FieldasRFieldfromaredis_om.model.modelimportmodel_registryfromtypingimportLiteralfromuuidimportUUIDredis=Redis(host='localhost',port=3333,password="ssssss")
classMessage(EmbeddedJsonModel):
role: Literal['user', 'system', 'assistant']
content: strclassMeta:
database=redisclassChatSessionData(EmbeddedJsonModel): # change hereid: str=RField(index=True,primary_key=True)
messages: list[Message] =Field(default_factory=list)
summaries: list[str] =Field(default_factory=list)
urls: list[AnyUrl] =Field(default_factory=list,description="Addition data should be store in object storage and provide url.")
classMeta:
database=redisclassUserData(JsonModel):
username:str=RField(index=True,primary_key=True)
password:strchat_sessions:list[ChatSessionData] =Field(default_factory=list)
classMeta:
database=redisawaitMigrator().run() # create all indexeschat_id=uuid7()
chat_id_str=str(chat_id)
chat_session_data=ChatSessionData(id=chat_id_str,
messages=[Message(role="user",content="this is content")],
summaries=["sum1","sum2"],
urls= ["http://example.com"])
userdata=UserData(username="xxx", password="def",token=uuid7(),chat_sessions= [chat_session_data])
awaituserdata.save()
In the above code, i change EmbeddedJsonModel parent class to both JsonModel and EmbeddedJsonModel. And they store object completely the same in server (monitor in RedisInsight).
Thank you.
The text was updated successfully, but these errors were encountered:
Hello guys, I try to understand what is the different of EmbeddedJsonModel and JsonModel and when to use it, i try some example to clarify but cannot find anything.
In the above code, i change EmbeddedJsonModel parent class to both JsonModel and EmbeddedJsonModel. And they store object completely the same in server (monitor in RedisInsight).
Thank you.
The text was updated successfully, but these errors were encountered: