Skip to content

Conversation

junaid-shirur
Copy link
Collaborator

@junaid-shirur junaid-shirur commented Oct 10, 2025

Description

Testing

Additional Notes

Summary by CodeRabbit

  • New Features

    • Added Knowledge Base as a selectable integration in agent-driven queries.
    • Collection selections (including expanded sheet IDs) are now honored in searches.
  • Improvements

    • Deduplicated app/entity schemas to reduce duplicate or empty entries.
    • More consistent context building and parameter handling across query flows.
    • Better propagation of collection selections into agent queries and metadata resolution.
  • Bug Fixes

    • Prevented errors when Google Drive selections are missing.
    • Improved reliability of item retrieval by computing and passing needed IDs and selections internally.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds 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

Cohort / File(s) Summary
Chat API + agent plumbing
server/api/chat/chat.ts
Typed selectedItem as Partial<Record<Apps,string[]>>; added KnowledgeBase into appIntegrations/agentApps and KB schema paths; extracted and propagated collectionSelections (collectionIds/folderIds/fileIds, expanded sheet IDs); passed selectedItem and collectionSelections into searchVespa/searchVespaAgent/getItems; minor formatting.
Chat utils: parsed result type
server/api/chat/utils.ts
Changed ParsedResult.selectedItems from { [app: string]: string[] } to Partial<Record<Apps, string[]>>; initialized typed empty object in parseAppSelections; small formatting tweaks.
Search utils: defensive guard
server/search/utils.ts
Added guard to ensure options.selectedItem exists before accessing Apps.GoogleDrive in extractDriveIds; whitespace/formatting tweaks.
Vespa wrapper & signature
server/search/vespa.ts
Replaced direct export with async getItems wrapper that computes driveIds (from input/email) and processedCollectionSelections from provided collectionSelections; updated public signature to accept collectionSelections and omit processedCollectionSelections; imported GetItemsParams.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • zereraz
  • naSim087
  • shivamashtikar
  • kalpadhwaryu

Poem

I nibble code and munch on types,
Selected items snug and tight.
Through Vespa tunnels, I hop and steer,
Collections gathered, knowledge near.
A rabbit's cheer — the changes are here! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title follows conventional commit style and succinctly highlights the main change area by specifying a fix to the getItems function and its usage in agent queries. It directly corresponds to the updates made to propagate collection selections and adjust the getItems signature, providing clear context without unnecessary detail. This phrasing is concise and specific enough for reviewers to understand the primary intent of the changeset at a glance.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/agent_getitems

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 getItems query functionality, primarily focusing on improving how various application integrations and collection selections are processed. It introduces better type safety, removes a previous workaround for Google Drive, and streamlines the handling of KnowledgeBase collections, leading to more robust and accurate search queries by ensuring proper data preprocessing and unique schema handling.

Highlights

  • Refactored getItems Function: The core getItems function has been wrapped to preprocess driveIds and collectionSelections before executing the underlying Vespa search, centralizing logic for item retrieval.
  • Improved Collection and App Integration: Enhanced handling of collectionSelections and selectedItem parameters, particularly for Google Drive and KnowledgeBase. This includes removing a previous hotfix that blocked Google Drive queries and better integrating KnowledgeBase collections into the agent app enumeration and schema generation.
  • Enhanced Type Safety and Robustness: Introduced explicit typing for selectedItem as Record<Apps, string[]> across relevant functions and added null/undefined checks for options.selectedItem, improving code reliability and preventing potential runtime errors.
  • Ensured Unique Schema Entries: Modified schema generation logic to use Sets, guaranteeing that only unique schema entries are processed when mapping applications or entities to Vespa schemas.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 57292b8 and 83a575e.

📒 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 refactored collectFollowupContext 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 agentAppEnums

Switch 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 selections

Pushes 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-if

The 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 logger

Use 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

📥 Commits

Reviewing files that changed from the base of the PR and between 83a575e and 447b147.

📒 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 selectedItem

Using 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 expansion

Same Partial<Record<Apps, string[]>> shape used here; keep this consistent across the file.


3154-3166: LGTM: schema dedup with Set

Unique schemas via Set avoids duplicates from mappers.


1982-1991: Fix invalid rankProfile: SearchModes.AttachmentRank

SearchModes.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.

@junaid-shirur junaid-shirur merged commit 762258c into main Oct 13, 2025
3 of 4 checks passed
@junaid-shirur junaid-shirur deleted the fix/agent_getitems branch October 13, 2025 07:34
junaid-shirur pushed a commit that referenced this pull request Oct 13, 2025
## [3.13.7](v3.13.6...v3.13.7) (2025-10-13)

### Bug Fixes

* **getItems:** Fix agent getItems queries ([#1090](#1090)) ([762258c](762258c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants