Azure-Samples / azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
https://azure.microsoft.com/products/search
MIT License
6.05k stars 4.14k forks source link

403 Forbidden when ai search and azure openai public networking is disabled #1886

Open GijsVoogd opened 2 months ago

GijsVoogd commented 2 months ago

Question regarding Azure OpenAI using RAG on our own data via AI Search.

Our setup is as follows:

AI Search:

Azure OpenAI:

The issue we’re facing is that it is calling Azure OpenAI and from Azure OpenAI, AI Search is called. This gives a 403 which seems to make sense since AI Search public network is disabled and we cannot integrate Azure OpenAI in the VNET. Shared private access is not an option on Azure OpenAI.

It works when we enable public access on AI Search but we have a requirement for private access only. Is there a way to make this work without enabling public access?

{

"error": {

"requestid": "xxx",

"code": 400,

"message": "Invalid AzureCognitiveSearch configuration detected: Call to get Azure Search index failed. Check if you are using the correct Azure Search endpoint and index name. If you are using key based authentication, check if the admin key is correct. If you are using access token authentication or managed identity of Azure OpenAI, check if the Azure Search has enabled RBAC based authentication and if the user identity or Azure OpenAI managed identity has required role assignments to access Azure Search resource [https://aka.ms/aoaioydauthentication]. If the Azure Search resource has no public network access, make sure enable trusted service of Azure Search.\nAzure Search Error: 403, message\u003d\u0027Server responded with status 403.

pamelafox commented 2 months ago

Hm, is this an issue you're encountering with this repository, or when using the Azure OpenAI on your Data feature?

GijsVoogd commented 2 months ago

@pamelafox I am using this repo but this issue, i think, is not related to it. Looks like it is more related to azure components. Having this would be a great addition to the productionizing part of the repo

amddaa commented 1 month ago

@GijsVoogd Any update on that? I'm facing similar issue using api_key to authenticate (system_assigned_managed_identity works fine).

GijsVoogd commented 1 month ago

@amddaa I also switched to MI authentication which is the preferred way anyways. Never got the key authentication working

sebastus commented 3 weeks ago

I have this exact issue in a python program. I'm not using this repo. I'm using the AzureOpenAI import from pypi openai.

chat_completion = openai_client.chat.completions.create(
    model=deployment,
    messages=chat_history,
    max_tokens=800,
    temperature=0.7,
    top_p=0.95,
    frequency_penalty=0,
    presence_penalty=0,
    stop=None,
    stream=False,
    extra_body={
        "data_sources": [
            {
                "type": "azure_search",
                "parameters": {
                    "endpoint": f"{azure_search_endpoint}",
                    "index_name": azure_search_index_name,
                    "semantic_configuration": "default",
                    "query_type": "simple",
                    "fields_mapping": {},
                    "in_scope": True,
                    "role_information": "some stuff",
                    "filter": None,
                    "strictness": 3,
                    "top_n_documents": 5,
                    "authentication": {
                        "type": "api_key",
                        "key": f"{azure_search_admin_key}"
                    }
                }                
            }
        ]
    }
)

I delete my environment nightly and rebuild it in the morning. Yesterday, it all worked correctly. But all other days (about 2 weeks worth?) this fails. I have private endpoints on both openai and ai search. Public access is enabled for openai at the moment, but public access is disabled for ai search.