Skip to content

Conversation

darkskygit
Copy link
Member

@darkskygit darkskygit commented Jul 11, 2025

fix AI-339

@darkskygit darkskygit requested a review from a team July 11, 2025 10:26
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The changes update how the models dependency is managed and passed within the Copilot plugin's tool creation process. The models instance is now retrieved earlier and passed to buildDocSearchGetter, which uses it to enrich document chunk results with metadata by fetching author information.

Changes

File(s) Summary
.../server/src/plugins/copilot/providers/provider.ts Retrieves models earlier in getTools and passes it to buildDocSearchGetter; removes redundant retrievals.
.../server/src/plugins/copilot/tools/doc-semantic-search.ts Updates buildDocSearchGetter to accept models; enriches returned chunks with document metadata.

Sequence Diagram(s)

sequenceDiagram
    participant Provider as getTools (Provider)
    participant Models as Models
    participant Tool as buildDocSearchGetter
    participant DB as Database

    Provider->>Models: Retrieve Models instance
    Provider->>Tool: Call buildDocSearchGetter(ac, context, docContext, models)
    Tool->>DB: models.doc.findAuthors(workspaceId, docIds)
    DB-->>Tool: Return document metadata
    Tool-->>Provider: Return enriched doc chunks with metadata
Loading

Possibly related PRs

Suggested labels

app:server

Suggested reviewers

  • fengmk2

Poem

In the warren of code, a hop and a leap,
Models now travel where data runs deep.
Chunks gain their stories, authors in tow,
Enriched and informed, metadata in flow.
With every small patch, our features grow—
A rabbit’s delight in the work we bestow! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93f13e9 and ed16055.

📒 Files selected for processing (2)
  • packages/backend/server/src/plugins/copilot/providers/provider.ts (2 hunks)
  • packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/backend/server/src/plugins/copilot/providers/provider.ts (2)
packages/backend/server/src/models/index.ts (1)
  • Models (63-63)
packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (1)
  • buildDocSearchGetter (11-69)
packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (3)
packages/backend/server/src/plugins/copilot/context/session.ts (1)
  • ContextSession (16-339)
packages/backend/server/src/models/index.ts (1)
  • Models (63-63)
packages/backend/server/src/models/common/copilot.ts (1)
  • ChunkSimilarity (96-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (49)
  • GitHub Check: y-octo binding test on aarch64-pc-windows-msvc
  • GitHub Check: E2E Mobile Test (5)
  • GitHub Check: E2E Mobile Test (4)
  • GitHub Check: E2E Mobile Test (1)
  • GitHub Check: E2E Mobile Test (3)
  • GitHub Check: E2E Mobile Test (2)
  • GitHub Check: y-octo binding test on x86_64-pc-windows-msvc
  • GitHub Check: y-octo binding test on aarch64-apple-darwin
  • GitHub Check: y-octo binding test on x86_64-apple-darwin
  • GitHub Check: Run native tests
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, chromium)
  • GitHub Check: fuzzing
  • GitHub Check: Build @affine/electron renderer
  • GitHub Check: Build AFFiNE native (x86_64-pc-windows-msvc)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, webkit)
  • GitHub Check: Build AFFiNE native (aarch64-pc-windows-msvc)
  • GitHub Check: loom thread test
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, firefox)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, webkit)
  • GitHub Check: Build AFFiNE native (x86_64-apple-darwin)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, chromium)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, firefox)
  • GitHub Check: E2E Test (8)
  • GitHub Check: Build Server native
  • GitHub Check: E2E Test (9)
  • GitHub Check: E2E Test (10)
  • GitHub Check: E2E Test (5)
  • GitHub Check: E2E Test (6)
  • GitHub Check: E2E Test (7)
  • GitHub Check: E2E Test (4)
  • GitHub Check: E2E Test (1)
  • GitHub Check: E2E BlockSuite Test (10)
  • GitHub Check: E2E BlockSuite Test (9)
  • GitHub Check: E2E Test (3)
  • GitHub Check: E2E Test (2)
  • GitHub Check: E2E BlockSuite Test (4)
  • GitHub Check: E2E BlockSuite Test (6)
  • GitHub Check: E2E BlockSuite Test (5)
  • GitHub Check: E2E BlockSuite Test (8)
  • GitHub Check: E2E BlockSuite Test (2)
  • GitHub Check: E2E BlockSuite Test (3)
  • GitHub Check: E2E BlockSuite Test (1)
  • GitHub Check: E2E BlockSuite Test (7)
  • GitHub Check: Typecheck
  • GitHub Check: Analyze (typescript, affine)
  • GitHub Check: Analyze (javascript, blocksuite)
  • GitHub Check: Analyze (javascript, affine)
  • GitHub Check: Analyze (typescript, blocksuite)
  • GitHub Check: Lint
🔇 Additional comments (6)
packages/backend/server/src/plugins/copilot/providers/provider.ts (2)

144-144: Good refactoring to centralize dependency retrieval.

Moving the Models instance retrieval earlier in the method improves code organization and allows sharing the dependency across multiple tools that need it.


186-191: Correctly updated function call with new parameter.

The buildDocSearchGetter function call is properly updated to include the models parameter, maintaining consistency with the updated function signature in the doc-semantic-search.ts file.

packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (4)

5-5: Import updated correctly for new dependency.

The import statement properly includes the Models type needed for the updated function signature.


14-15: Function signature updated correctly.

The function signature is properly updated to accept the models: Models parameter, maintaining consistency with the caller in provider.ts.


50-58: Well-implemented metadata fetching with efficient data structure.

The implementation efficiently fetches document metadata and converts it to a Map for O(1) lookups. The null filtering ensures data integrity, and the oxlint disable comment acknowledges the acceptable use of non-null assertion.


60-66: Proper metadata enrichment and type casting.

The return statement correctly merges document chunks with their metadata using the spread operator, and the type casting to ChunkSimilarity[] ensures type safety. The file chunks are preserved as-is while document chunks are enriched with author information.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fengmk2 fengmk2 enabled auto-merge July 11, 2025 10:31
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 35.71429% with 18 lines in your changes missing coverage. Please review.

Project coverage is 57.47%. Comparing base (a2b86bc) to head (ed16055).
Report is 2 commits behind head on canary.

Files with missing lines Patch % Lines
...r/src/plugins/copilot/tools/doc-semantic-search.ts 14.28% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13174      +/-   ##
==========================================
- Coverage   57.47%   57.47%   -0.01%     
==========================================
  Files        2708     2708              
  Lines      132329   132352      +23     
  Branches    20673    20675       +2     
==========================================
+ Hits        76062    76075      +13     
- Misses      54062    54610     +548     
+ Partials     2205     1667     -538     
Flag Coverage Δ
server-test 80.30% <35.71%> (+<0.01%) ⬆️
unittest 32.21% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 disabled auto-merge July 11, 2025 10:36
@fengmk2 fengmk2 merged commit 847ef00 into canary Jul 11, 2025
109 of 110 checks passed
@fengmk2 fengmk2 deleted the darksky/return-doc-metadata-in-tools branch July 11, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants