-
Notifications
You must be signed in to change notification settings - Fork 4.3k
.Net: feat: Eliminate obsolete VectorSearchFilter technical debt in VectorStoreTextSearch (microsoft#10456) #13179
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
Open
alzarei
wants to merge
4
commits into
microsoft:feature-text-search-linq
Choose a base branch
from
alzarei:feature-text-search-linq-pr2
base: feature-text-search-linq
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+233
−3
Conversation
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
…obsolete VectorSearchFilter - Replace obsolete VectorSearchFilter conversion with direct LINQ filtering for simple equality filters - Add ConvertTextSearchFilterToLinq() method to handle TextSearchFilter.Equality() cases - Fall back to legacy approach only for complex filters that cannot be converted - Eliminates technical debt and performance overhead identified in Issue microsoft#10456 - Maintains 100% backward compatibility - all existing tests pass (1,574/1,574) - Reduces object allocations and removes obsolete API warnings for common filtering scenarios Addresses Issue microsoft#10456 - PR 2: VectorStoreTextSearch internal modernization
0e78309
to
3c9fc7b
Compare
…pliance - Replace broad catch-all exception handling with specific exception types - Add comprehensive exception handling for reflection operations in CreateEqualityExpression: * ArgumentNullException for null parameters * ArgumentException for invalid property names or expression parameters * InvalidOperationException for invalid property access or operations * TargetParameterCountException for lambda expression parameter mismatches * MemberAccessException for property access permission issues * NotSupportedException for unsupported operations (e.g., byref-like parameters) - Maintain intentional catch-all Exception handler with #pragma warning disable CA1031 - Preserve backward compatibility by returning null for graceful fallback - Add clear documentation explaining exception handling rationale - Addresses CA1031 code analysis warning while maintaining robust error handling - All tests pass (1,574/1,574) and formatting compliance verified
@moonbox3 @roji @markwallace-microsoft can you please trigger the review workflows? Thanks |
8 tasks
- Add InvalidPropertyFilterThrowsExpectedExceptionAsync: Validates that new LINQ filtering creates expressions correctly and passes them to vector store connectors - Add ComplexFiltersUseLegacyBehaviorAsync: Tests graceful fallback for complex filter scenarios when LINQ conversion returns null - Add SimpleEqualityFilterUsesModernLinqPathAsync: Confirms end-to-end functionality of the new LINQ filtering optimization for simple equality filters Analysis: - All 15 VectorStoreTextSearch tests pass (3 new + 12 existing) - All 85 TextSearch tests pass, confirming no regressions - Tests prove the new ConvertTextSearchFilterToLinq() and CreateEqualityExpression() methods work correctly - Exception from InMemory connector in invalid property test confirms LINQ path is being used instead of fallback behavior - Improves edge case coverage for the filtering modernization introduced in previous commits
- Add NullFilterReturnsAllResultsAsync test to verify behavior when no filter is applied - Remove unnecessary Microsoft.Extensions.VectorData using statement - Enhance test coverage for VectorStoreTextSearch edge cases
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.
Eliminate obsolete VectorSearchFilter usage in VectorStoreTextSearch
Fixes #10456
Motivation and Context
Why is this change required?
VectorStoreTextSearch currently converts TextSearchFilter to obsolete VectorSearchFilter for all filtering operations, requiring suppressed compiler warnings (
#pragma warning disable CS0618
) and introducing unnecessary conversion overhead for simple equality filters.What problem does it solve?
What scenario does it contribute to?
This change improves the performance and maintainability of text search operations in Semantic Kernel, particularly for applications using simple equality filters with VectorStoreTextSearch. It enables direct LINQ expression usage while maintaining full backward compatibility.
Issue Reference
Addresses: #10456
Description
This PR removes technical debt in VectorStoreTextSearch implementation by eliminating obsolete VectorSearchFilter conversion for simple equality filters. The implementation introduces direct LINQ expression conversion while maintaining full backward compatibility through a hybrid approach.
Solution
Introduces two new private methods in VectorStoreTextSearch:
ConvertTextSearchFilterToLinq<TRecord>()
- Converts simple equality filters to LINQ expressionsCreateEqualityExpression<TRecord>()
- Creates type-safe equality expressions using reflectionFor simple equality filters (single
EqualToFilterClause
), the implementation now generates LINQ expressions directly. Complex filters continue using the existing VectorSearchFilter conversion as a fallback.Changes Made
VectorStoreTextSearch.cs
ConvertTextSearchFilterToLinq<TRecord>()
method for direct LINQ conversionCreateEqualityExpression<TRecord>()
method with reflection-based property accessTest Coverage
NullFilterReturnsAllResultsAsync()
test to verify null filter handlingMicrosoft.Extensions.VectorData
using statementTechnical Debt Elimination
#pragma warning disable CS0618
)Benefits
Performance Improvements
Code Quality Improvements
Zero Breaking Changes
Implementation Strategy
This PR implements Phase 2 of the Issue #10456 resolution across 6 structured PRs:
[DONE] PR 1: Core generic interface additions
ITextSearch<TRecord>
andTextSearchOptions<TRecord>
interfaces[DONE] PR 2 (This PR): VectorStoreTextSearch internal modernization
VectorSearchFilter
conversion overhead for simple cases[TODO] PR 3: Modernize BingTextSearch connector
BingTextSearch.cs
to implementITextSearch<TRecord>
[TODO] PR 4: Modernize GoogleTextSearch connector
GoogleTextSearch.cs
to implementITextSearch<TRecord>
[TODO] PR 5: Modernize remaining connectors
TavilyTextSearch.cs
andBraveTextSearch.cs
[TODO] PR 6: Tests and samples modernization
Verification Results
Microsoft Official Pre-Commit Compliance
Test Coverage
New Strategic Test Cases Added
To ensure comprehensive coverage of the new filtering implementation, 3 strategic test cases were added:
InvalidPropertyFilterThrowsExpectedExceptionAsync
ConvertTextSearchFilterToLinq()
andCreateEqualityExpression()
functionalityComplexFiltersUseLegacyBehaviorAsync
SimpleEqualityFilterUsesModernLinqPathAsync
Test Analysis Results:
Code Quality
Impact
Validation
Recent Updates
Latest commit adds test coverage enhancement:
NullFilterReturnsAllResultsAsync()
test caseContribution Checklist
dotnet build --configuration Release
- 0 warnings, 0 errorsNullFilterReturnsAllResultsAsync()
test for edge case coverage