diff --git a/.github/workflows/python-integration-tests.yml b/.github/workflows/python-integration-tests.yml index a7c7d27e17a1..a8507300cd7a 100644 --- a/.github/workflows/python-integration-tests.yml +++ b/.github/workflows/python-integration-tests.yml @@ -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 diff --git a/.github/workflows/python-unit-tests.yml b/.github/workflows/python-unit-tests.yml index a4cbe06573fd..c125341d0296 100644 --- a/.github/workflows/python-unit-tests.yml +++ b/.github/workflows/python-unit-tests.yml @@ -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 diff --git a/dotnet/SK-dotnet.sln b/dotnet/SK-dotnet.sln index 4b8444a509aa..79ae7ae61185 100644 --- a/dotnet/SK-dotnet.sln +++ b/dotnet/SK-dotnet.sln @@ -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 diff --git a/dotnet/samples/KernelSyntaxExamples/Example14_SemanticMemory.cs b/dotnet/samples/KernelSyntaxExamples/Example14_SemanticMemory.cs index edd4e0a8ba08..a26db827821f 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example14_SemanticMemory.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example14_SemanticMemory.cs @@ -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; @@ -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); diff --git a/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj b/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj index 21d855e66029..244cadfa2ea4 100644 --- a/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj +++ b/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj @@ -31,7 +31,7 @@ - + diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryException.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryException.cs similarity index 76% rename from dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryException.cs rename to dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryException.cs index 5d31ac1a6b46..a21202fa1dff 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryException.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryException.cs @@ -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 /// /// Exception thrown by the Azure Cognitive Search connector /// -public class AzureSearchMemoryException : Exception +public class AzureCognitiveSearchMemoryException : Exception { /// - /// Initializes a new instance of the class with a provided error code and message. + /// Initializes a new instance of the class with a provided error code and message. /// /// The error code. /// The exception message. - public AzureSearchMemoryException(ErrorCodes errorCode, string? message) + public AzureCognitiveSearchMemoryException(ErrorCodes errorCode, string? message) : this(errorCode, message, innerException: null) { } /// - /// Initializes a new instance of the class with a provided error code, message, and inner exception. + /// Initializes a new instance of the class with a provided error code, message, and inner exception. /// /// The error code. /// A string that describes the error. /// The exception that is the cause of the current exception. - 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; diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryRecord.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryRecord.cs similarity index 92% rename from dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryRecord.cs rename to dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryRecord.cs index 2a270d6273cd..40ece7daea7f 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryRecord.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryRecord.cs @@ -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; /// /// Azure Cognitive Search record and index definition. /// Note: once defined, index cannot be modified. /// -public class AzureSearchMemoryRecord +public class AzureCognitiveSearchMemoryRecord { public const string IdField = "Id"; public const string TextField = "Text"; @@ -73,16 +73,16 @@ public class AzureSearchMemoryRecord /// /// Ctor required by JSON deserializer /// - 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, @@ -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, diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryStore.cs similarity index 81% rename from dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryStore.cs rename to dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryStore.cs index cd3b73329f16..e007c5c0a4ad 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/AzureSearchMemoryStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/AzureCognitiveSearchMemoryStore.cs @@ -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"; @@ -29,7 +29,7 @@ public class AzureSearchMemoryStore : IMemoryStore /// /// Azure Cognitive Search URI, e.g. "https://contoso.search.windows.net" /// API Key - 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()); @@ -40,7 +40,7 @@ public AzureSearchMemoryStore(string endpoint, string apiKey) /// /// Azure Cognitive Search URI, e.g. "https://contoso.search.windows.net" /// Azure service - public AzureSearchMemoryStore(string endpoint, TokenCredential credentials) + public AzureCognitiveSearchMemoryStore(string endpoint, TokenCredential credentials) { this._adminClient = new SearchIndexClient(new Uri(endpoint), credentials, ClientOptions()); } @@ -81,15 +81,15 @@ public Task DeleteCollectionAsync(string collectionName, CancellationToken cance public Task 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); } /// public async IAsyncEnumerable UpsertBatchAsync(string collectionName, IEnumerable records, [EnumeratorCancellation] CancellationToken cancellationToken = default) { collectionName = this.NormalizeIndexName(collectionName); - IList azureSearchRecords = records.Select(AzureSearchMemoryRecord.FromMemoryRecord).ToList(); - List result = await this.UpsertBatchAsync(collectionName, azureSearchRecords, cancellationToken).ConfigureAwait(false); + IList searchRecords = records.Select(AzureCognitiveSearchMemoryRecord.FromMemoryRecord).ToList(); + List result = await this.UpsertBatchAsync(collectionName, searchRecords, cancellationToken).ConfigureAwait(false); foreach (var x in result) { yield return x; } } @@ -98,11 +98,11 @@ public async IAsyncEnumerable UpsertBatchAsync(string collectionName, IE { collectionName = this.NormalizeIndexName(collectionName); var client = this.GetSearchClient(collectionName); - Response? result; + Response? result; try { result = await client - .GetDocumentAsync(AzureSearchMemoryRecord.EncodeId(key), cancellationToken: cancellationToken) + .GetDocumentAsync(AzureCognitiveSearchMemoryRecord.EncodeId(key), cancellationToken: cancellationToken) .ConfigureAwait(false); } catch (RequestFailedException e) when (e.Status == 404) @@ -113,8 +113,8 @@ public async IAsyncEnumerable UpsertBatchAsync(string collectionName, IE if (result?.Value == null) { - throw new AzureSearchMemoryException( - AzureSearchMemoryException.ErrorCodes.ReadFailure, + throw new AzureCognitiveSearchMemoryException( + AzureCognitiveSearchMemoryException.ErrorCodes.ReadFailure, "Memory read returned null"); } @@ -164,16 +164,16 @@ public async IAsyncEnumerable GetBatchAsync( SearchQueryVector vectorQuery = new() { KNearestNeighborsCount = limit, - Fields = AzureSearchMemoryRecord.EmbeddingField, + Fields = AzureCognitiveSearchMemoryRecord.EmbeddingField, Value = embedding.Vector.ToList() }; SearchOptions options = new() { Vector = vectorQuery }; - Response>? searchResult = null; + Response>? searchResult = null; try { searchResult = await client - .SearchAsync(null, options, cancellationToken: cancellationToken) + .SearchAsync(null, options, cancellationToken: cancellationToken) .ConfigureAwait(false); } catch (RequestFailedException e) when (e.Status == 404) @@ -183,7 +183,7 @@ public async IAsyncEnumerable GetBatchAsync( if (searchResult == null) { yield break; } - await foreach (SearchResult? doc in searchResult.Value.GetResultsAsync()) + await foreach (SearchResult? doc in searchResult.Value.GetResultsAsync()) { if (doc == null || doc.Score < minRelevanceScore) { continue; } @@ -204,7 +204,7 @@ public async Task RemoveBatchAsync(string collectionName, IEnumerable ke { collectionName = this.NormalizeIndexName(collectionName); - var records = keys.Select(x => new List { new(x) }); + var records = keys.Select(x => new List { new(x) }); var client = this.GetSearchClient(collectionName); try @@ -246,8 +246,8 @@ private Task> 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."); } @@ -256,18 +256,18 @@ private Task> CreateIndexAsync( { Fields = new List { - 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 { @@ -295,16 +295,16 @@ private async IAsyncEnumerable GetIndexesAsync([EnumeratorCancellation] private async Task UpsertRecordAsync( string indexName, - AzureSearchMemoryRecord record, + AzureCognitiveSearchMemoryRecord record, CancellationToken cancellationToken = default) { - var list = await this.UpsertBatchAsync(indexName, new List { record }, cancellationToken).ConfigureAwait(false); + var list = await this.UpsertBatchAsync(indexName, new List { record }, cancellationToken).ConfigureAwait(false); return list.First(); } private async Task> UpsertBatchAsync( string indexName, - IList records, + IList records, CancellationToken cancellationToken = default) { var keys = new List(); @@ -336,8 +336,8 @@ Task> 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"); } @@ -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."); } @@ -386,7 +386,7 @@ private SearchClient GetSearchClient(string indexName) } /// - /// 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 /// private static SearchClientOptions ClientOptions() diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/Connectors.Memory.AzureSearch.csproj b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/Connectors.Memory.AzureCognitiveSearch.csproj similarity index 79% rename from dotnet/src/Connectors/Connectors.Memory.AzureSearch/Connectors.Memory.AzureSearch.csproj rename to dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/Connectors.Memory.AzureCognitiveSearch.csproj index a27dcf1466b1..a9e9143a793c 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureSearch/Connectors.Memory.AzureSearch.csproj +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCognitiveSearch/Connectors.Memory.AzureCognitiveSearch.csproj @@ -1,8 +1,8 @@ - Microsoft.SemanticKernel.Connectors.Memory.AzureSearch - Microsoft.SemanticKernel.Connectors.Memory.AzureSearch + Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch + Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch netstandard2.0 @@ -15,9 +15,9 @@ - Microsoft.SemanticKernel.Connectors.Memory.AzureSearch + Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch Semantic Kernel - Azure Cognitive Search Semantic Memory - Azure Search Semantic Memory connector for Semantic Kernel + Azure Cognitive Search Semantic Memory connector for Semantic Kernel diff --git a/dotnet/src/Connectors/Connectors.UnitTests/Connectors.UnitTests.csproj b/dotnet/src/Connectors/Connectors.UnitTests/Connectors.UnitTests.csproj index eeeedeee5625..62baaacb23ed 100644 --- a/dotnet/src/Connectors/Connectors.UnitTests/Connectors.UnitTests.csproj +++ b/dotnet/src/Connectors/Connectors.UnitTests/Connectors.UnitTests.csproj @@ -33,7 +33,7 @@ - + diff --git a/python/.env.example b/python/.env.example index 3bc4a37f102f..a1989cae275f 100644 --- a/python/.env.example +++ b/python/.env.example @@ -3,8 +3,8 @@ OPENAI_ORG_ID="" AZURE_OPENAI_DEPLOYMENT_NAME="" AZURE_OPENAI_ENDPOINT="" AZURE_OPENAI_API_KEY="" -AZURE_SEARCH_ENDPOINT="" -AZURE_SEARCH_ADMIN_KEY="" +AZURE_COGNITIVE_SEARCH_ENDPOINT="" +AZURE_COGNITIVE_SEARCH_ADMIN_KEY="" PINECONE_API_KEY="" PINECONE_ENVIRONMENT="" POSTGRES_CONNECTION_STRING="" diff --git a/python/pyproject.toml b/python/pyproject.toml index 129086ec6bbb..f8ca5bb53b33 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -45,7 +45,7 @@ psycopg-pool = "^3.1.7" psycopg = "^3.1.9" psycopg-binary = "^3.1.9" -[tool.poetry.group.azure_search.dependencies] +[tool.poetry.group.azure_cognitive_search.dependencies] azure-search-documents = {version = "11.4.0b6", allow-prereleases = true} azure-core = "^1.28.0" azure-identity = "^1.13.0" diff --git a/python/semantic_kernel/connectors/memory/azure_cognitive_search/__init__.py b/python/semantic_kernel/connectors/memory/azure_cognitive_search/__init__.py new file mode 100644 index 000000000000..8592bc7b7c43 --- /dev/null +++ b/python/semantic_kernel/connectors/memory/azure_cognitive_search/__init__.py @@ -0,0 +1,7 @@ +# Copyright (c) Microsoft. All rights reserved. + +from semantic_kernel.connectors.memory.azure_cognitive_search.azure_cognitive_search_memory_store import ( + AzureCognitiveSearchMemoryStore, +) + +__all__ = ["AzureCognitiveSearchMemoryStore"] diff --git a/python/semantic_kernel/connectors/memory/azure_search/azure_search_memory_store.py b/python/semantic_kernel/connectors/memory/azure_cognitive_search/azure_cognitive_search_memory_store.py similarity index 94% rename from python/semantic_kernel/connectors/memory/azure_search/azure_search_memory_store.py rename to python/semantic_kernel/connectors/memory/azure_cognitive_search/azure_cognitive_search_memory_store.py index fca7969c6ed2..5ce2787dae70 100644 --- a/python/semantic_kernel/connectors/memory/azure_search/azure_search_memory_store.py +++ b/python/semantic_kernel/connectors/memory/azure_cognitive_search/azure_cognitive_search_memory_store.py @@ -15,7 +15,7 @@ ) from numpy import ndarray -from semantic_kernel.connectors.memory.azure_search.utils import ( +from semantic_kernel.connectors.memory.azure_cognitive_search.utils import ( SEARCH_FIELD_EMBEDDING, SEARCH_FIELD_ID, dict_to_memory_record, @@ -30,7 +30,7 @@ from semantic_kernel.utils.null_logger import NullLogger -class AzureSearchMemoryStore(MemoryStoreBase): +class AzureCognitiveSearchMemoryStore(MemoryStoreBase): _search_index_client: SearchIndexClient = None _vector_size: int = None _logger: Logger = None @@ -44,15 +44,15 @@ def __init__( token_credentials: Optional[TokenCredential] = None, logger: Optional[Logger] = None, ) -> None: - """Initializes a new instance of the AzureSearchMemoryStore class. + """Initializes a new instance of the AzureCognitiveSearchMemoryStore class. Arguments: vector_size {int} -- Embedding vector size. - search_endpoint {Optional[str]} -- The endpoint of the Azure Search service + search_endpoint {Optional[str]} -- The endpoint of the Azure Cognitive Search service (default: {None}). - admin_key {Optional[str]} -- Azure Search API key (default: {None}). - azure_credentials {Optional[AzureKeyCredential]} -- Azure Search credentials (default: {None}). - token_credentials {Optional[TokenCredential]} -- Azure Search token credentials + admin_key {Optional[str]} -- Azure Cognitive Search API key (default: {None}). + azure_credentials {Optional[AzureKeyCredential]} -- Azure Cognitive Search credentials (default: {None}). + token_credentials {Optional[TokenCredential]} -- Azure Cognitive Search token credentials (default: {None}). logger {Optional[Logger]} -- The logger to use (default: {None}). """ @@ -60,7 +60,8 @@ def __init__( pass except ImportError: raise ValueError( - "Error: Unable to import Azure Search client python package. Please install Azure Search client" + "Error: Unable to import Azure Cognitive Search client python package." + "Please install Azure Cognitive Search client" ) self._logger = logger or NullLogger() @@ -222,7 +223,7 @@ async def upsert_async(self, collection_name: str, record: MemoryRecord) -> str: """ # Look up Search client class to see if exists or create - azure_search_client = self._search_index_client.get_search_client( + search_client = self._search_index_client.get_search_client( collection_name.lower() ) @@ -234,7 +235,7 @@ async def upsert_async(self, collection_name: str, record: MemoryRecord) -> str: search_record = memory_record_to_search_record(record) - result = await azure_search_client.upload_documents(documents=[search_record]) + result = await search_client.upload_documents(documents=[search_record]) # Throw exception if problem # Clean this up not needed if throwing @@ -258,7 +259,7 @@ async def upsert_batch_async( # Initialize search client here # Look up Search client class to see if exists or create - azure_search_client = self._search_index_client.get_search_client( + search_client = self._search_index_client.get_search_client( collection_name.lower() ) @@ -276,7 +277,7 @@ async def upsert_batch_async( search_records.append(search_record) search_ids.append(record._id) - result = azure_search_client.upload_documents(documents=search_records) + result = search_client.upload_documents(documents=search_records) if result[0].succeeded: return search_ids diff --git a/python/semantic_kernel/connectors/memory/azure_search/utils.py b/python/semantic_kernel/connectors/memory/azure_cognitive_search/utils.py similarity index 83% rename from python/semantic_kernel/connectors/memory/azure_search/utils.py rename to python/semantic_kernel/connectors/memory/azure_cognitive_search/utils.py index 2f3a127304ca..5fe9d88dedba 100644 --- a/python/semantic_kernel/connectors/memory/azure_search/utils.py +++ b/python/semantic_kernel/connectors/memory/azure_cognitive_search/utils.py @@ -30,7 +30,7 @@ def get_search_index_async_client( azure_credential: Optional[AzureKeyCredential] = None, token_credential: Optional[TokenCredential] = None, ): - """Return a client for Azure Search. + """Return a client for Azure Cognitive Search. Arguments: search_endpoint {str} -- Optional endpoint (default: {None}). @@ -39,8 +39,8 @@ def get_search_index_async_client( token_credential {TokenCredential} -- Optional Token credential (default: {None}). """ - ENV_VAR_ENDPOINT = "AZURE_SEARCH_ENDPOINT" - ENV_VAR_API_KEY = "AZURE_SEARCH_ADMIN_KEY" + ENV_VAR_ENDPOINT = "AZURE_COGNITIVE_SEARCH_ENDPOINT" + ENV_VAR_API_KEY = "AZURE_COGNITIVE_SEARCH_ADMIN_KEY" try: # Note: there are two client classes available: @@ -49,7 +49,8 @@ def get_search_index_async_client( from azure.search.documents.indexes.aio import SearchIndexClient except ImportError: raise ValueError( - "Error: Unable to import Azure Search client python package. Please install Azure Search client" + "Error: Unable to import Azure Cognitive Search client python package." + "Please install Azure Cognitive Search client" ) azure_credential: AzureKeyCredential = None @@ -64,11 +65,11 @@ def get_search_index_async_client( elif os.getenv(ENV_VAR_ENDPOINT): service_endpoint = os.getenv(ENV_VAR_ENDPOINT) else: - raise ValueError("Error: missing Azure Search client endpoint.") + raise ValueError("Error: missing Azure Cognitive Search client endpoint.") if service_endpoint is None: print(service_endpoint) - raise ValueError("Error: Azure Search client not set.") + raise ValueError("Error: Azure Cognitive Search client not set.") # Credentials if admin_key: @@ -80,10 +81,10 @@ def get_search_index_async_client( elif os.getenv(ENV_VAR_API_KEY): azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY)) else: - raise ValueError("Error: missing Azure Search client credentials.") + raise ValueError("Error: missing Azure Cognitive Search client credentials.") if azure_credential is None and token_credential is None: - raise ValueError("Error: Azure Search credentials not set.") + raise ValueError("Error: Azure Cognitive Search credentials not set.") sk_headers = {"User-Agent": "Semantic-Kernel"} @@ -97,7 +98,7 @@ def get_search_index_async_client( endpoint=service_endpoint, credential=token_credential, headers=sk_headers ) - raise ValueError("Error: unable to create Azure Search client.") + raise ValueError("Error: unable to create Azure Cognitive Search client.") def get_index_schema(vector_size: int) -> list: @@ -107,7 +108,7 @@ def get_index_schema(vector_size: int) -> list: vector_size {int} -- The size of the vectors being stored in collection/index. Returns: - list -- The Azure Search schema as list type. + list -- The Azure Cognitive Search schema as list type. """ search_fields = [ @@ -195,10 +196,10 @@ def dict_to_memory_record(data: dict, with_embeddings: bool) -> MemoryRecord: """Converts a search result to a MemoryRecord. Arguments: - data {dict} -- Azure Search result data. + data {dict} -- Azure Cognitive Search result data. Returns: - MemoryRecord -- The MemoryRecord from Azure Search Data Result. + MemoryRecord -- The MemoryRecord from Azure Cognitive Search Data Result. """ sk_result = MemoryRecord( @@ -219,7 +220,7 @@ def memory_record_to_search_record(record: MemoryRecord) -> dict: """Convert a MemoryRecord to a dictionary Arguments: - record {MemoryRecord} -- The MemoryRecord from Azure Search Data Result. + record {MemoryRecord} -- The MemoryRecord from Azure Cognitive Search Data Result. Returns: data {dict} -- Dictionary data. @@ -237,10 +238,10 @@ def memory_record_to_search_record(record: MemoryRecord) -> dict: def encode_id(id: str) -> str: - """Encode a record id to ensure compatibility with Azure search. + """Encode a record id to ensure compatibility with Azure Cognitive Search. - Azure Search keys can contain only letters, digits, underscore, dash, equal sign, - recommending to encode values with a URL-safe algorithm. + Azure Cognitive Search keys can contain only letters, digits, underscore, dash, + equal sign, recommending to encode values with a URL-safe algorithm. """ id_bytes = id.encode("ascii") @@ -251,8 +252,8 @@ def encode_id(id: str) -> str: def decode_id(base64_id: str) -> str: """Decode a record id to the original value. - Azure Search keys can contain only letters, digits, underscore, dash, equal sign, - recommending to encode values with a URL-safe algorithm. + Azure Cognitive Search keys can contain only letters, digits, underscore, dash, + equal sign, recommending to encode values with a URL-safe algorithm. """ base64_bytes = base64_id.encode("ascii") diff --git a/python/semantic_kernel/connectors/memory/azure_search/__init__.py b/python/semantic_kernel/connectors/memory/azure_search/__init__.py deleted file mode 100644 index b1aab2289a5a..000000000000 --- a/python/semantic_kernel/connectors/memory/azure_search/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) Microsoft. All rights reserved. - -from semantic_kernel.connectors.memory.azure_search.azure_search_memory_store import ( - AzureSearchMemoryStore, -) - -__all__ = ["AzureSearchMemoryStore"] diff --git a/python/tests/integration/connectors/memory/test_azure_search.py b/python/tests/integration/connectors/memory/test_azure_cognitive_search.py similarity index 86% rename from python/tests/integration/connectors/memory/test_azure_search.py rename to python/tests/integration/connectors/memory/test_azure_cognitive_search.py index bbd9bed7cda4..cb05dc189fcc 100644 --- a/python/tests/integration/connectors/memory/test_azure_search.py +++ b/python/tests/integration/connectors/memory/test_azure_cognitive_search.py @@ -6,29 +6,30 @@ import numpy as np import pytest -from semantic_kernel.connectors.memory.azure_search.azure_search_memory_store import ( - AzureSearchMemoryStore, +from semantic_kernel.connectors.memory.azure_cognitive_search.azure_cognitive_search_memory_store import ( + AzureCognitiveSearchMemoryStore, ) from semantic_kernel.memory.memory_record import MemoryRecord try: - azure_search_installed = True + azure_cognitive_search_installed = True except ImportError: - azure_search_installed = False + azure_cognitive_search_installed = False pytestmark = pytest.mark.skipif( - not azure_search_installed, reason="Azure Search is not installed" + not azure_cognitive_search_installed, + reason="Azure Cognitive Search is not installed", ) @pytest.fixture def memory_store(): - yield AzureSearchMemoryStore(vector_size=4) + yield AzureCognitiveSearchMemoryStore(vector_size=4) def test_constructor(): test_endpoint = "https://test-endpoint.search.windows.net" - memory = AzureSearchMemoryStore(test_endpoint) + memory = AzureCognitiveSearchMemoryStore(test_endpoint) assert memory._search_index_client is not None