-
Notifications
You must be signed in to change notification settings - Fork 56
fix(getItems): Fix agent getItems queries #1090
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
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds strong typing for selectedItems, integrates KnowledgeBase into agent parsing and metadata flows, propagates collectionSelections and selectedItem through chat -> agent -> Vespa/getItems calls, wraps/changes server/search/vespa.ts getItems signature to compute driveIds and processedCollectionSelections, and adds defensive guards for drive ID extraction. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant ChatAPI as Chat API
participant Parser as Agent Parser
participant VespaWrapper as server/search/vespa.ts
participant Vespa as vespa.getItems
User->>ChatAPI: request with app selections (incl. KB)
ChatAPI->>Parser: build agentPromptData (includes KnowledgeBase)
Parser-->>ChatAPI: selectedItem (Partial<Record<Apps,string[]>>), collectionSelections
ChatAPI->>VespaWrapper: getItems(params, selectedItem, collectionSelections)
rect rgba(220,235,255,0.35)
VespaWrapper->>VespaWrapper: compute driveIds, processedCollectionSelections
VespaWrapper->>Vespa: getItems(..., driveIds, processedCollectionSelections)
end
Vespa-->>VespaWrapper: items
VespaWrapper-->>ChatAPI: items
ChatAPI-->>User: response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @junaid-shirur, 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! This pull request refactors and enhances the Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Footnotes
|
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 several fixes and improvements, primarily focused on correcting agent queries for getItems
. The core change involves wrapping the getItems
call in server/search/vespa.ts
to correctly process driveIds
and collectionSelections
before making the search request. Additionally, there are several valuable type safety improvements, such as providing explicit types for selectedItem
.
I've identified a critical bug in the agent integration logic where a KnowledgeBase
case was incorrectly pushing Apps.Slack
. I've also made several suggestions to improve code consistency and robustness, such as standardizing type declarations and preventing duplicate entries in the schema array. The numerous formatting changes appear to be from an automated tool and have been reviewed for correctness.
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: 6
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
server/api/chat/chat.ts
(19 hunks)server/api/chat/utils.ts
(3 hunks)server/search/utils.ts
(3 hunks)server/search/vespa.ts
(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-05-28T10:47:41.020Z
Learnt from: naSim087
PR: xynehq/xyne#484
File: server/integrations/google/sync.ts:222-222
Timestamp: 2025-05-28T10:47:41.020Z
Learning: The functions `handleGoogleDriveChange` and `getDriveChanges` in `server/integrations/google/sync.ts` are intentionally exported for future changes, even though they are not currently being imported by other modules.
Applied to files:
server/search/utils.ts
📚 Learning: 2025-10-08T15:44:13.457Z
Learnt from: Himanshvarma
PR: xynehq/xyne#1065
File: server/search/utils.ts:23-42
Timestamp: 2025-10-08T15:44:13.457Z
Learning: In the codebase, sheet numbers in file IDs (pattern: `docId_sheet_number`) are always >= 1 and never 0 or negative. This is a domain constraint that applies to the `expandSheetIds` function in `server/search/utils.ts`.
Applied to files:
server/search/utils.ts
🧬 Code graph analysis (3)
server/api/chat/utils.ts (2)
server/db/schema/messages.ts (2)
messages
(31-78)SelectMessage
(88-88)server/shared/types.ts (2)
AttachmentMetadata
(707-707)Apps
(40-40)
server/search/vespa.ts (1)
server/search/utils.ts (2)
extractDriveIds
(95-138)extractCollectionVespaIds
(140-193)
server/api/chat/chat.ts (4)
server/search/utils.ts (1)
expandSheetIds
(23-42)server/search/vespa.ts (1)
getItems
(134-155)server/api/chat/chunk-selection.ts (1)
getChunkCountPerDoc
(13-148)server/api/chat/utils.ts (2)
getChannelIdsFromAgentPrompt
(152-170)collectFollowupContext
(79-145)
🪛 GitHub Actions: TypeScript Build Check
server/search/utils.ts
[error] 100-100: TS7053: Element implicitly has an 'any' type because expression of type 'Apps.GoogleDrive' can't be used to index type '{}'. Property '[Apps.GoogleDrive]' does not exist on type '{}'.
[error] 101-101: TS7053: Element implicitly has an 'any' type because expression of type 'Apps.GoogleDrive' can't be used to index type '{}'. Property '[Apps.GoogleDrive]' does not exist on type '{}'.
server/search/vespa.ts
[error] 144-144: TS2339: Property 'selectedItem' does not exist on type 'Omit<GetItemsParams, "processedCollectionSelections"> & { collectionSelections?: { collectionIds?: string[] | undefined; collectionFolderIds?: string[] | undefined; collectionFileIds?: string[] | undefined; }[] | undefined; }'.
[error] 151-151: TS2353: Object literal may only specify known properties, and 'processedCollectionSelections' does not exist in type 'GetItemsParams'.
server/api/chat/chat.ts
[error] 1989-1989: TS2339: Property 'attachmentRank' does not exist on type 'typeof SearchModes'.
[error] 3411-3411: TS2353: Object literal may only specify known properties, and 'selectedItem' does not exist in type 'Omit<GetItemsParams, "processedCollectionSelections"> & { collectionSelections?: { collectionIds?: string[]; collectionFolderIds?: string[]; collectionFileIds?: string[]; }[] | undefined; }'.
🔇 Additional comments (1)
server/api/chat/utils.ts (1)
72-145
: LGTM on the refactoredcollectFollowupContext
logic.The changes improve clarity with explicit variable names, proper deduplication via Set, and clearer separation between file IDs and attachment file IDs. The MAX_FILES constant and boundary checks are good additions.
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
♻️ Duplicate comments (1)
server/api/chat/chat.ts (1)
3050-3053
: Corrected: KnowledgeBase mapping to agentAppEnumsSwitch now correctly pushes Apps.KnowledgeBase instead of Apps.Slack.
🧹 Nitpick comments (4)
server/api/chat/chat.ts (4)
3392-3394
: Avoid duplicates when enriching agentApps/schema for KB selectionsPushes may duplicate Apps.KnowledgeBase and KbItemsSchema if already present.
Apply guards:
- if (agentSpecificCollectionSelections.length) { - agentApps.push(Apps.KnowledgeBase) - schema.push(KbItemsSchema) - } + if (agentSpecificCollectionSelections.length) { + if (!agentApps.includes(Apps.KnowledgeBase)) { + agentApps.push(Apps.KnowledgeBase) + } + if (!schema.includes(KbItemsSchema)) { + schema.push(KbItemsSchema) + } + }
3281-3283
: Telemetry size/PII caution: setAttribute('context', …)Recording full built context into spans can be large and may capture sensitive content. Recommend trimming or hashing for observability hygiene.
Example:
- Truncate to N chars
- Store chunk count and IDs; omit raw text
Also applies to: 3468-3471, 3618-3620
2220-2230
: Simplify redundant else-ifThe else-if condition is the negation of the previous branch. Replace with else to reduce noise.
-} else if ( - // If no answer found, exit and yield nothing related to selected context found - !answer -) { +} else {
1299-1299
: Replace console.log with structured loggerUse loggerWithChild for consistency and to include email context.
- console.log("No KnowledgeBase items found in selectedItems") + loggerWithChild({ email }).info( + "No KnowledgeBase items found in selectedItems" + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
server/api/chat/chat.ts
(18 hunks)server/api/chat/utils.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- server/api/chat/utils.ts
🧰 Additional context used
🧬 Code graph analysis (1)
server/api/chat/chat.ts (4)
server/search/utils.ts (1)
expandSheetIds
(23-42)server/search/vespa.ts (3)
searchVespaInFiles
(118-118)searchCollectionRAG
(26-26)getItems
(134-155)server/api/chat/chunk-selection.ts (1)
getChunkCountPerDoc
(13-148)server/api/chat/utils.ts (2)
getChannelIdsFromAgentPrompt
(152-170)collectFollowupContext
(79-145)
🪛 GitHub Actions: TypeScript Build Check
server/api/chat/chat.ts
[error] 1989-1989: TS2339: Property 'AttachmentRank' does not exist on type 'typeof SearchModes'.
[error] 3411-3411: TS2353: Object literal may only specify known properties, and 'selectedItem' does not exist in type 'Omit<GetItemsParams, "processedCollectionSelections"> & { collectionSelections?: { collectionIds?: string[] | undefined; collectionFolderIds?: string[] | undefined; collectionFileIds?: string[] | undefined; }[] | undefined; }'.
🔇 Additional comments (4)
server/api/chat/chat.ts (4)
1171-1171
: Good: narrowed type for selectedItemUsing Partial<Record<Apps, string[]>> is appropriate for sparse selections. Consider using the same type in other functions for consistency (see metadata path).
Search for other selectedItem declarations (e.g., in generateMetadataQueryAnswer) and align types.
2397-2397
: Good: consistent selectedItem typing in time expansionSame Partial<Record<Apps, string[]>> shape used here; keep this consistent across the file.
3154-3166
: LGTM: schema dedup with SetUnique schemas via Set avoids duplicates from mappers.
1982-1991
: Fix invalid rankProfile: SearchModes.AttachmentRankSearchModes.AttachmentRank is undefined (TS2339). Use an existing profile (e.g., GlobalSorted) until you confirm the correct attachment-specific member:
- rankProfile: SearchModes.AttachmentRank, + rankProfile: SearchModes.GlobalSorted,Confirm the correct enum member in @xyne/vespa-ts/types and update accordingly.
## [3.13.7](v3.13.6...v3.13.7) (2025-10-13) ### Bug Fixes * **getItems:** Fix agent getItems queries ([#1090](#1090)) ([762258c](762258c))
Description
Testing
Additional Notes
Summary by CodeRabbit
New Features
Improvements
Bug Fixes