Azure OpenAI similarity search

Alex Castillo 0 Reputation points
2023-05-25T21:19:27.9666667+00:00

Using Azure OpenAI, how I can make similarity searches?

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

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 48,506 Reputation points
    2023-05-26T00:59:29.8966667+00:00

    Hello @Alex Castillo

    Thanks for reaching out to us again, sorry, we have not heard from you. Just want to add more information for my answer -

    Azure OpenAI provides a number of APIs and services that can be used for similarity search. One of the most commonly used services for similarity search is the OpenAI GPT-3 API, which provides natural language processing capabilities that can be used to find similar text.

    Here are the general steps to perform similarity search using the OpenAI GPT-3 API:

    Create an Azure OpenAI resource: To use the OpenAI GPT-3 API, you will need to create an Azure OpenAI resource in the Azure portal.

    Authenticate with the API: Once you have created an Azure OpenAI resource, you can authenticate with the API using an API key.

    Send a request to the API: To perform similarity search, you can send a request to the OpenAI GPT-3 API with a piece of text that you want to find similar text for. The API will return a list of similar text based on the input text.

    Process the response: Once you receive the response from the API, you can process the results to extract the similar text.

    Here is an example of how to use the OpenAI GPT-3 API for similarity search in Python:

    import os 
    import requests 
    import json 
    import openai
    
    openai.api_key = os.getenv("AZURE_OPENAI_KEY") 
    openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") 
    openai.api_type = 'azure' 
    openai.api_version = '2023-05-15' # this may change in the future
    
    # Send a completion call to generate an answer 
    print('Sending a test completion job') 
    start_phrase = 'Find similar text to' + '{What you want to input}'
    response = openai.Completion.create(engine=deployment_name, prompt=start_phrase, max_tokens=10) 
    text = response['choices'][0]['text'].replace('\n', '').replace(' .', '.').strip() 
    print(start_phrase+text)
    
    
    
    

    I hope this helps, please let me know if you need more information.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

    1 person found this answer helpful.
    0 comments No comments