-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add batching support to map operations with configurable parameters #16
Conversation
Forgot to mention that |
Wow! This looks so thorough. I will review today 🙏🙌🏽 |
Any reason for introducing the Flask dependency? |
Great question! The Flask dependency was initially introduced as a safeguard against XSS and RCE vulnerabilities by ensuring proper escaping of Jinja2 templates. However, after revisiting the issue, I've found that we can achieve the same level of security without Flask by configuring Jinja2's Based on the documentation here, we can remove the Flask dependency and simply configure Jinja2 with: from jinja2 import Environment
env = Environment(autoescape=True) This change would enforce the necessary escaping behavior during template rendering. I’m happy to update the PR to remove the Flask dependency and handle this via Jinja2. Let me know if that works for you! |
Awesome, I'll let you update it to replace Flask with Jinja. We're using Jinja elsewhere too, e.g., here, so it will be good to be consistent. Thank you 🙏🏽 |
Worked out the last few kinks -- I also swapped out the super-unsafe |
Amazing, will check this out, play around with the new functionality, & merge it this weekend! Thank you for taking the time to do this 😄 |
3d2309d
to
bb2b08b
Compare
I went through the PR and most of the changes look good. I ended up removing the parallel map operation batching, since the code did not seem to be changing the functionality. I also removed the semantic similarity functionality here. Overall, I think there is a misunderstanding between Map operation and Reduce operations (I should be more clear in the documents). Map operations are 1:1, where the prompt that the user writes only has access to one input. Reduce operations, on the other hand, are many:1. The example you had in your documentation looked like a reduce operation--and we support semantic similarity grouping for reduce operations actually :-) I think the basic batching that we have now (thanks to you!) is good for limiting parallelism; if there are too many documents in the input, we should not try to process all of them at the same time, so batching is good. But in the future I wonder if it's possible to batch map operations in the same prompt, while ensuring the output still matches that same 1:1 expectation. |
eabb763
to
ebfda87
Compare
Merging into another branch so I can create a PR that runs test. |
e533ea2
into
ucbepic:orban-map-batching
I’ve been thinking along the same lines. The updates to I’ve started working on this already but paused due to the size of the current PR. If we’re aligned on batching, I’m happy to continue and get this integrated. Let me know if you want me to go ahead or focus elsewhere. Appreciate the quick merge! |
Sounds good to me! It would be great to also limit the number of concurrent LLM calls for the ParallelMapOperation. The PR should be a lot smaller :-) LMK if any issues come up! Thank you! |
Summary
This pull request introduces batching support to map operations as described in issue #7, with the aim of significantly enhancing performance and reducing costs when processing small documents. Key updates include new batching parameters, implementation of batching logic, configuration enhancements, expanded testing, and documentation improvements. Additionally, Pydantic models have been introduced in
schemas.py
to simplify and streamline validation logic.Main Changes
Batching Support in Map Operations
batch_size
andclustering_method
to the map operation interface to enable batching functionality.Testing Enhancements
Documentation Improvements
Validation Logic Simplification
schemas.py
to simplify validation logic and improve code maintainability.New Pydantic Models
ToolFunction
: Defines the structure of a tool function with fields forname
,description
, andparameters
.Tool
: Represents a tool with fields forcode
andfunction
.OutputSchema
: Specifies the output schema using aschema
field.MapOperationConfig
: Configures map operations with optional fields such asdrop_keys
,prompt
,output
,model
, andtools
, including a validator fordrop_keys
.ParallelMapOperationConfig
: Configures parallel map operations with fields forprompts
,model
, andtools
.BatchConfig
: Defines batch configurations withbatch_size
and an optionalclustering_method
.OperationConfig
: A generic operation configuration with fields forname
,type
, and a union of specific operation configurations (MapOperationConfig
,ParallelMapOperationConfig
,BatchConfig
).These enhancements collectively improve the efficiency and usability of map operations, making it easier to process small documents at scale while maintaining accuracy and performance.