Enable answer synthesis in Foundry IQ (Azure AI Search)

Note

Foundry IQ (Azure AI Search) provides direct indexing and query APIs alongside higher-level knowledge source and knowledge base APIs for managed retrieval. Use the Azure portal, REST APIs, or Azure SDKs to configure these capabilities, or connect agents to knowledge bases in the Microsoft Foundry portal.

By default, a knowledge base in Foundry IQ (Azure AI Search) performs data extraction, returning grounding content from your knowledge sources without generating an answer.

You can instead enable answer synthesis, which uses the LLM configured in your knowledge base to generate a natural-language answer. You can provide answer instructions to shape the response, such as requesting a bulleted list. References provide the source IDs used for citations.

You can set the output mode in a knowledge base or a retrieve request. The knowledge base setting establishes the default for all queries, while the retrieve request setting overrides the default on a query-by-query basis.

Usage support

Azure portal Microsoft Foundry portal .NET SDK Python SDK Java SDK JavaScript SDK REST API
✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

Prerequisites

  • A Foundry IQ service with a knowledge base that specifies an LLM.

  • Permission to update knowledge bases. Configure keyless authentication with the Search Service Contributor role assigned to your user account (recommended) or use an admin API key.

  • For outbound calls to the LLM, the Foundry IQ service must have a managed identity with Cognitive Services User permissions on the Microsoft Foundry resource.

  • The latest Azure.Search.Documents preview package: dotnet add package Azure.Search.Documents --prerelease

  • For keyless authentication, the Azure.Identity package: dotnet add package Azure.Identity

  • The 2026-10-01 or later Search REST API. The examples use 2026-11-01-preview.

  • For keyless authentication, include a Microsoft Entra ID token in the Authorization header of each HTTP request.

Limitations and considerations

  • Ordinary minimal effort bypasses model-based query planning, not answer synthesis. Synthesis separately requires a configured model, including with minimal. For more information, see Set the retrieval reasoning effort.

  • Answer synthesis incurs pay-as-you-go charges from Azure OpenAI, which are based on the number of input and output tokens. Charges appear under the LLM assigned to the knowledge base. For more information, see Region availability, limits, and billing.

Enable answer synthesis in a knowledge base

To route a knowledge base retrieval model through Azure API Management (APIM), use an OpenAI-compatible model configuration with REST API 2026-11-01-preview.

Enable answer synthesis in an existing knowledge base. For knowledge base creation, see Create a knowledge base.

Set OutputMode to "answerSynthesis" on the KnowledgeBase definition. Optionally, set AnswerInstructions to customize the answer output. The following example instructs the knowledge base to Use concise bulleted lists.

var indexClient = new SearchIndexClient(
    new Uri(searchEndpoint), credential);

var aoaiParams = new AzureOpenAIVectorizerParameters
{
    ResourceUri = new Uri("<aoai-endpoint>"),
    DeploymentName = "<aoai-gpt-deployment>",
    ModelName = "<aoai-gpt-model>",
};

var knowledgeBase = new KnowledgeBase(
    name: "<knowledge-base-name>",
    knowledgeSources: new[] { new KnowledgeSourceReference("<knowledge-source-name>") })
{
    Models = { new KnowledgeBaseAzureOpenAIModel(aoaiParams) },
    OutputMode = "answerSynthesis",
    AnswerInstructions = "Use concise bulleted lists",
};

await indexClient.CreateOrUpdateKnowledgeBaseAsync(knowledgeBase);

Reference: SearchIndexClient, KnowledgeBase

Set output_mode to "answerSynthesis" on the KnowledgeBase definition. Optionally, set answer_instructions to customize the answer output. The following example instructs the knowledge base to Use concise bulleted lists.

from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    AzureOpenAIVectorizerParameters,
    KnowledgeBase,
    KnowledgeBaseAzureOpenAIModel,
    KnowledgeSourceReference,
)

aoai_params = AzureOpenAIVectorizerParameters(
    resource_url="<aoai-endpoint>",
    deployment_name="<aoai-gpt-deployment>",
    model_name="<aoai-gpt-model>",
)

knowledge_base = KnowledgeBase(
    name="<knowledge-base-name>",
    models=[KnowledgeBaseAzureOpenAIModel(azure_open_ai_parameters=aoai_params)],
    knowledge_sources=[KnowledgeSourceReference(name="<knowledge-source-name>")],
    output_mode="answerSynthesis",
    answer_instructions="Use concise bulleted lists",
)

index_client = SearchIndexClient(
    endpoint=search_endpoint,
    credential=credential,
)
index_client.create_or_update_knowledge_base(knowledge_base)

Reference: SearchIndexClient, KnowledgeBase

Set outputMode to "answerSynthesis" on the knowledge base definition. Optionally, set answerInstructions to customize the answer output. The following example instructs the knowledge base to Use concise bulleted lists.

If the knowledge base defines named tools, include its existing tools array in the update.

### Enable answer synthesis in a knowledge base
PUT {{search-endpoint}}/knowledgebases/{{knowledge-base-name}}?api-version=2026-11-01-preview
Content-Type: application/json
Authorization: Bearer {{search-access-token}}

{
    "name": "{{knowledge-base-name}}",
    "knowledgeSources": [ ... // OMITTED FOR BREVITY ],
    "models": [ ... // OMITTED FOR BREVITY ],
    "outputMode": "answerSynthesis",
    "answerInstructions": "Use concise bulleted lists"
}

Reference: Knowledge Base - Create or Update

Enable answer synthesis in a retrieve request

For per-query control over the response format, you can enable answer synthesis at query time. This approach overrides the default output mode specified in the knowledge base.

Use answer synthesis with REST

Use an existing knowledge base whose models array contains a supported model, a populated search index knowledge source, and credentials authorized to retrieve content. If the knowledge base uses Azure OpenAI, configure access.

POST {{search-endpoint}}/knowledgebases/{{knowledge-base-name}}/retrieve?api-version=2026-11-01-preview
Content-Type: application/json
Authorization: Bearer {{search-token}}

{
  "intents": [
    {
      "type": "semantic",
      "search": "What is the return policy?"
    }
  ],
  "retrievalReasoningEffort": {
    "kind": "minimal"
  },
  "outputMode": "answerSynthesis",
  "includeActivity": true
}

Reference: Knowledge Retrieval - Retrieve

Inspect the response messages, references, and separate modelAnswerSynthesis activity. For model-backed query planning, choose low or medium instead. Supply either messages or intents, not both.

Additional examples

The following examples show equivalent SDK and message-based REST requests.

Set OutputMode to "answerSynthesis" on a KnowledgeBaseRetrievalRequest.

var client = new KnowledgeBaseRetrievalClient(
    endpoint: new Uri(searchEndpoint),
    knowledgeBaseName: knowledgeBaseName,
    credential: credential);

var request = new KnowledgeBaseRetrievalRequest
{
    RetrievalReasoningEffort = new KnowledgeRetrievalLowReasoningEffort()
};
request.Messages.Add(
    new KnowledgeBaseMessage(
        content: new[]
        {
            new KnowledgeBaseMessageTextContent("What is healthcare?")
        }) { Role = "user" });
request.OutputMode = "answerSynthesis";

var result = await client.RetrieveAsync(request);

Reference: KnowledgeBaseRetrievalClient, KnowledgeBaseRetrievalRequest

Set output_mode to "answerSynthesis" on a KnowledgeBaseRetrievalRequest.

from azure.search.documents.knowledgebases import KnowledgeBaseRetrievalClient
from azure.search.documents.knowledgebases.models import (
    KnowledgeBaseMessage,
    KnowledgeBaseMessageTextContent,
    KnowledgeBaseRetrievalRequest,
    KnowledgeRetrievalLowReasoningEffort,
)

agent_client = KnowledgeBaseRetrievalClient(
    endpoint=search_endpoint,
    credential=credential,
    knowledge_base_name=knowledge_base_name,
)

request = KnowledgeBaseRetrievalRequest(
    messages=[
        KnowledgeBaseMessage(
            role="user",
            content=[KnowledgeBaseMessageTextContent(text="What is healthcare?")],
        )
    ],
    retrieval_reasoning_effort=KnowledgeRetrievalLowReasoningEffort(),
    output_mode="answerSynthesis",
)

result = agent_client.retrieve(retrieval_request=request)

Reference: KnowledgeBaseRetrievalClient, KnowledgeBaseRetrievalRequest

Set outputMode to "answerSynthesis" on a retrieve request.

### Enable answer synthesis in a retrieve request
POST {{search-endpoint}}/knowledgebases/{{knowledge-base-name}}/retrieve?api-version=2026-11-01-preview
Content-Type: application/json
Authorization: Bearer {{search-access-token}}

{
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What is healthcare?"
                }
            ]
        }
    ],
    "retrievalReasoningEffort": {
        "kind": "low"
    },
    "outputMode": "answerSynthesis"
}

Reference: Knowledge Retrieval - Retrieve

Get a synthesized answer

When answer synthesis is enabled, the knowledge base returns a natural-language answer based on the instructions you optionally specified in the knowledge base. Citations to your knowledge sources are formatted as [ref_id:<number>].

For example, if your instructions are Use concise bulleted lists and your query is What is healthcare?, the response should be similar to the following example.

{
  "response": [
    {
      "content": [
        {
          "type": "text",
          "text": "- Healthcare encompasses various services provided to patients and the general population ..."
        }
      ]
    }
  ]
}

The full text output is as follows:

"- Healthcare encompasses various services provided to patients and the general population, including primary health services, hospital care, dental care, mental health services, and alternative health services [ref_id:1].\n- It involves the delivery of safe, effective, patient-centered care through different modalities, such as in-person encounters, shared medical appointments, and group education sessions [ref_id:0].\n- Behavioral health is a significant aspect of healthcare, focusing on the connection between behavior and overall health, including mental health and substance use [ref_id:2].\n- The healthcare system aims to ensure quality of care, access to providers, and accountability for positive outcomes while managing costs effectively [ref_id:2].\n- The global health system is evolving to address complex health needs, emphasizing the importance of cross-sectoral collaboration and addressing social determinants of health [ref_id:4]."

Depending on your knowledge base's configuration, the response might include other information, such as activity logs and reference arrays. For more information, see Create a knowledge base.