-
Notifications
You must be signed in to change notification settings - Fork 4.4k
.Net: feat: Modernize samples and documentation for ITextSearch<TRecord> interface (microsoft#10456) #13194
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
Merged
westey-m
merged 1 commit into
microsoft:feature-text-search-linq
from
alzarei:feature-text-search-linq-pr6
Nov 25, 2025
Merged
.Net: feat: Modernize samples and documentation for ITextSearch<TRecord> interface (microsoft#10456) #13194
westey-m
merged 1 commit into
microsoft:feature-text-search-linq
from
alzarei:feature-text-search-linq-pr6
Nov 25, 2025
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
b33f63e to
209836a
Compare
b0042f4 to
a27e3f6
Compare
6 tasks
a27e3f6 to
e465b3c
Compare
c1d5bed to
46e2f37
Compare
Author
|
Needs to be merged after PRs: 3,4,5. |
markwallace-microsoft
pushed a commit
that referenced
this pull request
Nov 3, 2025
…arch.GetSearchResultsAsync (#13318) This PR enhances the type safety of the `ITextSearch<TRecord>` interface by changing the `GetSearchResultsAsync` method to return `KernelSearchResults<TRecord>` instead of `KernelSearchResults<object>`. This improvement eliminates the need for manual casting and provides better IntelliSense support for consumers. ## Motivation and Context The current implementation of `ITextSearch<TRecord>.GetSearchResultsAsync` returns `KernelSearchResults<object>`, which requires consumers to manually cast results to the expected type. This reduces type safety and degrades the developer experience by losing compile-time type checking and IntelliSense support. This change aligns the return type with the generic type parameter `TRecord`, providing the expected strongly-typed results that users of a generic interface would anticipate. ## Changes Made ### Interface (ITextSearch.cs) - Changed `ITextSearch<TRecord>.GetSearchResultsAsync` return type from `KernelSearchResults<object>` to `KernelSearchResults<TRecord>` - Updated XML documentation to reflect strongly-typed return value - Legacy `ITextSearch` interface (non-generic) remains unchanged, continuing to return `KernelSearchResults<object>` for backward compatibility ### Implementation (VectorStoreTextSearch.cs) - Added new `GetResultsAsTRecordAsync` helper method returning `IAsyncEnumerable<TRecord>` - Updated generic interface implementation to use the new strongly-typed helper - Retained `GetResultsAsRecordAsync` method for the legacy non-generic interface ### Tests (VectorStoreTextSearchTests.cs) - Updated 3 unit tests to use strongly-typed `DataModel` or `DataModelWithRawEmbedding` instead of `object` - Improved test assertions to leverage direct property access without casting - All 19 tests pass successfully ## Breaking Changes **Interface Change (Experimental API):** - `ITextSearch<TRecord>.GetSearchResultsAsync` now returns `KernelSearchResults<TRecord>` instead of `KernelSearchResults<object>` - This interface is marked with `[Experimental("SKEXP0001")]`, indicating that breaking changes are expected during the preview period - Legacy `ITextSearch` interface (non-generic) is unaffected and maintains full backward compatibility ## Benefits - **Improved Type Safety**: Eliminates runtime casting errors by providing compile-time type checking - **Enhanced Developer Experience**: Full IntelliSense support for TRecord properties and methods - **Cleaner Code**: Consumers no longer need to cast results from object to the expected type - **Consistent API Design**: Generic interface now behaves as expected, returning strongly-typed results - **Zero Impact on Legacy Code**: Non-generic ITextSearch interface remains unchanged ## Testing - All 19 existing unit tests pass - Updated tests demonstrate improved type safety with direct property access - Verified both generic and legacy interfaces work correctly - Confirmed zero breaking changes to non-generic ITextSearch consumers ## Related Work This PR is part of the Issue #10456 multi-PR chain for modernizing ITextSearch with LINQ-based filtering: - PR #13175: Foundation (ITextSearch<TRecord> interface) - Merged - PR #13179: VectorStoreTextSearch + deprecation pattern - In Review - **This PR (2.1)**: API refinement for improved type safety - PR #13188-13191: Connector migrations (Bing, Google, Tavily, Brave) - Pending - PR #13194: Samples and documentation - Pending All PRs target the `feature-text-search-linq` branch for coordinated release. ## Migration Guide for Consumers ### Before (Previous API) ```csharp ITextSearch<DataModel> search = ...; KernelSearchResults<object> results = await search.GetSearchResultsAsync("query", options); foreach (var obj in results.Results) { var record = (DataModel)obj; // Manual cast required Console.WriteLine(record.Name); } ``` ### After (Improved API) ```csharp ITextSearch<DataModel> search = ...; KernelSearchResults<DataModel> results = await search.GetSearchResultsAsync("query", options); foreach (var record in results.Results) // Strongly typed! { Console.WriteLine(record.Name); // Direct property access with IntelliSense } ``` ## Checklist - [x] Changes build successfully - [x] All unit tests pass (19/19) - [x] XML documentation updated - [x] Breaking change documented (experimental API only) - [x] Legacy interface backward compatibility maintained - [x] Code follows project coding standards Co-authored-by: Alexander Zarei <alzarei@users.noreply.github.com>
7 tasks
46e2f37 to
fe8e8aa
Compare
3ae3447 to
b306591
Compare
alzarei
commented
Nov 11, 2025
dotnet/samples/GettingStartedWithTextSearch/InMemoryVectorStoreFixture.cs
Show resolved
Hide resolved
dotnet/samples/GettingStartedWithTextSearch/Step1_Web_Search.cs
Outdated
Show resolved
Hide resolved
westey-m
reviewed
Nov 12, 2025
dotnet/src/VectorData/VectorData.Abstractions/FilterClauses/SearchQueryFilterClause.cs
Outdated
Show resolved
Hide resolved
Author
|
Hey @westey-m, @markwallace-microsoft, @roji: this PR is ready for review! When you get a chance, please check out the latest commit (there are just two in total). @roji, this branch includes all the code for the feature, with everything else rebased and cherry-picked in. Thanks! |
6a2e4a6 to
b306591
Compare
b306591 to
d84ccdc
Compare
westey-m
reviewed
Nov 12, 2025
dotnet/src/VectorData/VectorData.Abstractions/VectorData.Abstractions.csproj
Outdated
Show resolved
Hide resolved
d84ccdc to
5c86134
Compare
5c86134 to
594f4dd
Compare
594f4dd to
e877680
Compare
westey-m
approved these changes
Nov 19, 2025
…ples Add comprehensive LINQ filtering demonstrations for the new ITextSearch<TRecord> interface to showcase type-safe search capabilities across multiple connectors. **GettingStartedWithTextSearch (Step1_Web_Search.cs):** - Add BingSearchWithLinqFilteringAsync() demonstrating ITextSearch<BingWebPage> with Language and FamilyFriendly filters - Add GoogleSearchWithLinqFilteringAsync() demonstrating ITextSearch<GoogleWebPage> with Title.Contains() and DisplayLink.EndsWith() filters - Use interface type declaration (ITextSearch<TRecord>) to showcase the new generic interface - Include CA1859 pragma suppression with explanation (sample intentionally demonstrates interface usage) **Concepts (Bing_TextSearch.cs):** - Add UsingBingTextSearchWithLinqFilteringAsync() with 4 progressive LINQ filter examples - Demonstrate Language equality, FamilyFriendly boolean filtering, compound AND filters, and complex multi-property filters - Show both SearchAsync() and GetSearchResultsAsync() usage patterns **Concepts (Tavily_TextSearch.cs):** - Add UsingTavilyTextSearchWithLinqFilteringAsync() with 4 progressive LINQ filter examples - Demonstrate Title.Contains() filtering, compound filters with exclusion (!Contains), full result retrieval with filtering, and complex multi-property filters - Showcase null-safety patterns with Title != null checks **Technical Notes:** - Uses ITextSearch<TRecord> interface type to avoid method ambiguity with legacy ITextSearch - Generic methods are explicitly implemented, requiring interface type or casting - All examples include proper null checks for nullable properties - Maintains backward compatibility with existing simple search examples Addresses microsoft#10456
e877680 to
7354b99
Compare
Author
|
@westey-m this one was rebased on top of the feature branch and ready to merge now. |
This was referenced Nov 23, 2025
b21dc2f
into
microsoft:feature-text-search-linq
10 checks passed
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.
Modernize samples and documentation for ITextSearch interface
Problem Statement
The existing GettingStartedWithTextSearch samples only demonstrate the legacy ITextSearch interface with clause-based filtering. With the introduction of generic ITextSearch interfaces, developers need clear examples showing both legacy patterns and modern LINQ-based patterns for migration guidance.
Technical Approach
This PR completes the Issue #10456 implementation by updating the GettingStartedWithTextSearch samples to demonstrate the new generic ITextSearch interface with LINQ filtering capabilities. The implementation focuses on developer education and smooth migration paths.
Implementation Details
Sample Structure
Educational Content
Code Examples
Legacy Interface (Preserved)
Modern Interface Examples
Implementation Benefits
For Developers Learning Text Search
For Existing Users
For the Semantic Kernel Ecosystem
Validation Results
Build Verification
dotnet build --configuration Release --interactiveTest Results
Full Test Suite (with external dependencies):
Core Unit Tests (framework only):
dotnet test src\SemanticKernel.UnitTests\SemanticKernel.UnitTests.csproj --configuration ReleaseTest Failure Analysis
The 2,934 test failures are infrastructure/configuration issues, not code defects:
These failures are expected in development environments without external API configurations.
Code Quality
dotnet format SK-dotnet.slnx- no changes required (already compliant)Files Modified
Breaking Changes
None. All existing samples continue to work unchanged with new content being additive only.
Multi-PR Context
This is PR 6 of 6 in the structured implementation approach for Issue #10456. This PR provides educational content and sample modernization to complete the comprehensive text search interface modernization, enabling developers to understand and adopt the new LINQ-based filtering patterns.