Skip to content
Docs

Google Drive Document Loader

The Google Drive loader implements the loader.DocumentLoader interface for loading files from Google Drive. It uses the Google Drive REST API v3 to fetch file content, with automatic export support for Google Workspace documents (Docs, Sheets, Slides).

Choose Google Drive when you need to load documents from Google Drive, especially Google Workspace files (Docs, Sheets, Slides). The loader automatically exports Workspace formats to text, avoiding manual conversion. For other cloud storage (S3, GCS, Azure), use Cloud Storage. For Atlassian wikis, consider Confluence.

Terminal window
go get github.com/lookatitude/beluga-ai/rag/loader/providers/gdrive
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/lookatitude/beluga-ai/config"
"github.com/lookatitude/beluga-ai/rag/loader"
_ "github.com/lookatitude/beluga-ai/rag/loader/providers/gdrive"
)
func main() {
l, err := loader.New("gdrive", config.ProviderConfig{
APIKey: os.Getenv("GOOGLE_API_KEY"),
})
if err != nil {
log.Fatal(err)
}
docs, err := l.Load(context.Background(), "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms")
if err != nil {
log.Fatal(err)
}
fmt.Printf("File: %s\n", docs[0].Metadata["file_name"])
fmt.Printf("Content: %s\n", docs[0].Content)
}
ParameterTypeDefaultDescription
APIKeystring(required)Google API key or OAuth access token
BaseURLstringhttps://www.googleapis.comGoogle API base URL
Timeouttime.Duration60sHTTP request timeout

The source parameter is a Google Drive file ID:

docs, err := l.Load(ctx, "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms")

You can find the file ID in the Google Drive URL: https://docs.google.com/document/d/<FILE_ID>/edit

The loader automatically detects Google Workspace formats and exports them as text:

MIME TypeExport Format
application/vnd.google-apps.documentPlain text
application/vnd.google-apps.spreadsheetCSV
application/vnd.google-apps.presentationPlain text
Other vnd.google-apps.* typesPlain text

Non-Google files (PDFs, text files, etc.) are downloaded directly.

FieldTypeDescription
sourcestringFile ID passed to Load
loaderstringAlways "gdrive"
file_idstringGoogle Drive file ID
file_namestringFile name from Drive metadata
mime_typestringFile MIME type

For public files or files accessible via API key:

l, err := loader.New("gdrive", config.ProviderConfig{
APIKey: os.Getenv("GOOGLE_API_KEY"),
})

For private files, pass an OAuth 2.0 access token as the APIKey:

l, err := loader.New("gdrive", config.ProviderConfig{
APIKey: oauthToken.AccessToken,
})
docs, err := l.Load(ctx, "file-id")
if err != nil {
// Possible errors:
// - "gdrive: API key or OAuth token is required" (missing APIKey)
// - "gdrive: file ID is required" (empty source)
// - "gdrive: get metadata ...: ..." (file not found or access denied)
// - "gdrive: get content ...: export failed (status 403): ..." (auth error)
log.Fatal(err)
}