.docx and .xlsx. So is any file over 25 MB (raise it with GOOGLE_DRIVE_MAX_FILE_SIZE_MB), and a Google Sheet contributes its first sheet only, which is all Drive’s export returns. See What gets indexed for the full table — the hosted connector reads files through the same code path.
Before You Start
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured — the script calls
cognee.recall(), which needs an LLM for the final completion - Read Datasets — the folder is synced into the
google_drive_demodataset - Install the connector extra:
pip install "cognee[google-drive]" - Enable the Google Drive API in the Google Cloud Console and set up one of these auth modes:
- Service account (recommended, no interactive step): create a service account, download a JSON key for it, and share the target folder with the service account’s
client_email(Viewer access is enough). Then setGOOGLE_DRIVE_AUTH_MODE=service_accountandGOOGLE_DRIVE_CREDENTIALS_PATH=/path/to/service-account.json - OAuth user credentials (for a folder in your own My Drive): create an OAuth Client ID of type “Desktop app” and download its JSON. Then set
GOOGLE_DRIVE_AUTH_MODE=oauth,GOOGLE_DRIVE_CREDENTIALS_PATH=/path/to/oauth-client-secret.json, andGOOGLE_DRIVE_TOKEN_PATH=/path/to/cache-the-user-token.json. The first run opens a browser for one-time consent; later runs reuse the cached, auto-refreshed token
- Service account (recommended, no interactive step): create a service account, download a JSON key for it, and share the target folder with the service account’s
- Set
GOOGLE_DRIVE_FOLDER_IDto the folder’s Drive ID, taken from its URL
This guide drives the connector from your own script, with credentials you hold on disk. If you instead want users to connect their own Drive account to a running Cognee backend over a web OAuth consent, use the Google Drive integration — it is configured with a different set of
GOOGLE_DRIVE_* variables (GOOGLE_DRIVE_CLIENT_ID, GOOGLE_DRIVE_REDIRECT_URI, and so on) and syncs over its own REST endpoints.Code in Action
What Just Happened
Step 1: Create the Drive Source
google_drive_source() returns a dlt source for the folder. Called with no arguments, it takes the auth mode, credentials, token path, and folder ID from the GOOGLE_DRIVE_* environment variables set up in Before You Start.
Step 2: Run the Initial Sync
remember() extracts every file, chunks it, and builds the graph. primary_key="id" keys each row by its Drive file ID, and write_disposition="merge" upserts on that key — which is what makes later runs incremental and lets deletions propagate.
max_rows_per_table=0 means no row cap, but it changes nothing here: Google Drive is a document source, and Cognee always reads a document source’s whole staging table, whatever max_rows_per_table or DLT_MAX_ROWS_PER_TABLE says. (The upstream script’s inline comment still describes an older 50-row default, which cognee dropped in favor of unlimited ingestion.)
Step 3: Recall From the Folder
recall() can answer questions about them.
Step 4: Re-Sync Incrementally
dlt (Data Load Tool)
The dlt ingestion path the connector builds on, including write dispositions.
remember()
Every option
remember() accepts when ingesting a source.