[agents] Optimize vector search - #1123
Merged
Merged
Conversation
Refactored SearchAsync to use a raw SQL query with a CTE and CROSS APPLY for efficient vector distance calculation and top-K retrieval, replacing the LINQ-based approach. Introduced a private SearchResultDto for SQL result mapping. Client-side transformation to RetrievedChunk is unchanged. SourceDocument projection logic was only reformatted, with no functional changes.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the Agents document vector retrieval path by replacing the EF/LINQ-based distance query with a raw SQL CTE + CROSS APPLY approach that computes vector distances and retrieves top‑K chunk IDs first, then joins the richer document/blob projections only for those results. It also bumps the Agents package version suffix from beta13 to beta14.
Changes:
- Refactor
DocumentsService.SearchAsyncto a raw SQL (;WITH RankedChunks ...) top‑K vector-distance query and map results via a DTO. - Keep the client-side projection to
RetrievedChunkintact while changing the server-side retrieval strategy. - Bump
VersionSuffixtobeta14across Agents Core/Server/UI projects.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Indice.Features.Agents.UI/Indice.Features.Agents.UI.csproj | Bumps Agents UI package prerelease suffix to beta14. |
| src/Indice.Features.Agents.Server/Indice.Features.Agents.Server.csproj | Bumps Agents Server package prerelease suffix to beta14. |
| src/Indice.Features.Agents.Core/Indice.Features.Agents.Core.csproj | Bumps Agents Core package prerelease suffix to beta14. |
| src/Indice.Features.Agents.Core/Services/DocumentsService.cs | Replaces LINQ-based vector search with CTE + CROSS APPLY SQL and adds a DTO for result materialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactored SearchAsync to use a raw SQL query with a CTE and CROSS APPLY for efficient vector distance calculation and top-K retrieval, replacing the LINQ-based approach. Introduced a private SearchResultDto for SQL result mapping. Client-side transformation to RetrievedChunk is unchanged. SourceDocument projection logic was only reformatted, with no functional changes.