Improve performance of streaming JSON output by using an event-based JSON parser #27911
doerwalter
announced in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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