Skip to content

Commit

Permalink
Rename Azure Search to Azure Cognitive Search (#2075)
Browse files Browse the repository at this point in the history
### Motivation and Context

The service was renamed to Azure Cognitive Search in 2019, so we should
follow the new convention. The only thing still named "Azure Search" is
the old Azure SDK, out of scope.

### Description

* Revert nuget package name to the previous name (we'll delete the new
package, which has been out only for few days)
* Rename C# and Python classes and namespaces
  • Loading branch information
dluc committed Jul 19, 2023
1 parent 11d00e0 commit 8b4d916
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 105 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ jobs:
Pinecone__ApiKey: ${{ secrets.PINECONE__APIKEY }}
Pinecone__Environment: ${{ secrets.PINECONE__ENVIRONMENT }}
Postgres__Connectionstr: ${{secrets.POSTGRES__CONNECTIONSTR}}
AZURE_SEARCH_ADMIN_KEY: ${{secrets.AZURE_SEARCH_ADMIN_KEY}}
AZURE_SEARCH_ENDPOINT: ${{secrets.AZURE_SEARCH_ENDPOINT}}
AZURE_COGNITIVE_SEARCH_ADMIN_KEY: ${{secrets.AZURE_COGNITIVE_SEARCH_ADMIN_KEY}}
AZURE_COGNITIVE_SEARCH_ENDPOINT: ${{secrets.AZURE_COGNITIVE_SEARCH_ENDPOINT}}
run: |
cd python
poetry run pytest ./tests/integration
2 changes: 1 addition & 1 deletion .github/workflows/python-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
python -m pip install poetry pytest
cd python
poetry install --without chromadb --without hugging_face --without azure_search --without weaviate --without pinecone --without postgres
poetry install --without chromadb --without hugging_face --without azure_cognitive_search --without weaviate --without pinecone --without postgres
- name: Test with pytest
run: |
cd python && poetry run pytest ./tests/unit
2 changes: 1 addition & 1 deletion dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Extensions.UnitTests", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Planning.SequentialPlanner", "src\Extensions\Planning.SequentialPlanner\Planning.SequentialPlanner.csproj", "{A350933D-F9D5-4AD3-8C4F-B856B5020297}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectors.Memory.AzureSearch", "src\Connectors\Connectors.Memory.AzureSearch\Connectors.Memory.AzureSearch.csproj", "{EC3BB6D1-2FB2-4702-84C6-F791DE533ED4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectors.Memory.AzureCognitiveSearch", "src\Connectors\Connectors.Memory.AzureCognitiveSearch\Connectors.Memory.AzureCognitiveSearch.csproj", "{EC3BB6D1-2FB2-4702-84C6-F791DE533ED4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectors.Memory.Pinecone", "src\Connectors\Connectors.Memory.Pinecone\Connectors.Memory.Pinecone.csproj", "{4D226C2F-AE9F-4EFB-AF2D-45C8FE5CB34E}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Memory.AzureSearch;
using Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch;
using Microsoft.SemanticKernel.Memory;
using RepoUtils;

Expand Down Expand Up @@ -37,7 +37,7 @@ public static async Task RunAsync()
var kernelWithACS = Kernel.Builder
.WithLogger(ConsoleLogger.Log)
.WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", TestConfiguration.OpenAI.ApiKey)
.WithMemoryStorage(new AzureSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
.WithMemoryStorage(new AzureCognitiveSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
.Build();

await RunExampleAsync(kernelWithACS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Connectors\Connectors.AI.OpenAI\Connectors.AI.OpenAI.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.AI.HuggingFace\Connectors.AI.HuggingFace.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.AzureSearch\Connectors.Memory.AzureSearch.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.AzureCognitiveSearch\Connectors.Memory.AzureCognitiveSearch.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.Chroma\Connectors.Memory.Chroma.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.Postgres\Connectors.Memory.Postgres.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.Weaviate\Connectors.Memory.Weaviate.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

using System;

namespace Microsoft.SemanticKernel.Connectors.Memory.AzureSearch;
namespace Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch;

#pragma warning disable RCS1194 // Implement exception constructors

/// <summary>
/// Exception thrown by the Azure Cognitive Search connector
/// </summary>
public class AzureSearchMemoryException : Exception
public class AzureCognitiveSearchMemoryException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureSearchMemoryException"/> class with a provided error code and message.
/// Initializes a new instance of the <see cref="AzureCognitiveSearchMemoryException"/> class with a provided error code and message.
/// </summary>
/// <param name="errorCode">The error code.</param>
/// <param name="message">The exception message.</param>
public AzureSearchMemoryException(ErrorCodes errorCode, string? message)
public AzureCognitiveSearchMemoryException(ErrorCodes errorCode, string? message)
: this(errorCode, message, innerException: null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AzureSearchMemoryException"/> class with a provided error code, message, and inner exception.
/// Initializes a new instance of the <see cref="AzureCognitiveSearchMemoryException"/> class with a provided error code, message, and inner exception.
/// </summary>
/// <param name="errorCode">The error code.</param>
/// <param name="message">A string that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public AzureSearchMemoryException(ErrorCodes errorCode, string? message, Exception? innerException)
public AzureCognitiveSearchMemoryException(ErrorCodes errorCode, string? message, Exception? innerException)
: base(GetDefaultMessage(errorCode, message, innerException), innerException)
{
this.ErrorCode = errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Memory;

namespace Microsoft.SemanticKernel.Connectors.Memory.AzureSearch;
namespace Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch;

/// <summary>
/// Azure Cognitive Search record and index definition.
/// Note: once defined, index cannot be modified.
/// </summary>
public class AzureSearchMemoryRecord
public class AzureCognitiveSearchMemoryRecord
{
public const string IdField = "Id";
public const string TextField = "Text";
Expand Down Expand Up @@ -73,16 +73,16 @@ public class AzureSearchMemoryRecord
/// <summary>
/// Ctor required by JSON deserializer
/// </summary>
public AzureSearchMemoryRecord()
public AzureCognitiveSearchMemoryRecord()
{
}

public AzureSearchMemoryRecord(string id)
public AzureCognitiveSearchMemoryRecord(string id)
{
this.Id = EncodeId(id);
}

public AzureSearchMemoryRecord(
public AzureCognitiveSearchMemoryRecord(
string id,
string text,
string externalSourceName,
Expand Down Expand Up @@ -111,9 +111,9 @@ public MemoryRecordMetadata ToMemoryRecordMetadata()
additionalMetadata: this.AdditionalMetadata ?? string.Empty);
}

public static AzureSearchMemoryRecord FromMemoryRecord(MemoryRecord record)
public static AzureCognitiveSearchMemoryRecord FromMemoryRecord(MemoryRecord record)
{
return new AzureSearchMemoryRecord(
return new AzureCognitiveSearchMemoryRecord(
id: record.Metadata.Id,
text: record.Metadata.Text,
externalSourceName: string.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Memory;

namespace Microsoft.SemanticKernel.Connectors.Memory.AzureSearch;
namespace Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch;

public class AzureSearchMemoryStore : IMemoryStore
public class AzureCognitiveSearchMemoryStore : IMemoryStore
{
// Note: Azure max length 24 chars
private const string UserAgent = "Semantic-Kernel";
Expand All @@ -29,7 +29,7 @@ public class AzureSearchMemoryStore : IMemoryStore
/// </summary>
/// <param name="endpoint">Azure Cognitive Search URI, e.g. "https://contoso.search.windows.net"</param>
/// <param name="apiKey">API Key</param>
public AzureSearchMemoryStore(string endpoint, string apiKey)
public AzureCognitiveSearchMemoryStore(string endpoint, string apiKey)
{
AzureKeyCredential credentials = new(apiKey);
this._adminClient = new SearchIndexClient(new Uri(endpoint), credentials, ClientOptions());
Expand All @@ -40,7 +40,7 @@ public AzureSearchMemoryStore(string endpoint, string apiKey)
/// </summary>
/// <param name="endpoint">Azure Cognitive Search URI, e.g. "https://contoso.search.windows.net"</param>
/// <param name="credentials">Azure service</param>
public AzureSearchMemoryStore(string endpoint, TokenCredential credentials)
public AzureCognitiveSearchMemoryStore(string endpoint, TokenCredential credentials)
{
this._adminClient = new SearchIndexClient(new Uri(endpoint), credentials, ClientOptions());
}
Expand Down Expand Up @@ -81,15 +81,15 @@ public Task DeleteCollectionAsync(string collectionName, CancellationToken cance
public Task<string> UpsertAsync(string collectionName, MemoryRecord record, CancellationToken cancellationToken = default)
{
collectionName = this.NormalizeIndexName(collectionName);
return this.UpsertRecordAsync(collectionName, AzureSearchMemoryRecord.FromMemoryRecord(record), cancellationToken);
return this.UpsertRecordAsync(collectionName, AzureCognitiveSearchMemoryRecord.FromMemoryRecord(record), cancellationToken);
}

/// <inheritdoc />
public async IAsyncEnumerable<string> UpsertBatchAsync(string collectionName, IEnumerable<MemoryRecord> records, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
collectionName = this.NormalizeIndexName(collectionName);
IList<AzureSearchMemoryRecord> azureSearchRecords = records.Select(AzureSearchMemoryRecord.FromMemoryRecord).ToList();
List<string> result = await this.UpsertBatchAsync(collectionName, azureSearchRecords, cancellationToken).ConfigureAwait(false);
IList<AzureCognitiveSearchMemoryRecord> searchRecords = records.Select(AzureCognitiveSearchMemoryRecord.FromMemoryRecord).ToList();
List<string> result = await this.UpsertBatchAsync(collectionName, searchRecords, cancellationToken).ConfigureAwait(false);
foreach (var x in result) { yield return x; }
}

Expand All @@ -98,11 +98,11 @@ public async IAsyncEnumerable<string> UpsertBatchAsync(string collectionName, IE
{
collectionName = this.NormalizeIndexName(collectionName);
var client = this.GetSearchClient(collectionName);
Response<AzureSearchMemoryRecord>? result;
Response<AzureCognitiveSearchMemoryRecord>? result;
try
{
result = await client
.GetDocumentAsync<AzureSearchMemoryRecord>(AzureSearchMemoryRecord.EncodeId(key), cancellationToken: cancellationToken)
.GetDocumentAsync<AzureCognitiveSearchMemoryRecord>(AzureCognitiveSearchMemoryRecord.EncodeId(key), cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (RequestFailedException e) when (e.Status == 404)
Expand All @@ -113,8 +113,8 @@ public async IAsyncEnumerable<string> UpsertBatchAsync(string collectionName, IE

if (result?.Value == null)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.ReadFailure,
throw new AzureCognitiveSearchMemoryException(
AzureCognitiveSearchMemoryException.ErrorCodes.ReadFailure,
"Memory read returned null");
}

Expand Down Expand Up @@ -164,16 +164,16 @@ public async IAsyncEnumerable<MemoryRecord> GetBatchAsync(
SearchQueryVector vectorQuery = new()
{
KNearestNeighborsCount = limit,
Fields = AzureSearchMemoryRecord.EmbeddingField,
Fields = AzureCognitiveSearchMemoryRecord.EmbeddingField,
Value = embedding.Vector.ToList()
};

SearchOptions options = new() { Vector = vectorQuery };
Response<SearchResults<AzureSearchMemoryRecord>>? searchResult = null;
Response<SearchResults<AzureCognitiveSearchMemoryRecord>>? searchResult = null;
try
{
searchResult = await client
.SearchAsync<AzureSearchMemoryRecord>(null, options, cancellationToken: cancellationToken)
.SearchAsync<AzureCognitiveSearchMemoryRecord>(null, options, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (RequestFailedException e) when (e.Status == 404)
Expand All @@ -183,7 +183,7 @@ public async IAsyncEnumerable<MemoryRecord> GetBatchAsync(

if (searchResult == null) { yield break; }

await foreach (SearchResult<AzureSearchMemoryRecord>? doc in searchResult.Value.GetResultsAsync())
await foreach (SearchResult<AzureCognitiveSearchMemoryRecord>? doc in searchResult.Value.GetResultsAsync())
{
if (doc == null || doc.Score < minRelevanceScore) { continue; }

Expand All @@ -204,7 +204,7 @@ public async Task RemoveBatchAsync(string collectionName, IEnumerable<string> ke
{
collectionName = this.NormalizeIndexName(collectionName);

var records = keys.Select(x => new List<AzureSearchMemoryRecord> { new(x) });
var records = keys.Select(x => new List<AzureCognitiveSearchMemoryRecord> { new(x) });

var client = this.GetSearchClient(collectionName);
try
Expand Down Expand Up @@ -246,8 +246,8 @@ private Task<Response<SearchIndex>> CreateIndexAsync(
{
if (embeddingSize < 1)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.InvalidEmbeddingSize,
throw new AzureCognitiveSearchMemoryException(
AzureCognitiveSearchMemoryException.ErrorCodes.InvalidEmbeddingSize,
"Invalid embedding size: the value must be greater than zero.");
}

Expand All @@ -256,18 +256,18 @@ private Task<Response<SearchIndex>> CreateIndexAsync(
{
Fields = new List<SearchField>
{
new SimpleField(AzureSearchMemoryRecord.IdField, SearchFieldDataType.String) { IsKey = true },
new SearchField(AzureSearchMemoryRecord.EmbeddingField, SearchFieldDataType.Collection(SearchFieldDataType.Single))
new SimpleField(AzureCognitiveSearchMemoryRecord.IdField, SearchFieldDataType.String) { IsKey = true },
new SearchField(AzureCognitiveSearchMemoryRecord.EmbeddingField, SearchFieldDataType.Collection(SearchFieldDataType.Single))
{
IsSearchable = true,
VectorSearchDimensions = embeddingSize,
VectorSearchConfiguration = configName
},
new SearchField(AzureSearchMemoryRecord.TextField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureSearchMemoryRecord.DescriptionField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureSearchMemoryRecord.AdditionalMetadataField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureSearchMemoryRecord.ExternalSourceNameField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureSearchMemoryRecord.IsReferenceField, SearchFieldDataType.Boolean) { IsFilterable = true, IsFacetable = true },
new SearchField(AzureCognitiveSearchMemoryRecord.TextField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureCognitiveSearchMemoryRecord.DescriptionField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureCognitiveSearchMemoryRecord.AdditionalMetadataField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureCognitiveSearchMemoryRecord.ExternalSourceNameField, SearchFieldDataType.String) { IsFilterable = true, IsFacetable = true },
new SimpleField(AzureCognitiveSearchMemoryRecord.IsReferenceField, SearchFieldDataType.Boolean) { IsFilterable = true, IsFacetable = true },
},
VectorSearch = new VectorSearch
{
Expand Down Expand Up @@ -295,16 +295,16 @@ private async IAsyncEnumerable<string> GetIndexesAsync([EnumeratorCancellation]

private async Task<string> UpsertRecordAsync(
string indexName,
AzureSearchMemoryRecord record,
AzureCognitiveSearchMemoryRecord record,
CancellationToken cancellationToken = default)
{
var list = await this.UpsertBatchAsync(indexName, new List<AzureSearchMemoryRecord> { record }, cancellationToken).ConfigureAwait(false);
var list = await this.UpsertBatchAsync(indexName, new List<AzureCognitiveSearchMemoryRecord> { record }, cancellationToken).ConfigureAwait(false);
return list.First();
}

private async Task<List<string>> UpsertBatchAsync(
string indexName,
IList<AzureSearchMemoryRecord> records,
IList<AzureCognitiveSearchMemoryRecord> records,
CancellationToken cancellationToken = default)
{
var keys = new List<string>();
Expand Down Expand Up @@ -336,8 +336,8 @@ Task<Response<IndexDocumentsResult>> UpsertCode()

if (result == null || result.Value.Results.Count == 0)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.WriteFailure,
throw new AzureCognitiveSearchMemoryException(
AzureCognitiveSearchMemoryException.ErrorCodes.WriteFailure,
"Memory write returned null or an empty set");
}

Expand All @@ -355,8 +355,8 @@ private string NormalizeIndexName(string indexName)
{
if (indexName.Length > 128)
{
throw new AzureSearchMemoryException(
AzureSearchMemoryException.ErrorCodes.InvalidIndexName,
throw new AzureCognitiveSearchMemoryException(
AzureCognitiveSearchMemoryException.ErrorCodes.InvalidIndexName,
"The collection name is too long, it cannot exceed 128 chars.");
}

Expand Down Expand Up @@ -386,7 +386,7 @@ private SearchClient GetSearchClient(string indexName)
}

/// <summary>
/// Options used by the Azure Search client, e.g. User Agent.
/// Options used by the Azure Cognitive Search client, e.g. User Agent.
/// See also https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/src/DiagnosticsOptions.cs
/// </summary>
private static SearchClientOptions ClientOptions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- THIS PROPERTY GROUP MUST COME FIRST -->
<AssemblyName>Microsoft.SemanticKernel.Connectors.Memory.AzureSearch</AssemblyName>
<RootNamespace>Microsoft.SemanticKernel.Connectors.Memory.AzureSearch</RootNamespace>
<AssemblyName>Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch</AssemblyName>
<RootNamespace>Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>

<!--NU5104: A stable release of a package should not have a prerelease dependency.-->
Expand All @@ -15,9 +15,9 @@

<PropertyGroup>
<!-- NuGet Package Settings -->
<PackageId>Microsoft.SemanticKernel.Connectors.Memory.AzureSearch</PackageId>
<PackageId>Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch</PackageId>
<Title>Semantic Kernel - Azure Cognitive Search Semantic Memory</Title>
<Description>Azure Search Semantic Memory connector for Semantic Kernel</Description>
<Description>Azure Cognitive Search Semantic Memory connector for Semantic Kernel</Description>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 8b4d916

Please sign in to comment.