By code, how to include AI Search results based on files data for citations using CompletionClient complete call ?

Matt B 0 Reputation points
2025-01-31T20:31:15.5166667+00:00

Hi,

Starting from the basic example provided in Azure AI SDK (https://learn.microsoft.com/en-us/azure/ai-studio/quickstarts/get-started-code?tabs=windows) based on the OpenAI gpt model I trained using files as datasources in AI Foundry, I wanted to do something similar to the Playground Chat application.

So in the complete() call I added: model_extras to:

    return chat.complete(
        model="gpt-4o-mini",
        messages=system_message + messages,
        temperature=1,
        frequency_penalty=0.5,
        presence_penalty=0.5,
        model_extras=model_extras,
    )

with models_extras defining my index in AI Search created by AI Foundry:

{
    "data_sources": [
        {
            "type": "azure_search",
            "parameters": {
                "top_n_documents": 5,
                "strictness": 3,
                "in_scope": true,
                "index_name": "my_index",
                "semantic_configuration": "azureml-default",
                "query_type": "vector_simple_hybrid",
                "endpoint": "https://myaisearch.search.windows.net",
                "authentication": {
                    "type": "api_key",
                    "key": "sonmekey"
                },
                "embedding_dependency": {
                    "type": "deployment_name",
                    "deployment_name": "text-embedding-ada-000"
                },
                "fields_mapping": {
                    "content_fields": [
                        "content"
                    ],
                    "title_field": "title",
                    "url_field": "url",
                    "filepath_field": "filepath",
                    "vector_fields": [
                        "contentVector"
                    ]
                }
            }
        }
    ]
}

but the complete calls fails with:

azure.core.exceptions.ResourceNotFoundError: Operation returned an invalid status 'Not Found'
Content: 404: Not Found

The webapp example tool seems to use the REST API directly and an extra_body field. Is model_extra different from extra_body ?

Or better, is there a python example on our to retrieve the AI Search results as citations using the complete() call ?

Thanks !

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,173 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel FANG 1,060 Reputation points MVP
    2025-02-01T11:55:31.49+00:00

    Hey. yes! you can find a python example from chat playground directly. link the chat with your ai search and then use the view code blue button from left top. you can see a very similar block under extra_body.

    User's image

    User's image


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.