Introduction
The Copilot Retrieval API represents a major advancement for IT professionals seeking to optimize their integrations with Microsoft 365 Copilot. This tool enables targeted searches on content in SharePoint Online, OneDrive for Business, and external connectors, and provides relevant text excerpts to enrich user queries.
Good to know
The Copilot Retrieval API uses an approach based on the RAG (Retrieval Augmented Generation) method, a key competitive advantage of Microsoft 365 Copilot over third-party solutions.
Key Features of the Copilot Retrieval API
What is Query "Grounding"?
Grounding consists of contextually enriching user queries by using text excerpts from authorized Microsoft 365 sources. Unlike tools like ChatGPT that process uploaded documents, the Copilot Retrieval API enables deep searches within Microsoft 365 data.
Differences Between the Search API and the Retrieval API
- Search API: Performs semantic searches.
- Retrieval API: Executes searches based on the RAG method, complemented by text excerpts.
This positioning facilitated by Microsoft provides rich context for integrated applications such as Word, Excel, or PowerPoint.
Access and Permissions of the Connected User
Usage of this API is limited to the context of the connected user. This means the API requires delegated permissions such as:
Files.Read.AllSites.Read.AllExternalItem.Read.Allfor connectors
These permissions ensure that the API only returns results accessible to the connected user.
Attention
Permissions must be properly configured in Microsoft Graph to enable seamless access to data.
Tutorial: Using the Copilot Retrieval API with the Microsoft Graph PowerShell SDK
Here is a series of steps to execute a search via the Copilot Retrieval API:
Connect to Microsoft Graph
Use the PowerShell command to connect with the necessary permissions:
1Connect-MgGraph -NoWelcome -Scopes Files.Read.All, Sites.Read.AllDefine the API endpoint
Assign the Copilot Retrieval API endpoint URL to a variable:
1$Uri = 'https://graph.microsoft.com/v1.0/copilot/retrieval'Create the request body
Configure a hash table containing the search parameters:
1$BodyRequest = @{}2$BodyRequest.Add("datasource", "sharepoint")3$BodyRequest.Add("queryString", "How to write a PowerShell script for Microsoft 365")4$BodyRequest.Add("maximumNumberOfResults", "3")Add advanced filters
Apply filters to target results:
1$BodyRequest.add("filterexpression", 'FileExtension:"DOCX" AND LastModifiedTime>=2025-11-01 AND LastModifiedTime<=2026-01-31')Execute the query
Send a POST request via the Microsoft Graph PowerShell SDK:
1[array]$Data = Invoke-MgGraphRequest -Uri $Uri -Method Post -Body $BodyRequest -OutputType PsObjectInterpret the results
Browse the results by displaying metadata and text excerpts:
1$Hits = $Data.RetrievalHits2ForEach ($Hit in $Hits) {3 Write-Host "File Title :" $Hit.ResourceMetaData.Title4 Write-Host "Creation Date :" $Hit.ResourceMetadata.Created5 Write-Host "Relevance :" $Hit.extracts.relevanceScore6 Write-Host "Sensitivity Label :" $Hit.SensitivityLabel.DisplayName7 Write-Host "Excerpt :" $Hit.extracts.text.substring(0,120)8}Possible Uses and Benefits
- Optimized contextualization of queries for Copilot applications.
- Improved results by using advanced filters and metadata.
- Facilitated integration with Microsoft Graph and PowerShell.
Conclusion
The Copilot Retrieval API paves the way for advanced contextual search in the Microsoft 365 environment, offering IT teams a powerful tool to exploit data in their automated processes or custom applications. As Microsoft continues to strengthen its features in Microsoft 365 Copilot, remaining agile with these tools will enable teams to maximize their benefits.
Tip
Subscribe to the blog to stay informed of the latest advances in Copilot APIs and other enhanced Microsoft 365 features.



