Short answer. Register an Entra ID app, grant
Sites.SelectedorSites.Read.Allwith admin consent, enumerate the selected sites and drives, pull file content with Graph, chunk it, and store the item ID, URL, modified date and item permissions with every chunk. At query time, filter by the user's identity and group memberships before assembling context. Use delta queries for sync and return citations the user is allowed to open.
Architecture
- Auth: Entra ID app registration with application permissions and admin consent.
- Discover: list selected sites, then their document libraries (drives).
- Ingest: download file content, extract text, chunk by heading or page, embed.
- Authorize: read item permissions and store the allowed principals with each chunk.
- Sync: use delta queries and change notifications to update, move and delete chunks.
- Retrieve: filter by user identity, rank, rerank, assemble context, cite.
1. App registration and scopes
Create an app registration in Entra ID, add a client secret or certificate, and grant Microsoft Graph application permissions. For a pilot, Sites.Selected is the least-privilege option: grant the app access to specific sites instead of the whole tenant. Sites.Read.All and Files.Read.All are broader and should be justified.
# Client credentials token (illustrative)
POST https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token
grant_type=client_credentials
client_id={client-id}
client_secret={client-secret}
scope=https://graph.microsoft.com/.default
Admin consent is required for application permissions. Record who approved the grant and which sites are in scope.
2. Find sites and drives
GET https://graph.microsoft.com/v1.0/sites?search=finance
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children
Store the site ID, drive ID and item ID. Do not key documents by filename; names change and collide. The Graph item ID is the stable identifier.
3. Read content and permissions
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/content
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/permissions
Permissions include granted users, groups and sharing links. Map them to your own principal model: user object IDs, group object IDs and “anyone with the link” if that is allowed. Inherited permissions matter; an item can inherit from a folder or library.
4. Chunk with metadata
Chunk by heading, page or paragraph, not by a fixed character count alone. Each chunk should carry:
site_id,drive_id,item_id,web_urlpath,title,section_heading,page_numberlast_modified,modified_by,content_hashallowed_users[],allowed_groups[],inherit_from
If a chunk has no permission record, treat it as inaccessible. Fail closed.
5. Delta sync
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/delta
# Follow @odata.nextLink until you receive @odata.deltaLink.
# Store the deltaLink and use it on the next run.
Delta returns new, updated and deleted items. Handle all three. A deleted file must remove its chunks; a permission change must update the allowed principals; a moved file must update the URL and path.
6. Retrieve with authorization
# Pseudocode: authorize before generation
user = current_user()
principals = [user.id] + user.group_ids
chunks = vector_search(query, top_k=50)
allowed = [c for c in chunks if c.allowed_users ∩ principals or c.allowed_groups ∩ principals]
context = rerank(query, allowed)[:8]
answer = chat_model(context, query)
citations = [c.web_url for c in context]
The filter must run before the model sees the context. A prompt instruction such as “do not reveal documents the user cannot access” is not an authorization control.
7. Citations and evaluation
- Citation correctness: every answer sentence that makes a factual claim points to an item the user can open.
- ACL leakage tests: query as a user without access and confirm the document never appears in context or citations.
- Recall: a labelled set of 50–100 questions with the expected source item.
- Freshness: after a delta sync, the changed content is retrievable and the old chunk is gone.
- Refusal: when no permitted chunk is relevant, the bot says so instead of guessing.
Cost model
index_cost = chunks × embedding_tokens × embedding_rate
query_cost = retrieved_tokens × input_rate + answer_tokens × output_rate
storage = vectors × dimensions × bytes + metadata
Re-embedding changed chunks, not the whole corpus, is the main cost lever. On Plugsky, paid plans start at $8/month; Builder and Scale have no monthly token cap, with fair-use concurrency and RPM. See pricing.
Common failures
- Indexing with a personal account and shipping a service that cannot refresh.
- Ignoring inherited permissions and sharing links.
- Not handling deletions, so stale documents keep answering questions.
- Putting the ACL check in the prompt instead of the retrieval layer.
- Returning a citation the user cannot open.
FAQ
Can I build RAG over SharePoint?
Yes. Use Graph to read sites, drives and content, store permissions with each chunk, and filter by the user's identity before generation.
How do I preserve SharePoint permissions in RAG?
Read item permissions from Graph and store allowed users/groups with each chunk. Filter before assembling context; never rely on the prompt for authorization.
Should I use delegated or application permissions?
Application permissions for a background indexer, scoped with Sites.Selected where possible; delegated permissions or an ACL filter for user-facing queries.
How do I keep the index fresh?
Use Graph delta queries and change notifications. Handle new, updated, deleted, moved and permission-changed items.
How much does SharePoint RAG cost?
Embedding the corpus, re-embedding changes, chat tokens, vector storage and engineering time. Plugsky paid plans start at $8/month; Builder and Scale have no monthly token cap.
Reviewed 20 November 2026. Microsoft Graph endpoints and permission names were checked against public Microsoft documentation on that date. Tenant configuration and Graph behavior vary; test ACL enforcement in a non-production site before rollout.