GoogleDriveFetcher
Fetch the full content of Google Drive files via the Drive API v3. Use this component with GoogleDriveRetriever to download file content after search, or pass file IDs and URLs directly.
Key Features
- Downloads binary files (PDF, DOCX, images, and others) as
ByteStreamobjects. - Exports native Google Docs, Sheets, and Slides to Office formats by default (DOCX, XLSX, PPTX).
- Accepts
Documentobjects fromGoogleDriveRetrieveror raw file IDs and Drive URLs. - Skips folders and non-downloadable Google file types.
- Supports concurrent fetching in async mode.
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
GoogleDriveFetchercomponent onto the canvas from the Component Library. - Wire an upstream
OAuthTokenResolverto provide a delegated Google OAuth bearer token on theaccess_tokeninput. - Connect
GoogleDriveRetriever.documentsor file IDs and URLs to thetargetsinput. - Connect the
streamsoutput to downstream converters such asPyPDFToDocumentorDOCXToDocument.
The access token must carry a scope that allows reading file content, for example https://www.googleapis.com/auth/drive.readonly.
Connections
GoogleDriveFetcher receives an access_token and a list of targets (Document objects or file ID/URL strings). It outputs streams as a list of ByteStream objects. Each stream's metadata includes file_id, web_url, file_name, and content_type.
Source Code
To check this component's source code, open fetcher.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
GoogleDriveFetcher:
type: haystack_integrations.components.fetchers.google_drive.fetcher.GoogleDriveFetcher
init_parameters: {}
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
fetcher:
type: haystack_integrations.components.fetchers.google_drive.fetcher.GoogleDriveFetcher
init_parameters: {}
connections:
- sender: oauth_resolver.access_token
receiver: retriever.access_token
- sender: oauth_resolver.access_token
receiver: fetcher.access_token
- sender: retriever.documents
receiver: fetcher.targets
inputs:
query:
- retriever.query
outputs:
streams: fetcher.streams
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
access_token | str | Secret | Delegated Google OAuth bearer token for the user whose files are fetched. |
targets | List[Document | str] | Files to fetch as Document objects from GoogleDriveRetriever or raw file IDs and Drive URLs. |
Outputs
| Parameter | Type | Description |
|---|---|---|
streams | List[ByteStream] | Fetched file content. Each stream's metadata includes file_id, web_url, file_name, and content_type. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
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 for throttled or transient server errors. |
max_concurrent_requests | int | 5 | Maximum concurrent file fetches in run_async. |
raise_on_failure | bool | True | If True, a fetch failure raises an exception. If False, the file is skipped. |
export_mime_types | Dict[str, str] | None | None | Mapping of native Google mime types to export formats. Defaults to Docs/Sheets/Slides exported as DOCX/XLSX/PPTX. |
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 |
|---|---|---|---|
access_token | str | Secret | Delegated Google OAuth bearer token. | |
targets | List[Document | str] | Files to fetch. |
Related Information
Was this page helpful?