.Net Improve type safety: Return TRecord instead of object in ITextSearch.GetSearchResultsAsync #13318
+35
−10
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.
This PR enhances the type safety of the
ITextSearch<TRecord>interface by changing theGetSearchResultsAsyncmethod to returnKernelSearchResults<TRecord>instead ofKernelSearchResults<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>.GetSearchResultsAsyncreturnsKernelSearchResults<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)
ITextSearch<TRecord>.GetSearchResultsAsyncreturn type fromKernelSearchResults<object>toKernelSearchResults<TRecord>ITextSearchinterface (non-generic) remains unchanged, continuing to returnKernelSearchResults<object>for backward compatibilityImplementation (VectorStoreTextSearch.cs)
GetResultsAsTRecordAsynchelper method returningIAsyncEnumerable<TRecord>GetResultsAsRecordAsyncmethod for the legacy non-generic interfaceTests (VectorStoreTextSearchTests.cs)
DataModelorDataModelWithRawEmbeddinginstead ofobjectBreaking Changes
Interface Change (Experimental API):
ITextSearch<TRecord>.GetSearchResultsAsyncnow returnsKernelSearchResults<TRecord>instead ofKernelSearchResults<object>[Experimental("SKEXP0001")], indicating that breaking changes are expected during the preview periodITextSearchinterface (non-generic) is unaffected and maintains full backward compatibilityBenefits
Testing
Related Work
This PR is part of the Issue #10456 multi-PR chain for modernizing ITextSearch with LINQ-based filtering:
All PRs target the
feature-text-search-linqbranch for coordinated release.Migration Guide for Consumers
Before (Previous API)
After (Improved API)
Checklist