skytin1004 / teach-chatgpt-to-answer

This repository is a lab for a post published on the Microsoft Tech Community blog.
0 stars 0 forks source link

Add a TIP for '$top' in the search_documents function #3

Open skytin1004 opened 7 months ago

skytin1004 commented 7 months ago

Add a tip and comment in search_documents function to this blog as shown below.

1. Add a TIP as below

TIP: In this tutorial I used 5 PDF documents as an example, so I used '$top': 3, but if you're storing a large number of documents, I would recommend increasing this value as well.

2. Add a comment as below

ex. semantic kernel version

async def search_documents(question):
    """Search documents using Azure Cognitive Search"""
    # Construct the Azure Cognitive Search service access URL
    url = (SEARCH_SERVICE_ENDPOINT + 'indexes/' +
               SEARCH_SERVICE_INDEX_NAME1 + '/docs')
    # Create a parameter dictionary
    params = {
        'api-version': SEARCH_SERVICE_API_VERSION,
        'search': question,
        'select': '*',
        '$top': 3, # '$top' means that when you search for something, only the top three documents in order of relevance to your question will be extracted from the search results.
        'queryLanguage': 'en-us',
        'queryType': 'semantic',
        'semanticConfiguration': SEARCH_SERVICE_SEMANTIC_CONFIG_NAME,
        '$count': 'true',
        'speller': 'lexicon',
        'answers': 'extractive|count-3',
        'captions': 'extractive|highlight-false'
        }
    # Make a GET request to the Azure Cognitive Search service and store the response in a variable
    resp = requests.get(url, headers=HEADERS, params=params)
    # Return the JSON response containing the search results
    return resp.json()