What This Workflow Does
This n8n workflow automatically processes your Gmail messages, converting them into vector embeddings stored in a PGVector database with the help of Ollama's local AI models. It solves the problem of email overload by transforming your inbox into a semantic searchable knowledge base.
Instead of manually searching through thousands of emails, you can ask natural language questions like "What hotel did I book for last vacation?" or "Show me all project update emails from Q2." The system understands the meaning behind your queries, not just keywords.
How It Works
1. Email Retrieval
The workflow connects to your Gmail account via the Gmail API, fetching new messages based on your specified criteria (labels, date ranges, etc.). It extracts the relevant text content while preserving metadata like sender, date, and subject.
2. Text Processing
Email content is cleaned and prepared for embedding - removing signatures, quoted text, and irrelevant formatting. The system can optionally summarize long threads or extract key entities (names, dates, amounts) before vectorization.
3. Vector Embedding Generation
Ollama's local language models process the cleaned text to generate high-dimensional vector embeddings. These numerical representations capture the semantic meaning of the email content in a way that similar concepts map to nearby points in vector space.
4. Database Storage
The generated embeddings along with their source email metadata are stored in a PostgreSQL database with the PGVector extension. This enables efficient similarity searches and clustering operations on your email corpus.
5. Query Interface
The workflow includes endpoints to query your vectorized emails. You can ask natural language questions that get converted to embeddings and matched against your stored emails, returning the most semantically relevant results.
Who This Is For
This workflow benefits knowledge workers, executives, customer support teams, and anyone who needs to frequently retrieve information from past emails. It's particularly valuable for:
- Consultants who need to recall specific client discussions
- Sales teams tracking customer conversations
- Legal professionals organizing case correspondence
- Project managers coordinating multiple initiatives
- Individuals wanting personal knowledge management
What You'll Need
- An n8n instance (self-hosted or cloud)
- Gmail account with API access enabled
- PostgreSQL database with PGVector extension
- Ollama installed with your preferred LLM model
- Basic understanding of API authentication
Quick Setup Guide
- Download the JSON template file
- Import into your n8n instance
- Configure Gmail API credentials
- Set up your PostgreSQL connection details
- Specify your Ollama endpoint and model
- Define your initial email search criteria
- Test with a small batch of emails first
Pro tip: Start with a specific label or folder rather than your entire inbox to test the system with manageable volumes.
Key Benefits
Save hours of manual email searching by converting your inbox into an AI-powered knowledge base that understands semantic queries.
Keep sensitive data private by processing emails locally with Ollama instead of sending them to external AI services.
Scale to thousands of emails with PGVector's efficient storage and retrieval of high-dimensional embeddings.
Discover hidden connections between emails through semantic similarity searches that keyword-based systems would miss.
Future-proof your email data by storing it in vector format ready for emerging AI applications.