Improve performance of streaming JSON output by using an event-based JSON parser #27911
doerwalter
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked
Feature request
Using
langchain_core.output_parsers.json.JsonOutputParser
in streaming mode is really slow for larger JSON output. I'd like to propose an improved JSON parser that uses the event-based JSON parserijson
.Motivation
langchain_core.output_parsers.json.JsonOutputParser
is slow in streaming mode since it reparses the JSON input multiple times during the run. The Python moduleijson
(available at https://pypi.org/project/ijson/) provides an event-based JSON parser that can be used to speed up streaming JSON output.The following test script compares the output of the current
langchain_core.output_parsers.json.JsonOutputParser
with the newincrementaljson.IncrementalJsonOutputParser
(attached below in the "proposal" section):This test produces JSON that is around 6K in length. Running the script outputs the following timing information:
i.e. the current
JsonOutputParser
takes nearly five minutes,IncrementalJsonOutputParser
finishes in 45 seconds.Proposal (If applicable)
The following module implements the proposed new incremental JSON parser:
Beta Was this translation helpful? Give feedback.
All reactions