Use of multiple azure cognitive search indexes fir openai chat completion

Sanskar Singh 20 Reputation points
2024-02-29T15:03:10.9066667+00:00

Question: Currently, when using the 'getChatCompletionsfeature provided by the@azure/openai` package, you can specify a single Azure Cognitive Search index as follows. "js const response = await client.getChatCompletions(deploymentid, messages, { azureExtensionOptions: { extensions: [ { type: 'AzureCognitiveSearch', endpoint. searchEndpoint, key: searchKey, indexName: searchIndex, }, }, However, I would like to be able to specify multiple indexes here. The reason is that currently there are multiple search indexes available, and I would like to dynamically decide which search index to use. It is not practical to create search indexes for all combinations in advance, so I want to be able to specify the necessary search indexes (multiple) each time. In summary, my questions are

  • Is there a way to call multiple Azure Cognitive Search indexes?
  • There are other types of data sources (e.g. Azure Cosmos DB, Elasticsearch, Pinecone), then can we do something similar? https://learn.microsoft.com/en-us/azure/ai- services/openai/references/azure-search?tabs=python * @azure/openai package does not support multiple 'AzureCognitiveSearch' in AzureExtensionOptions, which is used for chatCompletion request. * I want to better understand how is the request to Azure Cognitive Search. Can you point out the code lines in @azure/openai package where t request to Azure Cognitive Search is created while processing the chatCompletionRequest?
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,339 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2024-03-05T00:06:38.74+00:00

    Hi @Sanskar Singh the short answer to your question is, no.

    Currently the @azure/openai package does not support specifying multiple Azure Cognitive Search indexes in the AzureExtensionOptions for a getChatCompletions request. You can only specify one index per request. This means you cannot send a single request that searches across multiple indexes simultaneously regardless of data sources.

    You learn about combining search results from multiple Azure Cognitive Search indexes using search filters in this Azure doc.

    However, there are alternative approaches to achieve your desired functionality:

    1. Combine Search Results:
    • Search each index individually: Use separate getChatCompletions calls for each relevant search index, specifying the desired index in each call.
    • Combine results: In your application logic, combine the results from each search by filtering and merging relevant responses based on your criteria.
    1. Pre-process Search Terms:
    • Dynamically select index: Based on the user query or context, identify the most appropriate search index. This could involve keyword analysis, user selection, or rule-based decision making.
    • Use single index search: Perform a single getChatCompletions call with the chosen index and the modified user query.
    1. Custom Azure OpenAI Implementation:
    • Develop custom logic: If the above options don't meet your needs, consider creating a custom implementation using the lower-level API provided by the @azure/openai package.
    • Directly interact with OpenAI API: Utilize the OpenAI API directly, allowing more control over the request structure. This approach would require deeper knowledge of the OpenAI API and managing authentication and authorization.

    Hope that helps.

    -Grace


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.