fix: make DocList.to_json() return str instead of bytes #1769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💥 Contains breaking change
This changes the return type of
DocList.to_json()
andDocVec.to_json()
from bytes to str, by decoding the bytes output obtained from theorjson
library.This is done to make it consistent with
to_json()
onBaseDoc
and in pydantic.from_json()
does not need to be touched, since orjson happily accepts strings as well.This decoding step incurs a small performance penalty:

Running this multiple times I saw a
to_json()
performance penalty of 8-15%, depending on the run.The
to_json()
/from_json()
roundrip penalty was consistently single digit percent, presumably because thefrom_json()
call dominates this runtime.Note the breaking change this induces in cases like the one shown in the documentation that is also changed as part of this PR.
Also note that in the scenario there, after this change, a bytes object will be decoded to string, only to be encoded into bytes again.
closes #1766