GoogleDriveRetriever
Search Google Drive and retrieve matching files as Haystack Document objects. Use this component to find files by full-text search before fetching or indexing their content.
Key Features
- Runs full-text search over the user's Google Drive via the Drive API v3.
- Returns file metadata including
file_name,file_id,web_url,mime_type, and timestamps. - Optionally exports native Google Docs, Sheets, and Slides to text for document content.
- Supports shared drives, query filters, and custom field selection.
- 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
GoogleDriveRetrievercomponent onto the canvas from the Component Library. - Wire an upstream
OAuthTokenResolverto provide a delegated Google OAuth bearer token on theaccess_tokeninput. - Set
top_kto control the number of results. - Go to the Advanced tab to configure
query_filter,include_shared_drives,include_content, and other options.
The access token must carry a scope that allows search, for example https://www.googleapis.com/auth/drive.readonly. The metadata-only drive.metadata.readonly scope cannot search file content or export documents.
Connections
GoogleDriveRetriever receives a search query and an access_token. It outputs a list of Document objects. Connect the documents output to GoogleDriveFetcher for full file content, or to downstream components that process metadata and snippets.
Source Code
To check this component's source code, open retriever.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
GoogleDriveRetriever:
type: haystack_integrations.components.retrievers.google_drive.retriever.GoogleDriveRetriever
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://oauth2.googleapis.com/token
client_id: your-client-id
refresh_token:
type: env_var
env_vars:
- GOOGLE_REFRESH_TOKEN
strict: false
scopes:
- https://www.googleapis.com/auth/drive.readonly
retriever:
type: haystack_integrations.components.retrievers.google_drive.retriever.GoogleDriveRetriever
init_parameters:
top_k: 5
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, matched against file full text via fullText contains. |
access_token | str | Secret | Delegated Google OAuth bearer token for the user whose Drive is searched. |
top_k | int | None | Overrides the init-time top_k for this run. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Matching files as Haystack documents with metadata and optional exported content. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
include_content | bool | False | When True, exports native Google Docs/Sheets/Slides to text and uses the result as document content. |
top_k | int | 10 | Maximum number of documents to return. |
query_filter | str | None | None | Optional Drive query clause AND-ed with the search term, for example "mimeType != 'application/vnd.google-apps.folder'". |
include_shared_drives | bool | False | When True, searches shared drives as well as My Drive. |
order_by | str | None | None | Optional Drive orderBy expression, for example "modifiedTime desc". |
fields | List[str] | None | None | File properties to request via the Drive fields selection. |
api_base_url | str | https://www.googleapis.com/drive/v3 | The Drive API base URL. |
timeout | float | 30.0 | HTTP timeout in seconds for each Drive API request. |
max_retries | int | 3 | Maximum retries on rate-limit 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 Google OAuth bearer token. | |
top_k | int | None | None | Maximum number of documents to return. Overrides the init-time value. |
Related Information
Was this page helpful?