How can I retrieve the document citations (references) when I make an Azure OpenAI call against my own data?

Cecil (CJ) John 25 Reputation points
2024-02-03T15:09:32.1+00:00

User's image

I have an app service deployment for data that I imported into Azure Cognitive Search and integrated with Azure OpenAI. I notice in the app service (see image) that the document citations (references) are returned with the response to my prompt "what is a smart contract"? How can I retrieve these references for my documents that I indexed into Cognitive Search?

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,066 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,238 questions
0 comments No comments
{count} votes

Accepted answer
  1. ajkuma 26,721 Reputation points Microsoft Employee
    2024-02-12T08:57:41.4633333+00:00

    @Cecil (CJ) John , Following-up on this,

    The API response should contain both the assistant message and the citations list, please see an example:

    User's image

    1.The answer to my prompt

    The answer to your prompt is the "content" in the assistant message in the response.

    1. The inline citations to my indexed documents

    The inline citations are what the model generates as [doc1], [doc2], etc. These refer to the citations in the "tool" content, e.g. [doc1] refers to the first citation in the citations list.

    1. The links to the citations as references?**

    The client/UI can use these two components to render the inline citations, as in the sample code ( shared in my earlier response). The UI would look in the assistant message for [doc1], and replace these with inline pointers to the cited content from the citations list.


    please click Accept Answer - it will benefit the community/users to find the answer quickly.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. ajkuma 26,721 Reputation points Microsoft Employee
    2024-02-07T03:21:12.59+00:00

    @Cecil (CJ) John, To better assist you on this, kindly share more about your scenario and what you are attempting to accomplish? Just to clarify, do you mean how you can parse this info from the API response yourself?

      Kindly checkout these info for the approaches:

    --
    If the answer helped (pointed, you in the right direction) > please click Accept Answer Or please share the requested/more info to help you better.


  2. Cecil (CJ) John 25 Reputation points
    2024-02-08T14:10:48.6533333+00:00

    Hello,

    Thanks for your response. Please see my API call and the API Body request below. I have attached the response as a file. I only wish to get back the answer to my question, the follow up questions and particularly the citations ONLY for my indexed documents that are relevant to the response. I see the tool: property in my response, but not the doc references you allude to. I am also getting back the entire document which I do not need for performance reasons. I do see the cited documents being returned as a filepath.

    So how do I get just:

    1. The answer to my prompt
    2. The inline citations to my indexed documents
    3. The links to the citations as references?**

    API CALL** https://openaidevnewintellectual.openai.azure.com/openai/deployments/depoaidevnewintellectual/extensions/chat/completions?api-version=2023-08-01-preview&Content-Type=application/json API REQUEST BODY

    {
        
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": "https://csdevnewintellectual.search.windows.net",
                    "key": "hgpY8K5SN1gUK6age6fLO1ka4QCA5Kmy4EMytVdO6zAzSeB4oTWu",
                    "indexName": "pdfsazureblob-index01",
                    "semanticConfiguration": "default",
                    "queryType": "simple",
                    "fieldsMapping": {
                        "contentFields": [
                            // "ChapterID",
                            //"BookTitle",
                            //Title"
                            //"ChapterID",
                            //"Body",
                            //"Summary",
                            //"Thumbnail",
                            //"URL"
                    
                        ],
                        "contentFieldsSeparator": "|||"
                    }
                }
            }
        ],
        "inScope": true,
        "roleInformation": "You are an AI assistant that helps people find information.",
        "filter": null,
        "embeddingEndpoint": null,
        "embeddingKey": null,
        "strictness": 3,
        "topNDocuments": 5,
        "queryType":"simple",
        "messages": [
            {
                "role": "user",
                "content": "what is a smart contract? Please give me a bulleted list of 5 follow up questions to your response, and precede with the words 'follow up questions' as a heading."
            }
        ],
        "deployment": "depoaidevnewintellectual",
        "temperature": 0,
        "top_p": 1,
        "max_tokens": 300,
        "stop": null,
        "stream": false
    }
    

  3. Cecil (CJ) John 25 Reputation points
    2024-02-14T19:31:03.7533333+00:00

    Hello, as per the response I provided above, the problem is that I am NOT getting the citations returned in the [doc] format you refer to. Can you please take a look at my API request and reponse? Perhaps I am missing something in the request?

    Thank you.


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.