Recently, I came across a great YouTube tutorial from Cole Medin on building a RAG system with n8n, Google Drive, OpenAI, and Supabase. The workflow was solid for Google Docs, but I quickly realized it wouldn’t work with my existing Word documents or PDFs. Always up for a challenge, I decided to enhance Cole’s original workflow to support PDF and DOCX documents.
The Problem: PDFs and Word Docs Are Binary Blobs
If you try to use the original workflow with PDF or DOCX files, you’ll end up with something like this in your database:
PK DciZ word/numbering.xmlí�[nã6 †WÐ= zOt±,;Æ8ƒ` )Z E�N @K´MD" R²"n¡ }k_»¶¤ÔÕ·±*y¢zRÿOŠ ùÿ䡎ùÑ�!¿{ÿ …ƒ5•Š >3ì[Ë Pî‹€ñåÌøåÓãÍÄ ¨„ð€„‚ÓñB•ñþþ›w›)O£9•ºß@[p5�ü±J'xjšÊ_ш¨[ S BF$Ñ/åÒŒˆ|Jã *D1IØœ…,y1
Yikes! That’s raw binary data, not the text content that our RAG system needs. The AI can’t extract any meaningful information from this jumble.
The Solution: File Type Detection and Conversion
To fix this, I needed to add a few key improvements to the workflow:
- Update the Set File ID node
- Add a Switch node to detect file types
- Implement ConvertAPI integration to transform PDFs/DOCXs to plain text
- Use a Code node to ensure filenames have proper extensions
Here’s how I implemented each part:
1. Add mime_type to the Set File ID Node
First, I updated the Set File ID node to set the mime_type. This is used to drive the logic in the new Switch node below.
2. Detecting File Types with the Switch Node
Next, I added a Switch node after downloading the file from Google Drive. This node checks the MIME type (mime_type) of the file and routes it accordingly:
application/pdf
→ PDF conversion pathapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
→ DOCX conversion pathapplication/vnd.google-apps.document
→ Google Docs path (the original flow)
This routing ensures each file type gets handled appropriately. If you had more file types that you wanted to support, you could easily add them here.
3. Converting Files with ConvertAPI
For both PDF and DOCX paths, I integrated with ConvertAPI, a service that handles file conversions elegantly. You’ll need to:
- Sign up for a free ConvertAPI account (you get 250 free conversions)
- Copy your secret key from the dashboard
- Add the ConvertAPI (HTTP Request) nodes as shown in my workflow
- Configure your Credential for ConvertAPI with the secret from #2
For PDFs:
POST https://v2.convertapi.com/convert/pdf/to/txt
For DOCX:
POST https://v2.convertapi.com/convert/docx/to/txt
The beauty of this approach is that ConvertAPI handles all the complex conversion logic, including OCR for scanned PDFs if needed.
4. Adding File Extensions with a Code Node
I discovered a quirk: ConvertAPI expects files to have proper extensions in their filenames. Since my Google Docs file names did not include a file extension, I added a Code node with this simple JavaScript:
$input.item.binary.data.fileName = `${$input.item.binary.data.fileName}.${$input.item.binary.data.fileExtension}`;
return $input.item;
This ensures the filename has an extension before we send it to ConvertAPI. Ideally, you’d check to see if a file extension exists before adding one, but I know my Google Docs did not include one.
The Complete Workflow
After these modifications, the workflow now does the following:
- Detects when a file is created or updated in Google Drive
- Identifies the file type
- Converts PDFs and DOCX files to plain text
- Extracts the text content
- Stores it in Supabase with proper embeddings
- Makes it available for the RAG AI agent to query
Check out the full workflow in the screenshot:

Why This Matters
Having your RAG system work with PDFs and Word documents is game-changing for several reasons:
- Most business knowledge is locked in these formats
- Legacy documents don’t need to be converted manually
- You can ingest reports, contracts, manuals, and more
- The system becomes practical for real-world use
Additional Considerations
While implementing this enhanced RAG workflow with PDF and DOCX support, here are some important factors to keep in mind:
Cost Considerations
- ConvertAPI Pricing: The free tier includes 250 conversions, which is perfect for testing and small implementations. Beyond that, pricing starts at $30/month for 1,000 conversions and scales up based on volume.
- OpenAI Costs: Remember that each document processed generates embedding costs. For large document collections, these can add up quickly. Consider batching updates or implementing selective processing.
- Storage Costs: As your document database grows, Supabase storage and database costs may increase. Monitor your usage to avoid unexpected bills.
Technical Limitations
- Complex Document Formatting: While this solution works well for text-focused documents, highly formatted content with tables, charts, or complex layouts may lose structural information during conversion.
- Image-Heavy PDFs: If your PDFs primarily contain images or scanned text, ConvertAPI’s OCR capabilities will help, but may not be perfect. Consider testing with your specific documents.
- Large Files: Very large documents (over 25MB) might encounter timeout issues, and you may need to implement chunking strategies.
- Language Support: Non-English documents may have varying degrees of success depending on character sets and the OCR capabilities of ConvertAPI.
Security Considerations
- Data Privacy: This workflow sends document content to external services (ConvertAPI and OpenAI). Ensure this complies with your organization’s data policies.
- API Key Security: Store your ConvertAPI and OpenAI credentials securely. In n8n, use the credentials vault rather than hardcoding keys.
- Access Controls: Set appropriate permissions in Google Drive and Supabase to limit who can access the source documents and extracted content.
- Data Retention: Consider how long you need to keep both the original documents and their processed text. Implement a cleanup strategy for outdated material.
By addressing these considerations upfront, you’ll build a more robust, scalable, and secure document processing workflow that can handle real-world challenges.
Getting Started Yourself
If you want to implement this enhanced workflow:
- You can download my modified workflow JSON from GitHub
- Import it into your n8n instance
- Set up your credentials for Google Drive, OpenAI, Supabase, and ConvertAPI
- Configure the folder path in Google Drive where your documents live
- Start adding files and chatting with your data!
If you’re new to n8n, I highly recommend using n8n Cloud for the easiest setup. Their free trial is perfect for testing, and you can upgrade as your needs grow.
I’d love to hear how you adapt this approach for your own needs! Have you found ways to handle other file types? Created interesting agent prompts? Drop me a comment below and let me know!