MSSharePointRetriever
Search Microsoft SharePoint and OneDrive and retrieve matching content as Haystack Document objects. Use this component to find files, list items, and pages before fetching their full content.
Key Features
- Runs full-text search over SharePoint and OneDrive via the Microsoft Search (Graph) API.
- Returns search snippets as document content with rich metadata (
file_name,web_url,entity_type, timestamps, and SharePoint identifiers). - Supports Keyword Query Language (KQL) filters in queries and query templates.
- Configurable entity types, field selection, and result count.
- Works with
OAuthTokenResolverfor per-user delegated access.
Configuration
Add Workspace-Level Integration
- Click your profile icon and choose Settings.
- Go to Workspace>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in the current workspace.
Add Organization-Level Integration
- Click your profile icon and choose Settings.
- Go to Organization>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
- Drag the
MSSharePointRetrievercomponent onto the canvas from the Component Library. - Wire an upstream
OAuthTokenResolverto provide a delegated Microsoft Graph bearer token on theaccess_tokeninput. - Set
top_kto control the number of results. - Go to the Advanced tab to configure
entity_types,query_template, andfields.
The access token must carry delegated Microsoft Graph permissions, for example Files.Read.All and Sites.Read.All. The Search API supports delegated permissions only.
Connections
MSSharePointRetriever receives a search query and an access_token. It outputs a list of Document objects. Connect the documents output to MSSharePointFetcher for full file content, or to downstream components that process search snippets.
Source Code
To check this component's source code, open retriever.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
MSSharePointRetriever:
type: haystack_integrations.components.retrievers.microsoft_sharepoint.retriever.MSSharePointRetriever
init_parameters:
top_k: 10
Using the Component in a Pipeline
# haystack-pipeline
components:
oauth_resolver:
type: haystack_integrations.components.connectors.oauth.resolver.OAuthTokenResolver
init_parameters:
token_source:
type: haystack_integrations.utils.oauth.sources.OAuthRefreshTokenSource
init_parameters:
token_url: https://login.microsoftonline.com/common/oauth2/v2.0/token
client_id: your-client-id
refresh_token:
type: env_var
env_vars:
- MS_REFRESH_TOKEN
strict: false
scopes:
- https://graph.microsoft.com/Files.Read.All
- https://graph.microsoft.com/Sites.Read.All
retriever:
type: haystack_integrations.components.retrievers.microsoft_sharepoint.retriever.MSSharePointRetriever
init_parameters:
top_k: 5
query_template: '{searchTerms} path:"https://contoso.sharepoint.com/sites/Team"'
connections:
- sender: oauth_resolver.access_token
receiver: retriever.access_token
inputs:
query:
- retriever.query
outputs:
documents: retriever.documents
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
query | str | Search query string. Embed KQL operators directly, for example filetype:docx or path:"https://contoso.sharepoint.com/sites/Team". |
access_token | str | Secret | Delegated Microsoft Graph bearer token for the user whose content is searched. |
top_k | int | None | Overrides the init-time top_k for this run. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Matching items as Haystack documents with search snippets and metadata. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
entity_types | List[str] | None | ["driveItem", "listItem"] | Microsoft Search entity types to query. Also supports "list" and "site". |
top_k | int | 10 | Maximum number of documents to return. |
fields | List[str] | None | None | Resource properties to request via the Search API fields selection. |
query_template | str | None | None | Query template to scope the search. Use {searchTerms} as the placeholder for the run-time query. |
graph_url | str | https://graph.microsoft.com/v1.0 | The Microsoft Graph base URL. Override for sovereign clouds. |
timeout | float | 30.0 | HTTP timeout in seconds for each Graph API request. |
max_retries | int | 3 | Maximum retries for throttled or transient server errors. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | Search query string. | |
access_token | str | Secret | Delegated Microsoft Graph bearer token. | |
top_k | int | None | None | Maximum number of documents to return. Overrides the init-time value. |
Related Information
Was this page helpful?