Skip to content

Conversation

darkskygit
Copy link
Member

@darkskygit darkskygit commented Jul 14, 2025

fix AI-360
fix AI-348

@darkskygit darkskygit requested a review from a team July 14, 2025 07:02
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Walkthrough

The update introduces a utility to remove leading metadata lines from document chunks before returning them in search results. It also separates and merges author and metadata retrieval for documents, enriching chunk metadata with author details. The overall function signatures remain unchanged, and all modifications are internal.

Changes

File(s) Change Summary
packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts Added clearEmbeddingChunk to strip leading metadata lines from chunks; split and merged author/metadata retrieval for enrichment.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DocSearchGetter
    participant Models
    User->>DocSearchGetter: search(query)
    DocSearchGetter->>Models: findAuthors(docIds)
    Models-->>DocSearchGetter: authors[]
    DocSearchGetter->>Models: findMetas(docIds)
    Models-->>DocSearchGetter: metas[]
    DocSearchGetter->>DocSearchGetter: merge authors into metas
    DocSearchGetter->>DocSearchGetter: for each chunk, clearEmbeddingChunk(chunk)
    DocSearchGetter-->>User: cleaned, enriched chunks[]
Loading

Assessment against linked issues

Objective Addressed Explanation
embedding搜索的内容清理多余的元数据 (AI-360)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • fengmk2

Poem

In the warren of code where the searchers roam,
I swept metadata from chunks on their way home.
Now authors and titles, all neat and precise,
Make document searches fuzzy and nice.
With every hop, your queries are clean—
A rabbit’s touch, behind the scene! 🐇✨


📜 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 6b05a0a and 0367ddf.

📒 Files selected for processing (1)
  • packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts
⏰ 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). (54)
  • GitHub Check: Unit Test (3)
  • GitHub Check: Unit Test (4)
  • GitHub Check: Native Unit Test
  • GitHub Check: Unit Test (1)
  • GitHub Check: Unit Test (5)
  • GitHub Check: Unit Test (2)
  • GitHub Check: y-octo binding test on x86_64-apple-darwin
  • GitHub Check: y-octo binding test on aarch64-pc-windows-msvc
  • GitHub Check: y-octo binding test on aarch64-apple-darwin
  • GitHub Check: y-octo binding test on x86_64-pc-windows-msvc
  • GitHub Check: fuzzing
  • GitHub Check: loom thread test
  • GitHub Check: Run native tests
  • GitHub Check: E2E Mobile Test (3)
  • GitHub Check: E2E Mobile Test (2)
  • GitHub Check: E2E Mobile Test (4)
  • GitHub Check: E2E Test (10)
  • GitHub Check: E2E Mobile Test (5)
  • GitHub Check: E2E Mobile Test (1)
  • GitHub Check: E2E Test (6)
  • GitHub Check: E2E Test (8)
  • GitHub Check: E2E Test (9)
  • GitHub Check: E2E Test (7)
  • GitHub Check: E2E BlockSuite Test (10)
  • GitHub Check: E2E BlockSuite Test (4)
  • GitHub Check: E2E Test (2)
  • GitHub Check: E2E Test (3)
  • GitHub Check: E2E Test (4)
  • GitHub Check: E2E BlockSuite Test (2)
  • GitHub Check: E2E Test (5)
  • GitHub Check: E2E BlockSuite Test (5)
  • GitHub Check: E2E Test (1)
  • GitHub Check: E2E BlockSuite Test (7)
  • GitHub Check: E2E BlockSuite Test (9)
  • GitHub Check: E2E BlockSuite Test (8)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, webkit)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, webkit)
  • GitHub Check: E2E BlockSuite Test (1)
  • GitHub Check: E2E BlockSuite Test (3)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, firefox)
  • GitHub Check: E2E BlockSuite Test (6)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, firefox)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, chromium)
  • GitHub Check: Build AFFiNE native (aarch64-pc-windows-msvc)
  • GitHub Check: Typecheck
  • GitHub Check: Build AFFiNE native (x86_64-pc-windows-msvc)
  • GitHub Check: Analyze (javascript, blocksuite)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, chromium)
  • GitHub Check: Lint
  • GitHub Check: Analyze (typescript, blocksuite)
  • GitHub Check: Analyze (typescript, affine)
  • GitHub Check: Build Server native
  • GitHub Check: Analyze (javascript, affine)
  • GitHub Check: Build @affine/electron renderer
✨ 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.

@darkskygit darkskygit changed the title feat(server) clear semantic search metadata feat(server): clear semantic search metadata Jul 14, 2025
@darkskygit darkskygit requested a review from a team July 14, 2025 07:04
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 18.18182% with 45 lines in your changes missing coverage. Please review.

Project coverage is 57.51%. Comparing base (bcf6bd1) to head (0367ddf).
Report is 17 commits behind head on canary.

Files with missing lines Patch % Lines
...r/src/plugins/copilot/tools/doc-semantic-search.ts 18.18% 45 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13197      +/-   ##
==========================================
- Coverage   57.52%   57.51%   -0.02%     
==========================================
  Files        2709     2709              
  Lines      132506   132552      +46     
  Branches    20678    20678              
==========================================
+ Hits        76222    76231       +9     
- Misses      54075    54655     +580     
+ Partials     2209     1666     -543     
Flag Coverage Δ
server-test 80.28% <18.18%> (-0.05%) ⬇️
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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65453c3 and fb47c53.

📒 Files selected for processing (1)
  • packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (1)
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). (48)
  • GitHub Check: y-octo binding test on x86_64-apple-darwin
  • GitHub Check: E2E BlockSuite Test (9)
  • GitHub Check: y-octo binding test on aarch64-pc-windows-msvc
  • GitHub Check: y-octo binding test on x86_64-pc-windows-msvc
  • GitHub Check: E2E BlockSuite Test (8)
  • GitHub Check: Run native tests
  • GitHub Check: E2E BlockSuite Test (10)
  • GitHub Check: E2E BlockSuite Test (7)
  • GitHub Check: E2E Mobile Test (4)
  • GitHub Check: E2E BlockSuite Test (2)
  • GitHub Check: E2E Mobile Test (5)
  • GitHub Check: E2E BlockSuite Test (6)
  • GitHub Check: E2E BlockSuite Test (4)
  • GitHub Check: E2E BlockSuite Test (3)
  • GitHub Check: E2E BlockSuite Test (5)
  • GitHub Check: E2E BlockSuite Test (1)
  • GitHub Check: E2E Mobile Test (2)
  • GitHub Check: E2E Mobile Test (1)
  • GitHub Check: E2E Mobile Test (3)
  • GitHub Check: Build AFFiNE native (x86_64-apple-darwin)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, webkit)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, chromium)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, firefox)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, webkit)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, chromium)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, firefox)
  • GitHub Check: E2E Test (3)
  • GitHub Check: E2E Test (4)
  • GitHub Check: E2E Test (9)
  • GitHub Check: E2E Test (10)
  • GitHub Check: E2E Test (8)
  • GitHub Check: E2E Test (6)
  • GitHub Check: E2E Test (7)
  • GitHub Check: E2E Test (5)
  • GitHub Check: E2E Test (2)
  • GitHub Check: E2E Test (1)
  • GitHub Check: loom thread test
  • GitHub Check: Build Server native
  • GitHub Check: Build AFFiNE native (aarch64-pc-windows-msvc)
  • GitHub Check: Build AFFiNE native (x86_64-pc-windows-msvc)
  • GitHub Check: Build @affine/electron renderer
  • GitHub Check: fuzzing
  • GitHub Check: Analyze (typescript, blocksuite)
  • GitHub Check: Analyze (javascript, affine)
  • GitHub Check: Analyze (javascript, blocksuite)
  • GitHub Check: Analyze (typescript, affine)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
🔇 Additional comments (4)
packages/backend/server/src/plugins/copilot/tools/doc-semantic-search.ts (4)

2-2: LGTM - Import addition looks good.

The omit import from lodash-es is properly used later in the code for filtering document author fields.


12-18: LGTM - Well-defined metadata filter prefixes.

The FILTER_PREFIX array clearly defines the metadata prefixes that should be removed from chunks. The prefixes are comprehensive and cover the common metadata fields.


74-101: LGTM - Improved document metadata retrieval with author information.

The refactored logic properly separates author and metadata retrieval, then merges them effectively. The defensive filtering with docs.filter(d => !!d) and the use of omit to clean up author fields are good practices.

The key mapping strategy (using doc.id for authors and doc.docId for metadata) appears to align with the respective API responses.


104-104: Intentional: clearEmbeddingChunk only applies to fileChunks
docChunks come from the docs API and are returned without the injected “Title:…”, “Created at:…”, etc. prefixes, so there’s nothing to strip. fileChunks (and any contextChunks) may include those metadata lines and must be cleaned before downstream use. No change required.

@darkskygit darkskygit force-pushed the darksky/cleanup-embedding-metadata branch from fb47c53 to 6b05a0a Compare July 14, 2025 10:56
@darkskygit darkskygit added this pull request to the merge queue Jul 15, 2025
Merged via the queue into canary with commit c797cac Jul 15, 2025
109 checks passed
@darkskygit darkskygit deleted the darksky/cleanup-embedding-metadata branch July 15, 2025 11:29
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