Class AzureAISearchService
- Namespace
 - FoundationaLLM.Common.Services.Azure
 
- Assembly
 - FoundationaLLM.Common.dll
 
Implements the Azure AI Search Service.
public class AzureAISearchService : IAzureAISearchService
  - Inheritance
 - 
      
      AzureAISearchService
 
- Implements
 
- Inherited Members
 
- Extension Methods
 
Constructors
AzureAISearchService(SearchIndexClient, ILogger<AzureAISearchService>)
Implements the Azure AI Search Service.
public AzureAISearchService(SearchIndexClient searchIndexClient, ILogger<AzureAISearchService> logger)
  Parameters
searchIndexClientSearchIndexClientThe Azure SDK client for the Azure AI Search service.
loggerILogger<AzureAISearchService>The logger used for logging.
Methods
CreateIndexIfNotExists(string, IEnumerable<SearchField>, VectorSearch?)
Creates an index in the Azure AI Search service if it does not already exist.
public Task CreateIndexIfNotExists(string indexName, IEnumerable<SearchField> indexFields, VectorSearch? indexConfiguration = null)
  Parameters
indexNamestringThe name of the index to create.
indexFieldsIEnumerable<SearchField>The list of fields for the newly created index.
indexConfigurationVectorSearchThe optionsl vectorization configuration for the newly created index.
Returns
CreateSearchIndexClient(Dictionary<string, object>)
Creates a new instance of the SearchIndexClient class using a dictionary of parameter values.
public static SearchIndexClient CreateSearchIndexClient(Dictionary<string, object> clientParameters)
  Parameters
clientParametersDictionary<string, object>The dictionary of parameter values used to create the client instance.
Returns
- SearchIndexClient
 The requested client instance.
Exceptions
DeleteDocuments(string, string, string)
Deletes documents from the specified index in the Azure AI Search service based on a filter.
public Task<int> DeleteDocuments(string indexName, string keyFieldName, string filter)
  Parameters
indexNamestringThe name of the index from which the documents should be deleted.
keyFieldNamestringThe name of the key field for the index.
filterstringThe filter used to identify the documents to be deleted.
Returns
SearchDocuments(string, IEnumerable<string>, string, string?, ReadOnlyMemory<float>, string, float, int, bool)
Searches for documents in the specified index that match the given filter and are similar to the provided user prompt embedding.
public Task<IEnumerable<SearchDocument>> SearchDocuments(string indexName, IEnumerable<string> select, string filter, string? userPrompt, ReadOnlyMemory<float> userPromptEmbedding, string embeddingPropertyName, float similarityThreshold, int topN, bool useSemanticRanking)
  Parameters
indexNamestringThe name of the index to search within.
selectIEnumerable<string>A list of fields to select in the search results. If null or empty, all fields will be selected.
filterstringA filter expression to narrow down the search results.
userPromptstringThe original user prompt.
userPromptEmbeddingReadOnlyMemory<float>A read-only memory segment representing the embedding of the user prompt.
embeddingPropertyNamestringThe name of the index property that contains embeddings.
similarityThresholdfloatThe minimum similarity score required for a document to be included in the results. Must be a value between 0 and 1.
topNintThe maximum number of documents to return. Must be a positive integer.
useSemanticRankingboolA flag that indicates whether semantic ranking should be used or not.
Returns
- Task<IEnumerable<SearchDocument>>
 An enumerable collection of SearchDocument objects that match the filter and meet the similarity threshold, ordered by relevance. The collection will be empty if no matching documents are found.
UploadDocuments(string, List<string>, List<object[]>)
Uploads documents to the specified index in the Azure AI Search service.
public Task<Dictionary<string, bool>> UploadDocuments(string indexName, List<string> fieldNames, List<object[]> fieldValues)
  Parameters
indexNamestringThe name of the index in which the documents should be uploaded.
fieldNamesList<string>The names of the fields of the documents.
fieldValuesList<object[]>The values of the fields of the documents.
Returns
- Task<Dictionary<string, bool>>
 A dictionary that specifies for each index id value whether it was successfully uploaded or not.
Remarks
The code in this method assumes that the first field in fieldNames is the key field for the index.