Calling the Copilot Retrieval API - Request Shape, KQL Filters and the Gotchas We Hit
Most Australian organisations we work with already have years of policies, contracts, project files and procedures sitting in SharePoint and OneDrive. When they decide to build their own AI assistant, the first instinct is to copy all of that into a vector database. That means a second copy of sensitive documents, a second set of permissions to maintain, and an ingestion pipeline someone has to babysit forever.
The Copilot Retrieval API is Microsoft's answer to that problem. You send it a natural language query, it searches the content the signed-in user can already see, and it hands back relevant text chunks you can feed to whatever model you like. No re-indexing, no copying files, and the permission model is the one your organisation already has.
I wrote an overview of what the API is a little while ago. This post is the practical follow-up: what a request actually looks like, how to scope it properly, and the things that tripped us up when we started using it on client projects.
The basic request
Retrieval is a single POST to Microsoft Graph at the /copilot/retrieval endpoint. The body is small:
{
"queryString": "What is our policy on contractor reimbursement for travel?",
"dataSource": "sharePoint",
"filterExpression": "path:\"https://contoso.sharepoint.com/sites/HR/\"",
"resourceMetadata": ["title", "author", "lastModifiedDateTime"],
"maximumNumberOfResults": 10
}
A few notes on each field, based on what we've learned the hard way.
queryString is the question. Write it as a full sentence, not a keyword list. The service does semantic matching, so "contractor travel reimbursement policy" works, but a proper question tends to give better extracts. There's a length cap (1,500 characters at the time of writing), which matters if you're tempted to pass the user's entire chat history in. Don't. Have your model rewrite the latest turn into a standalone question first, then send that.
dataSource picks where to look. The main options are sharePoint, oneDriveBusiness and externalItem (for content pulled in through Copilot connectors). You pick one per request. If you want SharePoint and OneDrive together, that's two calls, which you can bundle with a Graph $batch request.
filterExpression is where most of the real work happens, and I'll come back to it.
resourceMetadata lets you ask for document properties alongside the text. Title, author and modified date are the ones we almost always request because they make citations far more useful. A user who sees "HR Travel Policy v4, updated March 2026" trusts the answer more than one who sees a bare URL.
maximumNumberOfResults tops out at 25. Ten is a sensible default for most chat scenarios. More results means more tokens going into your model and, in our testing, the bottom half of a 25-result set is usually noise.
Filters are the difference between good and bad answers
Without a filter, the API searches everything the user can access. In a big tenant that's a lot. We had one client, a professional services firm in Brisbane, where an unfiltered query about "leave entitlements" pulled back a mix of the current HR policy, three superseded drafts, a client's enterprise agreement that had been uploaded to a project site, and a staff member's personal notes from OneDrive. All technically accessible to that user. Only one of them was the right answer.
The filterExpression uses KQL (Keyword Query Language), the same syntax SharePoint search has used for years. The properties we lean on most:
path:"https://tenant.sharepoint.com/sites/Policies/"to restrict to a site or libraryFileExtension:"docx" OR FileExtension:"pdf"to skip spreadsheets and slide decks when you want proseLastModifiedTime>=2025-01-01to cut out stale contentAuthor:"Jane Smith"occasionally, though it's less useful than people expect
You can combine them with AND and OR. A typical filter for an HR assistant might restrict to two site paths and documents modified in the last two years.
Here's my honest take: the filter is a design decision, not a technical one. Someone in the business has to say which sites are authoritative for which kind of question. When we run a Copilot Studio or custom agent project, we spend more time in workshops agreeing on those sources than we spend writing the retrieval code. If nobody will own that decision, the agent will give confidently wrong answers sourced from someone's old draft, and people will stop using it within a month.
One thing to watch: not every KQL property behaves exactly as it does in SharePoint search. Check the supported properties list in the docs before you build a filter strategy around something obscure.
What comes back
The response is a list of retrievalHits. Each hit includes:
- the
webUrlof the source document - one or more
extracts, each with a chunk oftextand a relevance score - the
resourceType(list item, drive item, external item) - any metadata you asked for
- the sensitivity label, if the document has one
The extracts are the useful part. They're already chunked, so you don't need to fetch and split the document yourself. You pass them into your prompt as grounding context, tell the model to answer only from them, and render the URLs as citations.
The sensitivity label deserves more attention than it usually gets. If your app is going to display content or pass it to a model outside Microsoft's boundary, you should check the label and decide what to do with "Highly Confidential" material. The API respects access permissions, but whether a given user should see that content inside your particular app is a separate question. We usually drop anything above a certain label for agents that post into shared channels.
Permissions and licensing
This is where most first attempts fail.
The API uses delegated permissions only. There's no app-only mode. Every call runs as a signed-in user and only returns what that user can see. That's the whole point, but it rules out background jobs that crawl content on a schedule. If you need that pattern, you're back to building your own index with Azure AI Search.
For SharePoint and OneDrive you need Files.Read.All and Sites.Read.All. For connector content you need ExternalItem.Read.All. These need admin consent, so loop in your Entra ID administrator early. I've watched a two-week proof of concept lose four days waiting on a consent approval because nobody raised it up front.
Licensing is the other one. The users calling the API need a Microsoft 365 Copilot licence, or your tenant needs to be set up for the pay-as-you-go option where it's available. This catches people out when they want to build an assistant for frontline staff who don't have Copilot seats. Do the licence maths before you write any code. Sometimes it changes the whole architecture.
There's also a throttling limit per user per hour (200 requests at the time of writing). For a chat assistant that's fine. For something that fires several retrieval calls per user action, like a research agent that fans out sub-queries, you can hit it during heavy use. Cache where you can.
What works well
The permission trimming is the standout. On a recent project for a financial services client we were able to skip an entire security review workstream because the content never left Microsoft 365 and every result was trimmed to the user's existing access. Their risk team understood the model immediately because it was the same one they already approved for SharePoint search.
Freshness is the other win. A document saved to SharePoint this morning shows up in retrieval once it's indexed, typically within minutes. With a custom pipeline you're always one sync job behind.
And it's model-agnostic. You get text back, and you can send it to Azure OpenAI, to Claude, or to a small local model. The retrieval layer doesn't care.
What's still rough
The relevance ranking is decent but it's a black box. You can't tune it, add custom boosting or plug in your own reranker before results come back. If your content is messy (lots of near-duplicate documents, scanned PDFs with poor OCR) you'll see it in the results and there's not much you can do on the API side. Cleaning up the content is the fix, which is unglamorous but works.
Tables and spreadsheets don't come through well. The extracts are text, and a pricing table in a Word document often arrives as a jumble. For structured data, query the source directly or use a different tool.
Debugging is harder than with your own index. When a result is missing, you can't inspect the index to see why. Usually it's permissions, a filter that's too tight, or content that hasn't been indexed yet, but working out which takes some trial and error. We keep a small test script that runs a fixed set of questions against a fixed set of filters so we notice quickly when something changes.
When to use it and when not to
Use the Retrieval API when your content already lives in Microsoft 365, your users already have (or will get) Copilot licences, and permission trimming matters. That covers a lot of internal assistants: HR, policy, project knowledge, IT help.
Look elsewhere when you need app-only background processing, heavy structured data, custom ranking, or users without Copilot licences. Azure AI Search with your own ingestion is still the better fit there, and we build both regularly as part of our Azure AI consulting work.
If you're deciding between the two, or you want a second opinion on an agent design before you commit, get in touch through our AI agent development team. Most of the time the right answer comes out of a one-hour conversation about where the content lives and who needs to see it.
Reference: Microsoft Learn - Retrieve data with the Copilot Retrieval API