Use this powerful n8n workflow to automatically turn incoming Gmail messages into vector embeddings using Ollama, storing data in PGVector for similarity search and building a RAG knowledge base.
Download this n8n workflow template and start using it instantly.
• Users building RAG systems based on personal email history.
• Data scientists needing to analyze large volumes of proprietary communication data.
• Developers looking for advanced n8n templates integrating Gmail, Local AI (Ollama), and PostgreSQL.
• Anyone needing a robust n8n workflow for creating a searchable email knowledge base.
This sophisticated n8n workflow provides a complete, self-hosted solution for transforming your Gmail inbox into a powerful, searchable knowledge base. It uses local AI processing via the Ollama platform (specifically the nomic-embed-text model) to generate high-quality vector embeddings from your email content. The n8n workflow is dual-purpose, featuring an n8n trigger for real-time processing of new emails, and a robust manual bulk import function designed to vectorize your entire historical archive by processing data in weekly batches. All structured email metadata and the resulting vector data are safely stored in separate PostgreSQL tables (emailsmetadata and emailsembeddings), leveraging PGVector for efficient vector similarity searches. This specialized n8n node setup ensures data integrity and scalability, making it one of the most effective n8n templates available for email knowledge base generation.
This n8n workflow operates in two distinct modes:
Gmail Trigger n8n node continuously monitors your INBOX for new messages every minute. Upon detection, the email data flows directly to the Extract email fields n8n node, where metadata is prepared. The data is then stored structurally in PostgreSQL via the Store structured n8n node. Simultaneously, the email text is vectorized using the Embeddings Ollama n8n node and saved to PGVector via the Store vectorized n8n node.Manual Trigger n8n node is executed, the n8n workflow initializes by ensuring the PostgreSQL tables are created (Create the table). The custom Code n8n node, Explode interval into weeks, calculates all the weekly periods between your account creation date (which must be edited in the n8n node) and today. This creates multiple items, which are processed sequentially by the Loop Over Items n8n node.Inside the loop, the Set before and after dates n8n node specifies the weekly range. The Get a batch of messages Gmail n8n node retrieves the emails for that specific week. Each message is processed—extracted, structured, vectorized, and stored—identical to the real-time path. Finally, an If n8n node checks if the process was manual, and if so, ensures the loop continues to the next batch until the entire email history is processed. This efficient batching prevents timeout issues common with large data imports in any n8n workflow.
nomic-embed-text model is available (use ollama pull nomic-embed-text).Explode interval into weeks n8n node and update the variable whenDidICreateMyGmailAccount to your actual Gmail account creation date. This is crucial for the bulk import function of this n8n template.Gmail Trigger monitoring. To perform the initial bulk import, simply execute the Manual Trigger n8n node. Manual Trigger (n8n trigger): Used exclusively to initiate the one-time bulk ingestion of historical email data.
Gmail Trigger (n8n trigger): The primary n8n node for production use, monitoring the INBOX label every minute for new emails.
Explode interval into weeks (Code n8n node): A custom n8n node that calculates discrete weekly intervals based on a user-defined start date, preparing the data structure needed for the historical batch loop.
Get a batch of messages (Gmail n8n node): Retrieves emails based on date filters set dynamically by the looping structure.
Extract email fields (Set n8n node): Standardizes and extracts crucial email components (emailtext, emailid, threadid, etc.) into variables accessible by downstream n8n nodes.
Store structured (PostgreSQL n8n node): Inserts or updates the structured metadata into the emailsmetadata table using an UPSERT operation based on emailid. Uses error handling (continueErrorOutput) specific to this n8n workflow.
Embeddings Ollama (n8n node): Connects to the local Ollama service to generate vector embeddings using the nomic-embed-text:latest model, a key component for this AI-driven n8n workflow.
Recursive Character Text Splitter (n8n node): Ensures large emails are broken into manageable, context-rich chunks (chunk size 2000, overlap 50) before vectorization, optimizing RAG performance.
emailsembeddings table, completing the knowledge base creation process for this powerful n8n workflow.Automate email management using this n8n workflow. Get instant, AI-generated, casual summaries of incoming Gmail messages sent directly to Telegram via GPT-4o.

Use this powerful n8n workflow to automate the screening of Upwork job alerts. It utilizes a Gmail n8n trigger and OpenRouter AI to score job compatibility, sending only high-fit opportunities to Slack.

Use this robust n8n workflow template to automatically export specific Gmail messages, parse key data points, convert them to CSV, and save the resulting file securely to Google Drive.

Automate customer support intake using this powerful n8n workflow. It listens for specific Gmail messages, instantly creates Zendesk tickets, and logs all transaction details to Google Sheets for tracking. Deploy this essential n8n template today!

Use this powerful n8n workflow to automatically capture new emails from Gmail, leverage GPT-4o-mini via Azure OpenAI for intelligent prioritization and summary, create structured Zendesk tickets, and maintain an audit log in Google Sheets. Streamline your support operations with this advanced n8n automation.








































