Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

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 OAuthTokenResolver for per-user delegated access.

Configuration

Add Workspace-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. Drag the GoogleDriveRetriever component onto the canvas from the Component Library.
  2. Wire an upstream OAuthTokenResolver to provide a delegated Google OAuth bearer token on the access_token input.
  3. Set top_k to control the number of results.
  4. 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

ParameterTypeDescription
querystrSearch query string, matched against file full text via fullText contains.
access_tokenstr | SecretDelegated Google OAuth bearer token for the user whose Drive is searched.
top_kint | NoneOverrides the init-time top_k for this run.

Outputs

ParameterTypeDescription
documentsList[Document]Matching files as Haystack documents with metadata and optional exported content.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
include_contentboolFalseWhen True, exports native Google Docs/Sheets/Slides to text and uses the result as document content.
top_kint10Maximum number of documents to return.
query_filterstr | NoneNoneOptional Drive query clause AND-ed with the search term, for example "mimeType != 'application/vnd.google-apps.folder'".
include_shared_drivesboolFalseWhen True, searches shared drives as well as My Drive.
order_bystr | NoneNoneOptional Drive orderBy expression, for example "modifiedTime desc".
fieldsList[str] | NoneNoneFile properties to request via the Drive fields selection.
api_base_urlstrhttps://www.googleapis.com/drive/v3The Drive API base URL.
timeoutfloat30.0HTTP timeout in seconds for each Drive API request.
max_retriesint3Maximum 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.

ParameterTypeDefaultDescription
querystrSearch query string.
access_tokenstr | SecretDelegated Google OAuth bearer token.
top_kint | NoneNoneMaximum number of documents to return. Overrides the init-time value.