Skip to main content
This notebook covers how to retrieve documents from Google Drive.

Prerequisites

  1. Create a Google Cloud project or use an existing project
  2. Enable the Google Drive API
  3. Authorize credentials for desktop app
  4. pip install -U google-api-python-client google-auth-httplib2 google-auth-oauthlib

Retrieve the Google Docs

By default, the GoogleDriveRetriever expects the credentials.json file to be ~/.credentials/credentials.json, but this is configurable using the GOOGLE_ACCOUNT_FILE environment variable. The location of token.json uses the same directory (or use the parameter token_path). Note that token.json will be created automatically the first time you use the retriever. GoogleDriveRetriever can retrieve a selection of files with some requests. By default, If you use a folder_id, all the files inside this folder can be retrieved to Document. You can obtain your folder and document id from the URL: The special value root is for your personal home.
By default, all files with these MIME types can be converted to Document.
  • text/text
  • text/plain
  • text/html
  • text/csv
  • text/markdown
  • image/png
  • image/jpeg
  • application/epub+zip
  • application/pdf
  • application/rtf
  • application/vnd.google-apps.document (GDoc)
  • application/vnd.google-apps.presentation (GSlide)
  • application/vnd.google-apps.spreadsheet (GSheet)
  • application/vnd.google.colaboratory (Notebook colab)
  • application/vnd.openxmlformats-officedocument.presentationml.presentation (PPTX)
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document (DOCX)
It’s possible to update or customize this. See the documentation of GoogleDriveRetriever. But, the corresponding packages must be installed.
You can customize the criteria to select the files. A set of predefined filter are proposed:
Else, you can customize the prompt with a specialized PromptTemplate

Use Google Drive ‘description’ metadata

Each Google Drive has a description field in metadata (see the details of a file). Use the snippets mode to return the description of selected files.