Skip to content

.Net: Net: Address roji/westey review feedback round 2 on text search connectors (#10456)#13611

Merged
roji merged 5 commits intomicrosoft:feature-text-search-linqfrom
alzarei:address-roji-review-feedback-2
Mar 2, 2026
Merged

.Net: Net: Address roji/westey review feedback round 2 on text search connectors (#10456)#13611
roji merged 5 commits intomicrosoft:feature-text-search-linqfrom
alzarei:address-roji-review-feedback-2

Conversation

@alzarei
Copy link
Contributor

@alzarei alzarei commented Mar 1, 2026

.Net: Address roji/westey review feedback round 2 on text search connectors (#10456)

Motivation and Context

Addresses second round of review feedback from @roji and @westey-m on PR #13384 (feature-text-search-linq). This round focuses on code quality improvements: adding [Obsolete] attributes to legacy types, consolidating expression processing with pattern matching, and removing dead code.

Issue: #10456

Description

Obsolete attributes

Marked the following legacy types as [Obsolete] to signal the transition to LINQ-based filtering:

  • FilterClause, EqualToFilterClause, AnyTagEqualToFilterClause (VectorData.Abstractions) — base filter clause hierarchy replaced by LINQ expressions
  • TextSearchFilter (SemanticKernel.Abstractions) — replaced by TextSearchOptions<TRecord>.Filter
  • TextSearchOptions (non-generic, SemanticKernel.Abstractions) — replaced by TextSearchOptions<TRecord>

Google connector refactoring

Consolidated 8 expression-processing methods into 3 using C# pattern matching:

  • ProcessFilterNode: Recursive switch-based handler for AND, equality, inequality, string Contains, null-guard, collection Contains (error), and negation patterns
  • ProcessNegatedFilterNode: Handles !(expr) patterns, mapping to Google's excludeTerms
  • MapPropertyToGoogleFilter: Converted to expression-bodied member
  • Removed: TryProcessSingleExpression, TryProcessEqualityExpression, TryProcessInequalityExpression, TryProcessContainsExpression, TryProcessNotExpression, CollectAndCombineFilters, IsMemoryExtensionsContains, MapGoogleFilterToProperty (dead code)

Bing/Brave/Tavily connector cleanup

  • Pattern matching switch expressions replacing if-chains
  • Removed MemoryExtensions type checks — replaced with Object: null for static method detection
  • Expression-bodied property mapper methods

Error handling improvements

  • Collection Contains: Google and Bing now throw NotSupportedException with actionable guidance when collection.Contains(page.Property) is used (unsupported by these APIs)
  • ExtractFiltersFromLegacy: All four connectors now throw on unsupported FilterClause subtypes instead of silently skipping
  • Null-guard patterns: Google correctly handles page.Property != null comparisons (silently skipped)

Pragma consolidation

  • Replaced scattered #pragma warning disable/restore CS0618 pairs with single file-level pragmas across 22 files (library, tests, samples, integration tests)
  • Fixed AgentWithTextSearchProvider.cs where a local #pragma warning restore CS0618 was re-enabling the warning mid-method

Files Changed

Commit 1: Core changes (15 files, +198/-445)

File Change
FilterClause.cs Added [Obsolete]
EqualToFilterClause.cs Added [Obsolete]
AnyTagEqualToFilterClause.cs Added [Obsolete]
TextSearchFilter.cs Added [Obsolete], file-level pragma
TextSearchOptions.cs Added [Obsolete] on non-generic class
GoogleTextSearch.cs Major refactoring: 8→3 methods, pattern matching, null-guard, dead code removal
BingTextSearch.cs Pattern matching, removed MemoryExtensions, collection Contains error
BraveTextSearch.cs Pattern matching, removed MemoryExtensions, file-level pragma
TavilyTextSearch.cs Pattern matching, removed MemoryExtensions, file-level pragma
VectorStoreTextSearch.cs File-level pragma consolidation
TextSearchExtensions.cs File-level pragma consolidation
TextSearchProviderOptions.cs File-level pragma
MockTextSearch.cs (UnitTests) File-level pragma
MockTextSearch.cs (AotTests) File-level pragma
VectorStoreTextSearchTests.cs File-level pragma

Commit 2: Pragma fixes for samples/tests (7 files, +16/-1)

File Change
Bing_RagWithTextSearch.cs Added file-level #pragma warning disable CS0618
Bing_FunctionCallingWithTextSearch.cs Added file-level pragma
Bing_TextSearch.cs Added file-level pragma
Google_TextSearch.cs Added file-level pragma
Tavily_TextSearch.cs Added file-level pragma
Step3_Search_With_FunctionCalling.cs Added file-level pragma
AgentWithTextSearchProvider.cs Added file-level pragma, removed conflicting local restore

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

Validation

Check Result
Format (dotnet format --verify-no-changes) ✅ Pass
Build (dotnet build SK-dotnet.slnx -c Release --warnaserror --no-incremental) ✅ Pass (0 warnings, 0 errors)
Unit tests (full solution) ✅ 1606/1606 passed
AOT publish (dotnet publish -f net10.0) ✅ Pass
Validated twice — clean build both rounds

- Add [Obsolete] to FilterClause, EqualToFilterClause, AnyTagEqualToFilterClause
- Add [Obsolete] to non-generic TextSearchOptions and TextSearchFilter
- Refactor Google connector: merge 8 methods into 3 using pattern matching
- Refactor Bing/Brave/Tavily: pattern matching, remove MemoryExtensions
- Add explicit error for collection Contains (Enumerable.Contains) in Google/Bing
- Handle null-guard patterns (x != null) in Google expression processing
- Remove dead code (MapGoogleFilterToProperty)
- Consolidate pragma CS0618 to file-level in all affected files
- ExtractFiltersFromLegacy: throw on unsupported FilterClause types
@alzarei alzarei requested a review from a team as a code owner March 1, 2026 10:17
@moonbox3 moonbox3 added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Mar 1, 2026
@github-actions github-actions bot changed the title Net: Address roji/westey review feedback round 2 on text search connectors (#10456) .Net: Net: Address roji/westey review feedback round 2 on text search connectors (#10456) Mar 1, 2026
@alzarei alzarei force-pushed the address-roji-review-feedback-2 branch from 7d5f751 to 45e852b Compare March 2, 2026 07:14
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // Obsolete ITextSearch, TextSearchOptions, TextSearchFilter, FilterClause - backward compatibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally these would still be around the code using the obsolete legacy filtering stuff rather than over the entire file... Like I'd group all the legacy APIs in a #region and apply the suppression there.

Or is it too much somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yes, I like the suggested style too. Will revise shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alzarei I'm still seeing a file-scoped suppression here - the point is to more narrowly scope the suppression so we don't accidentally use another unrelated obsolete API etc.

/// A <see cref="FilterClause"/> is used to request that the underlying search service should
/// filter search results based on the specified criteria.
/// </remarks>
[Obsolete("Use LINQ expressions via TextSearchOptions<TRecord>.Filter instead. This type will be removed in a future version.")]
Copy link
Member

@roji roji Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obsoletion message is incorrect - we're in MEVD, so we shouldn't be mentioning TextSearchOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Scope file-level #pragma warning disable CS0618 to only surround
  code that references obsolete types, leaving LINQ-based methods clean
- Fix FilterClause/EqualToFilterClause/AnyTagEqualToFilterClause
  [Obsolete] messages to reference VectorSearchOptions<TRecord>.Filter
  (these types live in VectorData.Abstractions, not TextSearch)
Per reviewer feedback, replace file-level #pragma warning disable CS0618
with surgically scoped pragmas around only the code that references
obsolete types (ITextSearch, TextSearchOptions, TextSearchFilter,
FilterClause, ITextEmbeddingGenerationService).

- 4 connectors (Bing/Brave/Google/Tavily): scope to class declaration,
  legacy ITextSearch methods region, and ExtractFiltersFromLegacy
- VectorStoreTextSearch: scope to class declaration, obsolete
  constructors, legacy methods region, legacy ExecuteVectorSearchAsync,
  _textEmbeddingGeneration field, and BuildFilterExpression
- VectorStoreTextSearchTests: scope to legacy test methods only,
  leaving LINQ-based generic interface tests clean
@roji roji merged commit 42e0b2e into microsoft:feature-text-search-linq Mar 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants