Context-Aware RAG Indexing from Google Drive to Pinecone - n8n Workflow

Use this advanced n8n workflow to automate RAG data preparation. It pulls documents from Google Drive, uses an AI agent (via OpenRouter/Gemini) for context-aware chunking, and indexes the enriched vectors in Pinecone. Leverage powerful n8n templates for superior vector search.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • RAG Developers and ML Engineers focused on improving vector search recall.

  • Data scientists needing to preprocess large documents efficiently.

  • Users looking for advanced n8n templates integrating LangChain components.

  • Businesses requiring automated document processing pipelines using the Google Drive n8n node.

  • Anyone seeking a robust n8n workflow for vector database management.

Overview

Traditional Retrieval-Augmented Generation (RAG) pipelines often suffer from poor retrieval quality because simple text splitting loses crucial document context. This innovative n8n workflow solves this by implementing context-aware chunking.

Using a powerful combination of Google Drive, an OpenRouter-powered AI Agent, and Pinecone, the n8n workflow ensures that every text chunk is preceded by an AI-generated summary of its place within the full document. This drastically improves vector search results.

This specific n8n template demonstrates how to leverage custom code and multiple AI components—including the Google Gemini embeddings n8n node—to create a sophisticated data ingestion pipeline, providing a huge boost in data fidelity for your vector store.

How it Works

The n8n workflow initiates manually via the n8n trigger:


  1. Document Retrieval: The process starts when the manual n8n trigger runs, initiating the Get Document From Google Drive n8n node to download a specified file. The file is converted to plain text.

  2. Custom Splitting: A Split Document Text Into Sections Code n8n node uses a hardcoded separator ([SECTIONEND]) to logically divide the document into pre-defined sections. This prepares the data for focused looping.

  3. Looping: The Prepare Sections For Looping and Loop Over Items n8n nodes ensure that each section of the document is processed individually.

  4. Context Generation: For each section, the AI Agent - Prepare Context n8n node is invoked. Using the OpenRouter Chat Model as the underlying large language model (LLM), the agent analyzes the current chunk alongside the full original document text, generating a succinct context summarizing the chunk's content.

  5. Data Enrichment: The Concatenate the context and section text n8n node combines the newly generated AI context with the original section text into a single, enriched section_chunk.

  6. Vectorization: This enriched chunk is then passed to the Pinecone Vector Store n8n node. The vectorization itself is performed by the Embeddings Google Gemini n8n node, which translates the context-aware text into high-dimensional vectors.

  7. Indexing: Finally, the Pinecone n8n node inserts the vector and its metadata into the specified Pinecone index (context-rag-test), completing the RAG data ingestion phase of the n8n workflow.

Installation Guide

To install and utilize this sophisticated n8n workflow template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON and import it directly into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Google Drive Setup: Configure the Google Drive n8n node credential. Ensure the service account or OAuth application has access to the document ID specified in the workflow.

  3. Pinecone Credential: Set up credentials for the Pinecone Vector Store n8n node. Update the 'pineconeIndex' parameter to match your desired index name.

  4. Google Gemini Embeddings: Provide the necessary API key for the Google Gemini (PaLM) credential required by the Embeddings Google Gemini n8n node.

  5. OpenRouter Setup: Configure the API key for the OpenRouter n8n node. This powers the AI Agent that generates the context.

  6. Testing: Click the 'Test workflow' n8n trigger button to execute the pipeline. Note that the custom splitting logic relies on the document containing the specific separator —---------------------------—-------------[SECTIONEND]—---------------------------—------------- to function correctly.

Node Details

This n8n workflow utilizes several specialized and core n8n node types:

Manual Trigger: The starting n8n trigger point for manual execution.
Google Drive (Get Document From Google Drive): Downloads the specified Google Document and is configured to convert the file to text/plain format.
Code (Split Document Text Into Sections): A custom n8n node using JavaScript to split the document text based on a unique delimiter, enabling logical chunking.
AI Agent (AI Agent - Prepare Context): A LangChain n8n node that uses an LLM (powered by OpenRouter) and a specific prompt to generate contextual summaries for each text chunk.
OpenRouter Chat Model: Serves as the language model provider for the AI agent, demonstrating flexibility in LLM integration within an n8n workflow.
Set (Concatenate the context and section text): A core n8n node used to combine the AI-generated context and the original text section, creating the final enriched chunk (section_chunk) ready for embedding.
Embeddings Google Gemini: The specific n8n node responsible for converting the enriched text data into high-quality vectors using the models/text-embedding-004 model.
Pinecone Vector Store: The final destination n8n node, configured in insert mode to store the generated vectors into the 'context-rag-test' index, thereby completing the data ingestion phase of this critical n8n workflow.

Related n8n Workflows

Free

Nodes: 14 Nodes
Updated: December 26 2025
View all
Created by

Hi, I’m Udit, an Acquia-certified developer with a strong background in web development and creating enterprise solutions. Recently, I’ve transitioned into AI and ML, I hold DIAT Professional AI Certification. I specialize in building AI-driven automation to streamline workflows, improve efficiency, and solve complex problems. With expertise in AI/ML tools and years of experience in Acquia and Drupal, I’m passionate about leveraging tech to drive innovation and create smarter solutions.

Featured*