-
Notifications
You must be signed in to change notification settings - Fork 38
Feat(unified router) - Merged temporal classification and query prompt into a single prompt for faster query results #374
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
WalkthroughThis pull request adds a new environment configuration file and updates several modules to incorporate a temporal direction mechanism. The new Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant P as Prompt (searchQueryPrompt)
participant E as Evaluator (endToEndFlow)
participant C as Chat API
U->>P: Submit query
P->>P: Evaluate query for temporal direction
P->>U: Return JSON { answer, queryRewrite, temporalDirection }
U->>E: Send processed request
E->>E: Initialize parsed object (includes temporalDirection: null)
E->>E: Check for ambiguous answer (null or empty string)
E->>C: Forward classification using parsed.temporalDirection
C->>C: Process message with updated types
C->>U: Return final response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Hello @oindrila-b, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on unifying the query routing mechanism by incorporating temporal event classification directly into the searchQueryPrompt
. This eliminates the need for a separate classification step, potentially leading to faster query results. The changes include adding a missing .env.default
file and modifying the searchQueryPrompt
to include logic for determining temporal direction (past or future) within the prompt itself. The eval.ts
and chat.ts
files are updated to reflect these changes, removing the explicit call to temporalEventClassification
and adjusting the data structures accordingly.
Highlights
- Unified Query Router: The
searchQueryPrompt
now incorporates temporal event classification, streamlining the query processing pipeline. - Temporal Direction Detection: The prompt is enhanced to identify whether a query refers to a past or future event, indicated by the
temporalDirection
field in the JSON output. - Code Simplification: The separate
temporalEventClassification
call is removed fromeval.ts
andchat.ts
, simplifying the code and potentially improving performance.
Changelog
Click here to see the changelog
- server/.env.default
- Added the
.env.default
file with default environment variables.
- Added the
- server/ai/eval.ts
- Modified the
parsed
object to include adirection
property. - Removed the explicit call to
temporalEventClassification
and associated cost calculation. - Modified the condition to check for empty parsed answer
- Modified the
- server/ai/prompts.ts
- Modified
searchQueryPrompt
to include logic for temporal event classification, adding instructions to determinetemporalDirection
and include it in the JSON output.
- Modified
- server/api/chat.ts
- Modified
generatePointQueryTimeExpansion
andUnderstandMessageAndAnswer
functions to acceptTemporalClassifier
without thecost
property. - Removed the
costArr
initialization withclassification.cost
ingeneratePointQueryTimeExpansion
. - Modified
MessageApi
andMessageRetryApi
to remove the explicit call totemporalEventClassification
and instead rely on thetemporalDirection
from the parsed prompt output.
- Modified
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A prompt made unified,
No longer split and stratified,
One step decreased,
For queries released,
Results come, amplified.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a unified router for queries by incorporating the prompt from temporalEventClassification
into searchQueryPrompt
. This aims to improve query result speed by eliminating the need for separate classification. The changes include adding a .env.default
file and modifying the eval.ts
and prompts.ts
files. Overall, the changes seem well-structured and aligned with the goal of faster query results.
Summary of Findings
- Missing Cost Calculation: The
temporalEventClassification
cost is no longer being tracked or used in thegeneratePointQueryTimeExpansion
function, which could lead to inaccurate cost reporting. It's important to ensure that all relevant costs are accounted for to provide a complete picture of resource usage. - Incomplete Temporal Classification: The
temporalEventClassification
function is removed fromendToEndFlow
ineval.ts
, but theclassification
object is still being assigned adirection
based onparsed.temporalDirection
. This could lead to incorrect classification if thetemporalDirection
is not properly set in the unified prompt. - Default Encryption Keys: The
.env.default
file includes default encryption keys. While this is convenient for local development, it poses a significant security risk if these keys are used in a production environment. It's crucial to ensure that these default keys are replaced with unique, randomly generated keys in any deployed instance.
Merge Readiness
The pull request introduces significant changes to the query routing logic. While the changes aim to improve performance, there are some potential issues that need to be addressed before merging. Specifically, the missing cost calculation and incomplete temporal classification should be investigated and resolved. Additionally, the default encryption keys in .env.default
pose a security risk and should be addressed before merging. I am unable to approve this pull request, and recommend that others review and approve this code before merging.
ENCRYPTION_KEY= "ldRWi1hLL8zMT2yxAXwjjTJUYs1ikROLqRxFrs0qpvU=" # DEFAULT_VALUE, KINDLY GENERATE YOUR OWN | ||
JWT_SECRET= "ldRWi1hLL8zMT2yxAXwjjTJUYs1ikROLqRxFrs0qpvU=" # DEFAULT_VALUE, KINDLY GENERATE YOUR OWN | ||
SERVICE_ACCOUNT_ENCRYPTION_KEY= "ldRWi1hLL8zMT2yxAXwjjTJUYs1ikROLqRxFrs0qpvU=" # DEFAULT_VALUE, KINDLY GENERATE YOUR OWN |
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.
These are default encryption keys. While this is convenient for local development, it poses a significant security risk if these keys are used in a production environment. It's crucial to ensure that these default keys are replaced with unique, randomly generated keys in any deployed instance. Consider adding a warning in the README about this.
@@ -728,7 +728,7 @@ async function* generatePointQueryTimeExpansion( | |||
const maxIterations = 10 | |||
const weekInMs = 12 * 24 * 60 * 60 * 1000 | |||
const direction = classification.direction as string | |||
let costArr: number[] = [classification.cost] | |||
let costArr: number[] = [] |
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.
The temporalEventClassification
cost is no longer being tracked or used. Ensure that all relevant costs are accounted for to provide a complete picture of resource usage. Consider adding the cost from the unified prompt to costArr
.
let costArr: number[] = [] | |
let costArr: number[] = []; // Initialize as empty array |
const classification: TemporalClassifier = { | ||
direction: parsed.temporalDirection, | ||
} |
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.
The classification
object is being assigned a direction
based on parsed.temporalDirection
. Ensure that parsed.temporalDirection
is reliably set by the unified prompt, otherwise the classification might be incorrect. Consider adding a fallback mechanism or validation to ensure the direction is properly determined.
const classification: TemporalClassifier = { | |
direction: parsed.temporalDirection, | |
} | |
const classification: TemporalClassifier = { | |
direction: parsed.temporalDirection ?? null, // Add a null fallback | |
} |
const classification: TemporalClassifier = { | ||
direction: parsed.temporalDirection, | ||
} |
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.
Consider adding a check to ensure that parsed
is not null or undefined before accessing parsed.temporalDirection
to avoid potential runtime errors.
const classification: TemporalClassifier = { | |
direction: parsed.temporalDirection, | |
} | |
const classification: TemporalClassifier = { | |
direction: parsed?.temporalDirection ?? null, // Add a null fallback | |
} |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
server/.env.default
(1 hunks)server/ai/eval.ts
(2 hunks)server/ai/prompts.ts
(1 hunks)server/api/chat.ts
(7 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
server/ai/eval.ts (1)
server/ai/types.ts (1)
TemporalClassifier
(59-61)
server/api/chat.ts (1)
server/ai/types.ts (1)
TemporalClassifier
(59-61)
🔇 Additional comments (9)
server/.env.default (1)
1-7
:❓ Verification inconclusive
New environment configuration file looks good.
This new
.env.default
file provides helpful default configuration values for database connections, hosts, and necessary encryption keys. The embedding model is also properly specified.I recommend verifying that the default encryption key is appropriately flagged as a placeholder. While the comment indicates users should generate their own keys, consider checking if this value has sufficient entropy as a placeholder:
🏁 Script executed:
#!/bin/bash # Check if the encryption key has sufficient entropy (at least 32 bytes base64) DEFAULT_KEY="ldRWi1hLL8zMT2yxAXwjjTJUYs1ikROLqRxFrs0qpvU=" DECODED_LENGTH=$(echo $DEFAULT_KEY | base64 -d | wc -c) echo "Decoded key length: $DECODED_LENGTH bytes" if [ $DECODED_LENGTH -ge 32 ]; then echo "✅ Default key has sufficient entropy for a placeholder" else echo "⚠️ Default key has insufficient entropy for a placeholder" fiLength of output: 458
Attention Required: Verify the Entropy Check Mechanism for the Placeholder Key
The new
.env.default
file provides appropriate default values and clearly flags the encryption keys as placeholders. However, when verifying that the default encryption key has sufficient entropy as a placeholder, the entropy check failed because thebase64
command was not found in the current environment. Please ensure one of the following:
- The
base64
utility is available so that the entropy check can correctly validate that the provided key decodes to at least 32 bytes.- Alternatively, manually verify in an environment with
base64
support that the keyldRWi1hLL8zMT2yxAXwjjTJUYs1ikROLqRxFrs0qpvU=
meets the required entropy.Once the entropy verification process is confirmed in the proper environment, the placeholder key usage can be considered acceptable.
server/ai/eval.ts (2)
859-859
: Updated parsed object to include direction field.This change adds the direction field to the parsed object, aligning with the unified router approach mentioned in the PR objectives.
883-884
: Improved handling of empty responses.Good enhancement to handle both null and empty string responses, making the code more robust against different types of empty responses.
server/ai/prompts.ts (2)
700-714
: Integrated temporal classification into search query prompt.This is a key implementation of the PR's objective - merging the temporal classification logic directly into the search query prompt. The code clearly defines criteria for determining temporal direction based on the query context.
717-719
: Updated JSON output structure to include temporal direction.The output schema now includes the temporalDirection field, which supports the unified router approach. The documentation for this field is also appropriately added.
Also applies to: 722-723
server/api/chat.ts (4)
718-718
: Simplified the classification parameter type.The classification parameter has been simplified by removing the cost property, making it more focused on its primary purpose of temporal classification.
731-731
: Initialized costArr as an empty array.The cost array initialization has been modified to start empty instead of including the classification cost. This aligns with the simplified classification parameter type.
1128-1128
: Added temporalDirection to parsed object in MessageApi.The parsed object now includes temporalDirection to support the unified router approach. The classification object is also correctly instantiated using this property.
Also applies to: 1219-1219
1530-1530
: Added temporalDirection to parsed object in MessageRetryApi.Similar to the MessageApi, the MessageRetryApi now includes temporalDirection in its parsed object and properly uses it for the classification.
Also applies to: 1619-1619
const classification: TemporalClassifier = { | ||
direction: parsed.temporalDirection, | ||
} |
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.
Fixed field name inconsistency.
There's a field name inconsistency here. The parsed object has a direction
field (line 859), but you're using temporalDirection
to set the classification object's direction.
Apply this fix to ensure consistency:
const classification: TemporalClassifier = {
- direction: parsed.temporalDirection,
+ direction: parsed.direction,
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const classification: TemporalClassifier = { | |
direction: parsed.temporalDirection, | |
} | |
const classification: TemporalClassifier = { | |
direction: parsed.direction, | |
} |
Description
The PR contains the following changes :
.env.default
that was removed previously.searchQueryPrompt
to incorporate prompt fromtemporalEventClassification
, resulting intosearchQueryPrompt
becoming a unified router for query, thereby removing the need to separately classify the query as an event or meeting.Testing
Tested locally using eval.ts
Additional Notes
None so far
Summary by CodeRabbit
New Features
Chores