Issues with Empty Response in Azure AI Search Agentic Retrieval

Brent Kauffman 0 Reputation points
2025-05-25T00:16:32.4933333+00:00

Following the quickstart guide for Agentic retrieval in Azure AI Search: Quickstart Guide, an issue arises when retrieving the results.The line of code:

(retrievalResult.Value.Response[0].Content[0] as KnowledgeAgentMessageTextContent).Text

returns an empty array []. Assistance is needed to determine the cause of the empty response.

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,350 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JAYA SHANKAR G S 3,960 Reputation points Microsoft External Staff Moderator
    2025-05-28T10:09:53.4466667+00:00

    Hello @Brent Kauffman ,

    You have to give a user query that gives at least single document from index. If you give more generalized query, analysis query or size of document related you won't get the results.

    For hotels sample index i gave below kind of query

    messages.Add(new Dictionary<string, string>
    {
        { "role", "user" },
        { "content", @"
    Give me hotel name having parking spaces." }
    });
    

    and it gave set of documents and upon making chat completion call passing those documents got the successful output.

    Alter Chat completion code like below.

    messages.Add(new Dictionary<string, string>
    {
        { "role", "assistant" },
        { "content", (retrievalResult.Value.Response[0].Content[0] as KnowledgeAgentMessageTextContent).Text }
    });
    
    List<ChatMessage> chatMessages = messages
        .Select<Dictionary<string, string>, ChatMessage>(m => m["role"] switch
        {
            "user" => new UserChatMessage(m["content"]),
            "assistant" => new AssistantChatMessage(m["content"]),
            "system" => new SystemChatMessage(m["content"]),
            _ => null
        })
        .Where(m => m != null)
        .ToList();
    
    
    var result = await chatClient.CompleteChatAsync(chatMessages);
    
    Console.WriteLine($"[ASSISTANT]: {result.Value.Content[0].Text.Replace(".", "\n")}");
    

    User's image

    And as per instruction it gives below output when there is empty results from agent upon making chat completion call with that agent's message.

    User's image

    In your case if it's empty then there are no results from index for your query, so try giving query like some keywords it should match in search index.

    If you could provide the queries and data, you trying it will help us to make further investigation or do let us know if you have any questions in comments

    Thank you


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.