Share via


Knowledge Retrieval - Retrieve

KnowledgeAgent retrieves relevant data from backing stores.

POST {endpoint}/agents('{agentName}')/retrieve?api-version=2025-05-01-preview

URI Parameters

Name In Required Type Description
agentName
path True

string

The name of the agent.

endpoint
path True

string (url)

The endpoint URL of the search service.

api-version
query True

string

Client Api Version.

Request Header

Name Required Type Description
x-ms-client-request-id

string (uuid)

The tracking ID sent with the request to help with debugging.

x-ms-query-source-authorization

string

Token identifying the user for which the query is being executed. This token is used to enforce security restrictions on documents.

Request Body

Name Required Type Description
messages True

KnowledgeAgentMessage[]

The natural language message style object.

targetIndexParams

KnowledgeAgentIndexParams[]

Responses

Name Type Description
200 OK

KnowledgeAgentRetrievalResponse

The retrieval response is successfully returned.

Other Status Codes

ErrorResponse

Error response.

Examples

KnowledgeAgentRetrieve

Sample request

POST https://previewexampleservice.search.windows.net/agents('agent-preview-test')/retrieve?api-version=2025-05-01-preview



{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "text": "hello world",
          "type": "text"
        }
      ]
    }
  ],
  "targetIndexParams": [
    {
      "indexName": "preview-test",
      "filterAddOn": "foo eq bar",
      "maxDocsForReranker": 100,
      "rerankerThreshold": 2.5,
      "includeReferenceSourceData": true
    }
  ]
}

Sample response

{
  "response": [
    {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "[{...}]"
        }
      ]
    }
  ],
  "activity": [
    {
      "type": "ModelQueryPlanning",
      "id": 0,
      "inputTokens": 11,
      "outputTokens": 22
    },
    {
      "type": "AzureSearchQuery",
      "id": 1,
      "targetIndex": "preview-test",
      "query": {
        "search": "hello world",
        "filter": "foo eq bar"
      },
      "queryTime": "2025-01-01T00:08:45.045Z",
      "count": 2,
      "elapsedMs": 1234
    },
    {
      "type": "AzureSearchQuery",
      "id": 2,
      "targetIndex": "preview-test",
      "query": {
        "search": "hello world two",
        "filter": "foo eq bar"
      },
      "queryTime": "2025-01-01T00:08:45.045Z",
      "count": 2,
      "elapsedMs": 1234
    },
    {
      "type": "AzureSearchSemanticRanker",
      "id": 3,
      "inputTokens": 74
    }
  ],
  "references": [
    {
      "type": "AzureSearchDoc",
      "id": "83dd7d40",
      "activitySource": 1,
      "docKey": "myDocKey1",
      "sourceData": {
        "id": "myDocKey1",
        "title": "high_doc",
        "content": "hello world"
      }
    },
    {
      "type": "AzureSearchDoc",
      "id": "83dd7d41",
      "activitySource": 1,
      "docKey": "myDocKey2",
      "sourceData": {
        "id": "myDocKey2",
        "title": "low_doc",
        "content": "goodbye world"
      }
    }
  ]
}

Definitions

Name Description
ErrorAdditionalInfo

The resource management error additional info.

ErrorDetail

The error detail.

ErrorResponse

Error response

Image
KnowledgeAgentAzureSearchDocReference

Represents an Azure Search document reference.

KnowledgeAgentIndexParams
KnowledgeAgentMessage

The natural language message style object.

KnowledgeAgentMessageContentType

The type of message content.

KnowledgeAgentMessageImageContent

Text message type.

KnowledgeAgentMessageTextContent

Text message type.

KnowledgeAgentModelQueryPlanningActivityRecord

Represents an LLM query planning activity record.

KnowledgeAgentRetrievalRequest

The input contract for the retrieval request.

KnowledgeAgentRetrievalResponse

The output contract for the retrieval response.

KnowledgeAgentSearchActivityRecord

Represents a retrieval activity record.

KnowledgeAgentSemanticRankerActivityRecord

Represents a semantic ranker activity record.

Query

The query details for the retrieval activity.

ErrorAdditionalInfo

The resource management error additional info.

Name Type Description
info

object

The additional info.

type

string

The additional info type.

ErrorDetail

The error detail.

Name Type Description
additionalInfo

ErrorAdditionalInfo[]

The error additional info.

code

string

The error code.

details

ErrorDetail[]

The error details.

message

string

The error message.

target

string

The error target.

ErrorResponse

Error response

Name Type Description
error

ErrorDetail

The error object.

Image

Name Type Description
url

string

The url of the image.

KnowledgeAgentAzureSearchDocReference

Represents an Azure Search document reference.

Name Type Description
activitySource

integer (int32)

The source activity ID for the reference.

docKey

string

The document key for the reference.

id

string

The ID of the reference.

sourceData

object

type string:

AzureSearchDoc

The type of the reference.

KnowledgeAgentIndexParams

Name Type Description
filterAddOn

string

A filter condition applied to the index (e.g., 'State eq VA').

includeReferenceSourceData

boolean

Indicates whether reference source data should be included.

indexName

string

The name of the index the params apply to.

maxDocsForReranker

integer (int32)

Limits the number of documents considered for ranking.

rerankerThreshold

number (float)

minimum: 0
maximum: 4

A threshold for reranking results (range: 0-4).

KnowledgeAgentMessage

The natural language message style object.

Name Type Description
content KnowledgeAgentMessageContent[]:

Specifies the type of the message content.

role

string

The role of the tool response.

KnowledgeAgentMessageContentType

The type of message content.

Value Description
text

Text message content kind.

image

Image message content kind.

KnowledgeAgentMessageImageContent

Text message type.

Name Type Description
image

Image

type string:

image

The type of the message

KnowledgeAgentMessageTextContent

Text message type.

Name Type Description
text

string

type string:

text

The type of the message

KnowledgeAgentModelQueryPlanningActivityRecord

Represents an LLM query planning activity record.

Name Type Description
elapsedMs

integer (int32)

The elapsed time in milliseconds for the model activity.

id

integer (int32)

The ID of the activity record.

inputTokens

integer (int32)

The number of input tokens for the LLM query planning activity.

outputTokens

integer (int32)

The number of output tokens for the LLM query planning activity.

type string:

ModelQueryPlanning

The type of the activity record.

KnowledgeAgentRetrievalRequest

The input contract for the retrieval request.

Name Type Description
messages

KnowledgeAgentMessage[]

The natural language message style object.

targetIndexParams

KnowledgeAgentIndexParams[]

KnowledgeAgentRetrievalResponse

The output contract for the retrieval response.

Name Type Description
activity KnowledgeAgentActivityRecord[]:

The activity records for tracking progress and billing implications.

references KnowledgeAgentReference[]:

KnowledgeAgentAzureSearchDocReference[]

The references for the retrieval data used in the response.

response

KnowledgeAgentMessage[]

The natural language message style object.

KnowledgeAgentSearchActivityRecord

Represents a retrieval activity record.

Name Type Description
count

integer (int32)

The count of documents retrieved.

elapsedMs

integer (int32)

The elapsed time in milliseconds for the retrieval activity.

id

integer (int32)

The ID of the activity record.

query

Query

The query details for the retrieval activity.

queryTime

string (date-time)

The query time for this retrieval activity.

targetIndex

string

The target index for the retrieval activity.

type string:

AzureSearchQuery

The type of the activity record.

KnowledgeAgentSemanticRankerActivityRecord

Represents a semantic ranker activity record.

Name Type Description
elapsedMs

integer (int32)

The elapsed time in milliseconds for the model activity.

id

integer (int32)

The ID of the activity record.

inputTokens

integer (int32)

The number of input tokens for the semantic ranker activity.

type string:

AzureSearchSemanticRanker

The type of the activity record.

Query

The query details for the retrieval activity.

Name Type Description
filter

string

The filter string.

search

string

The search string.