-
Notifications
You must be signed in to change notification settings - Fork 781
feat(wren-ai-service): add context window size handling in LLMProvider and related components #1693
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
Conversation
…r and related components
WalkthroughA configurable Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LLMProvider
participant PreprocessSqlData
participant preprocess
User->>LLMProvider: get_context_window_size()
LLMProvider-->>User: returns context_window_size
User->>PreprocessSqlData: initialize with llm_provider
PreprocessSqlData->>LLMProvider: get_context_window_size()
PreprocessSqlData-->>PreprocessSqlData: set config["context_window_size"]
PreprocessSqlData->>preprocess: call with context_window_size
preprocess-->>PreprocessSqlData: process data with dynamic token limit
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (1)
298-300
: 🛠️ Refactor suggestionUpdate hardcoded log message to reflect dynamic threshold.
The log message still references the hardcoded value of "100,000" but the actual threshold is now dynamic. This could confuse users when debugging.
- logger.info( - "db_schemas token count is greater than 100,000, so we will prune columns" - ) + logger.info( + f"db_schemas token count is greater than {check_using_db_schemas_without_pruning['tokens']}, so we will prune columns" + )However, this would require accessing the context window size here. A better approach might be to pass the threshold value or access it from the configs:
- logger.info( - "db_schemas token count is greater than 100,000, so we will prune columns" - ) + logger.info( + f"db_schemas token count ({check_using_db_schemas_without_pruning['tokens']}) is greater than context window size, so we will prune columns" + )
🧹 Nitpick comments (1)
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (1)
469-469
: Add error handling for context window size retrieval.The integration with
llm_provider.get_context_window_size()
looks good, but consider adding validation to ensure the returned value is a positive integer.- "context_window_size": llm_provider.get_context_window_size(), + "context_window_size": max(1, llm_provider.get_context_window_size() or 100000),This ensures the context window size is always a positive value with a reasonable fallback.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
deployment/kustomizations/base/cm.yaml
(1 hunks)docker/config.example.yaml
(1 hunks)wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py
(3 hunks)
✅ Files skipped from review due to trivial changes (2)
- docker/config.example.yaml
- deployment/kustomizations/base/cm.yaml
🧰 Additional context used
🧬 Code Graph Analysis (1)
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (1)
wren-ai-service/src/core/provider.py (1)
get_context_window_size
(17-18)
🔇 Additional comments (2)
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (2)
233-233
: Good addition of configurable parameter.Adding the
context_window_size
parameter makes the function more flexible and aligns with the PR objective of replacing hardcoded token limits.
273-273
:✅ Verification successful
Verify function callers are updated for the new parameter.
The replacement of the hardcoded
100,000
with the dynamiccontext_window_size
parameter is correct. However, ensure all callers ofcheck_using_db_schemas_without_pruning
have been updated to provide this new required parameter.
🏁 Script executed:
#!/bin/bash # Description: Verify all function calls to check_using_db_schemas_without_pruning include the new context_window_size parameter # Expected: All calls should have the correct number of parameters echo "Searching for function calls to check_using_db_schemas_without_pruning..." rg -A 10 "check_using_db_schemas_without_pruning\(" --type py echo "Searching for function definition..." ast-grep --pattern 'def check_using_db_schemas_without_pruning($$$)'Length of output: 7279
No callers require updating – no invocations found
A global search forcheck_using_db_schemas_without_pruning(
returned only its own definition and no call sites in the repo. There are no callers that need the newcontext_window_size
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks for contribution
This PR integrates the
context_window_size
parameter fromLLMProvider
into the token limit checking logic. This ensures that prompt + context do not exceed the model’s actual maximum context length.Summary by CodeRabbit
New Features
Bug Fixes