Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - Sample demonstrates legacy interface usage

using Microsoft.SemanticKernel.Data;
using Microsoft.SemanticKernel.Plugins.Web.Bing;
using Microsoft.SemanticKernel.Plugins.Web.Google;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - Sample demonstrates legacy interface usage

using System.Text.RegularExpressions;
using HtmlAgilityPack;
using Microsoft.SemanticKernel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public abstract class AgentWithTextSearchProvider<TFixture>(Func<TFixture> creat
public async Task TextSearchBehaviorStateIsUsedByAgentInternalAsync(string question, string expectedResult, params string[] ragResults)
{
// Arrange
#pragma warning disable CS0618 // ITextSearch is obsolete - Testing legacy interface
var mockTextSearch = new Mock<ITextSearch>();
#pragma warning restore CS0618
mockTextSearch.Setup(x => x.GetTextSearchResultsAsync(
It.IsAny<string>(),
It.IsAny<TextSearchOptions>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Connectors.Qdrant;
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/IntegrationTests/Data/BaseTextSearchTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // Type or member is obsolete - Testing legacy non-generic ITextSearch interface

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.IO;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.IO;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.IO;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete

using System;
using System.IO;
using System.Linq;
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/Plugins/Plugins.Web/Bing/BingTextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace Microsoft.SemanticKernel.Plugins.Web.Bing;
/// <summary>
/// A Bing Text Search implementation that can be used to perform searches using the Bing Web Search API.
/// </summary>
#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility
public sealed class BingTextSearch : ITextSearch
#pragma warning restore CS0618
{
/// <summary>
/// Create an instance of the <see cref="BingTextSearch"/> with API key authentication.
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/Plugins/Plugins.Web/Brave/BraveTextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace Microsoft.SemanticKernel.Plugins.Web.Brave;
/// <summary>
/// A Brave Text Search implementation that can be used to perform searches using the Brave Web Search API.
/// </summary>
#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility
public sealed class BraveTextSearch : ITextSearch
#pragma warning restore CS0618
{
/// <summary>
/// Create an instance of the <see cref="BraveTextSearch"/> with API key authentication.
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/Plugins/Plugins.Web/Google/GoogleTextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace Microsoft.SemanticKernel.Plugins.Web.Google;
/// <summary>
/// A Google Text Search implementation that can be used to perform searches using the Google Web Search API.
/// </summary>
#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility
public sealed class GoogleTextSearch : ITextSearch, IDisposable
#pragma warning restore CS0618
{
/// <summary>
/// Initializes a new instance of the <see cref="GoogleTextSearch"/> class.
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/Plugins/Plugins.Web/Tavily/TavilyTextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace Microsoft.SemanticKernel.Plugins.Web.Tavily;
/// <summary>
/// A Tavily Text Search implementation that can be used to perform searches using the Tavily Web Search API.
/// </summary>
#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility
public sealed class TavilyTextSearch : ITextSearch
#pragma warning restore CS0618
{
/// <summary>
/// Create an instance of the <see cref="TavilyTextSearch"/> with API key authentication.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - these extension methods provide backward compatibility

using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel.Data;
using Microsoft.SemanticKernel.Plugins.Web.Bing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Task<KernelSearchResults<object>> GetSearchResultsAsync(

/// <summary>
/// Interface for text based search queries for use with Semantic Kernel prompts and automatic function calling.
/// This non-generic interface uses legacy <see cref="TextSearchFilter"/> for backward compatibility.
/// </summary>
[System.Obsolete("Use ITextSearch<TRecord> with LINQ-based filtering instead. This interface will be removed in a future version.")]
public interface ITextSearch
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace SemanticKernel.AotTests.UnitTests.Search;

#pragma warning disable CS0618 // Type or member is obsolete
internal sealed class MockTextSearch : ITextSearch
#pragma warning restore CS0618 // Type or member is obsolete
{
private readonly KernelSearchResults<object>? _objectResults;
private readonly KernelSearchResults<TextSearchResult>? _textSearchResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static async Task CreateWithSearch()
// Arrange
var testData = new List<string> { "test-value" };
KernelSearchResults<string> results = new(testData.ToAsyncEnumerable());
#pragma warning disable CS0618 // Type or member is obsolete
ITextSearch textSearch = new MockTextSearch(results);
#pragma warning restore CS0618 // Type or member is obsolete

// Act
var plugin = textSearch.CreateWithSearch("SearchPlugin", s_jsonSerializerOptions);
Expand All @@ -35,7 +37,9 @@ public static async Task CreateWithGetTextSearchResults()
// Arrange
var testData = new List<TextSearchResult> { new("test-value") };
KernelSearchResults<TextSearchResult> results = new(testData.ToAsyncEnumerable());
#pragma warning disable CS0618 // Type or member is obsolete
ITextSearch textSearch = new MockTextSearch(results);
#pragma warning restore CS0618 // Type or member is obsolete

// Act
var plugin = textSearch.CreateWithGetTextSearchResults("SearchPlugin", s_jsonSerializerOptions);
Expand All @@ -49,7 +53,9 @@ public static async Task CreateWithGetSearchResults()
// Arrange
var testData = new List<CustomResult> { new("test-value") };
KernelSearchResults<object> results = new(testData.ToAsyncEnumerable());
#pragma warning disable CS0618 // Type or member is obsolete
ITextSearch textSearch = new MockTextSearch(results);
#pragma warning restore CS0618 // Type or member is obsolete

// Act
var plugin = textSearch.CreateWithGetSearchResults("SearchPlugin", s_jsonSerializerOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - these extension methods provide backward compatibility

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace Microsoft.SemanticKernel.Data;
/// A Vector Store Text Search implementation that can be used to perform searches using a <see cref="VectorStoreCollection{TKey, TRecord}"/>.
/// </summary>
[Experimental("SKEXP0001")]
#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility
public sealed class VectorStoreTextSearch<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TRecord> : ITextSearch<TRecord>, ITextSearch
#pragma warning restore CS0618
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>
Expand Down Expand Up @@ -268,19 +270,22 @@ private TextSearchStringMapper CreateTextSearchStringMapper()
}

/// <summary>
/// Execute a vector search and return the results.
/// Execute a vector search and return the results using legacy filtering for backward compatibility.
/// </summary>
/// <param name="query">What to search for.</param>
/// <param name="searchOptions">Search options.</param>
/// <param name="searchOptions">Search options with legacy TextSearchFilter.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
private async IAsyncEnumerable<VectorSearchResult<TRecord>> ExecuteVectorSearchAsync(string query, TextSearchOptions? searchOptions, [EnumeratorCancellation] CancellationToken cancellationToken)
{
searchOptions ??= new TextSearchOptions();

var vectorSearchOptions = new VectorSearchOptions<TRecord>
{
#pragma warning disable CS0618 // VectorSearchFilter is obsolete
OldFilter = searchOptions.Filter?.FilterClauses is not null ? new VectorSearchFilter(searchOptions.Filter.FilterClauses) : null,
#pragma warning restore CS0618 // VectorSearchFilter is obsolete
OldFilter = searchOptions.Filter?.FilterClauses is not null
? new VectorSearchFilter(searchOptions.Filter.FilterClauses)
: null,
#pragma warning restore CS0618
Skip = searchOptions.Skip,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // ITextSearch is obsolete - this class provides backward compatibility

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/SemanticKernel.UnitTests/Data/MockTextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace SemanticKernel.UnitTests.Data;
/// <summary>
/// Mock implementation of <see cref="ITextSearch"/>
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
internal sealed class MockTextSearch(int count = 3, long totalCount = 30) : ITextSearch
#pragma warning restore CS0618 // Type or member is obsolete
{
/// <inheritdoc/>
public Task<KernelSearchResults<object>> GetSearchResultsAsync(string query, TextSearchOptions? searchOptions = null, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable CS0618 // Type or member is obsolete - Testing legacy non-generic ITextSearch interface

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public string MapFromResultToString(object result)
{
DataModel dataModel => dataModel.Text,
DataModelWithRawEmbedding dataModelWithRawEmbedding => dataModelWithRawEmbedding.Text,
DataModelWithTags dataModelWithTags => dataModelWithTags.Text,
_ => throw new ArgumentException("Invalid result type.")
};
}
Expand All @@ -155,6 +156,7 @@ public TextSearchResult MapFromResultToTextSearchResult(object result)
{
DataModel dataModel => new TextSearchResult(value: dataModel.Text) { Name = dataModel.Key.ToString() },
DataModelWithRawEmbedding dataModelWithRawEmbedding => new TextSearchResult(value: dataModelWithRawEmbedding.Text) { Name = dataModelWithRawEmbedding.Key.ToString() },
DataModelWithTags dataModelWithTags => new TextSearchResult(value: dataModelWithTags.Text) { Name = dataModelWithTags.Key.ToString() },
_ => throw new ArgumentException("Invalid result type.")
};
}
Expand Down Expand Up @@ -231,4 +233,27 @@ public sealed class DataModelWithRawEmbedding
[VectorStoreVector(1536)]
public ReadOnlyMemory<float> Embedding { get; init; }
}

/// <summary>
/// Sample model class for testing collection-based filtering (AnyTagEqualTo).
/// </summary>
#pragma warning disable CA1812 // Avoid uninstantiated internal classes
public sealed class DataModelWithTags
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
{
[VectorStoreKey]
public Guid Key { get; init; }

[VectorStoreData]
public required string Text { get; init; }

[VectorStoreData(IsIndexed = true)]
public required string Tag { get; init; }

[VectorStoreData(IsIndexed = true)]
public required IReadOnlyList<string> Tags { get; init; }

[VectorStoreVector(1536)]
public string? Embedding { get; init; }
}
}
Loading
Loading