Find answers from the community

Updated 3 months ago

Serialized

Is there a way to serialize and deserialize the query result to avoid losing all the information present in a response object while sending the data through HTTP calls ? Struggling to find a clean way to do this. Thanks !
W
L
L
7 comments
Creating the final response that is required at your end and then passing that should work
i) how do you create a response
ii) how do you pass it ?

Its is not a normal dict. The response object has many schema objects that are specific to llama_index.schema which is not directly serializable.
I'm assuming you call an API with a query and in return you want llamaindex returned object right
Plain Text
response = index.as_query_engine().query("USER_QUERY")
# This will convert llama object into a dict
print(response.__dict__)
I already did that. The problem I am facing if I do that is,
if we send it as it is, the JSON loses its structure -> as JSON is converted to str internally. Once we do this, I am not able to load it back as it will lead to JSON decode error.

Also,
Plain Text
relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(
if you look the response object, it contains NodeRelationship, RelatedNodeInfo, etc. which are schema classes that cannot be loaded back from str format, at the receiving end.
The source nodes can be loaded with node.json() and TextNode.parse_raw(json_str)
Add a reply
Sign up and join the conversation on Discord