Azure OpenAI & On your data API calling

uehara ryo 0 Reputation points
2023-09-26T10:07:35.72+00:00

Question: Could you please explain the root cause and offer solutions for the following issue?

Issue: When calling Azure OpenAI and Cognitive Search via API, if I input a prompt that does not specify document searching, I always get the output

"The requested information is not found in the retrieved data. Please try another query or topic."

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,106 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,851 Reputation points Microsoft Employee Moderator
    2023-09-28T21:33:03.51+00:00

    Hi uehara ryo,

    Which model you are trying to use? Can you please share the code which you are using to make call while interacting with Azure cognitive search.

    I have tested this with GPT 3.5 Turbo 0301 model and it behaves fine when I pass "Hi" to chat completion endpoint. Here is the python code which I have used -

    import openai, os, requests
    
    openai.api_type = "azure"
    
    # Azure OpenAI on your own data is only supported by the 2023-08-01-preview API version
    openai.api_version = "2023-08-01-preview"
    
    # Azure OpenAI setup
    openai.api_base = "https://{openai}.openai.azure.com/" # Add your endpoint here
    openai.api_key = os.getenv("AOAIKey") # Add your OpenAI API key here
    deployment_id = "gpt35turbo" # Add your deployment ID here
    
    # Azure Cognitive Search setup
    search_endpoint = "https://{conginitivesearch}.search.windows.net"; # Add your Azure Cognitive Search endpoint here
    search_key = "{searchkey}"; # Add your Azure Cognitive Search admin key here
    search_index_name = "azureblob-index"; # Add your Azure Cognitive Search index name here
    
    def setup_byod(deployment_id: str) -> None:
        """Sets up the OpenAI Python SDK to use your own data for the chat endpoint.
    
        :param deployment_id: The deployment ID for the model to use with your own data.
    
        To remove this configuration, simply set openai.requestssession to None.
        """
    
        class BringYourOwnDataAdapter(requests.adapters.HTTPAdapter):
    
            def send(self, request, **kwargs):
                request.url = f"{openai.api_base}/openai/deployments/{deployment_id}/extensions/chat/completions?api-version={openai.api_version}"
                return super().send(request, **kwargs)
    
        session = requests.Session()
    
        # Mount a custom adapter which will use the extensions endpoint for any call using the given `deployment_id`
        session.mount(
            prefix=f"{openai.api_base}/openai/deployments/{deployment_id}",
            adapter=BringYourOwnDataAdapter()
        )
    
        openai.requestssession = session
    
    setup_byod(deployment_id)
    
    completion = openai.ChatCompletion.create(
        messages=[{"role": "user", "content": "Hi"}],
        deployment_id=deployment_id,
        dataSources=[  # camelCase is intentional, as this is the format the API expects
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": search_endpoint,
                    "key": search_key,
                    "indexName": search_index_name,
                }
            }
        ]
    )
    print(completion)
    

    Output:

    User's image

    Also, I ask a question from the document, it gives the answer if available in the documentation. See example below-

    User's image

    I took this code from the Chat Playground, after setting up Azure Blob Storage with an Azure Search.

    Additionally, if you want to enforce the model to look for your data only, then you need to Check - "Limit responses to your data content".

    User's image

    You can achieve the same in API call by setting up the inScope to true. See below code snippet-

    completion = openai.ChatCompletion.create(
        messages=[{"role": "user", "content": "what is the population of USA?"}],
        deployment_id=deployment_id,
        dataSources=[  # camelCase is intentional, as this is the format the API expects
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": search_endpoint,
                    "key": search_key,
                    "indexName": search_index_name,
                    "inScope": true
                }
            }
        ]
    )
    

    Please refer to the documentation - Using your data(Preview) for details.
    Please let me know if you have any other questions.

    Thanks

    Saurabh

    2 people found this answer helpful.

  2. Tech-Hyd-1989 5,816 Reputation points
    2023-09-26T10:15:18.94+00:00

    Hello uehara ryo

    There are a few possible reasons why you are always getting the output "The requested information is not found in the retrieved data. Please try another query or topic." when calling Azure OpenAI and Cognitive Search via API, if you input a prompt that does not specify document searching:

    • The prompt is too broad. If the prompt is too broad, Azure OpenAI and Cognitive Search may not be able to find any relevant documents or information. Try to make the prompt more specific.
    • The prompt is not specific to Azure Cognitive Search. Azure Cognitive Search is a search engine for documents. If the prompt is not specific to Azure Cognitive Search, Azure OpenAI and Cognitive Search may not be able to find any relevant documents or information.
    • The prompt is not asking a question. Azure OpenAI and Cognitive Search are better at answering questions than generating text. If the prompt is not asking a question, Azure OpenAI and Cognitive Search may not be able to generate any relevant text.

    Here are some tips for writing prompts that are more likely to generate relevant results from Azure OpenAI and Cognitive Search:

    • Be specific. The more specific the prompt, the more likely Azure OpenAI and Cognitive Search are to find relevant documents or information.
    • Use keywords. Azure OpenAI and Cognitive Search use keywords to find relevant documents and information. Try to include relevant keywords in the prompt.
    • Ask a question. Azure OpenAI and Cognitive Search are better at answering questions than generating text. Try to write the prompt in the form of a question.
    • Use context. If you can provide context for the prompt, Azure OpenAI and Cognitive Search are more likely to generate relevant results. For example, you could provide the URL of a document that is relevant to the prompt.

    Here are some examples of prompts that are more likely to generate relevant results from Azure OpenAI and Cognitive Search:

    • What are the benefits of using Azure Cognitive Search?
    • How do I use Azure Cognitive Search to index my documents?
    • How do I use Azure Cognitive Search to search for documents?
    • What are the different types of Azure Cognitive Search queries?
    • How do I use Azure Cognitive Search to filter and sort my search results?

    I hope this helps!


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.