Choosing Between Keyword Search, Vector Search, Keyword-Vector Hybrid Search, Semantic Search, and Keyword, Vector, Semantic Hybrid Search when doing RAG with Python SDK for Azure OpenAI

Bao, Jeremy (Cognizant) 80 Reputation points
2024-04-03T22:15:08.3466667+00:00

If you want to do RAG just with simple keyword search, you do the following, right?:

response = client.chat.completions.create(
    model = ...,
    messages = ...,
    extra_body = {
		dataSources = [
            { 
                "type": "AzureCognitiveSearch", 
                "parameters": { 
                    "endpoint": ..., 
                    "key": ..., 
                    "indexName": ...,
                }
            }
        ]
    }
)

The following is if you wish to do vector search, right? Does it do only vector search, or keyword-vector hybrid search? If it carries out one of those, how do you do the other type of search?

response = client.chat.completions.create(
    model = ...,
    messages = ...,
    extra_body = {
		dataSources = [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": ...,
                    "key": ...,
                    "indexName": ...,
                    "vectorProfile": ...,
                    "vectorField": ...
                }
            }
        ]
    }
)

How would you modify this to do semantic search and keyword, vector, and semantic hybrid search?

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

Accepted answer
  1. navba-MSFT 16,940 Reputation points Microsoft Employee
    2024-04-09T05:00:33.2133333+00:00

    @Bao, Jeremy (Cognizant) Yes, your understanding is correct. Using the requests library in Python to make API calls is a common practice and it provides you with flexibility. The query_type parameter in the data_sources array in the request_body JSON indeed allows you to specify the type of search you want to perform. The options ‘simple’, ‘semantic’, ‘vector’, ‘vectorSimpleHybrid’, and ‘vectorSemanticHybrid’ correspond to different types of searches you can perform with Azure OpenAI service.


0 additional answers

Sort by: Most helpful