Complete RAG System with Automatic Source Citations Using Qdrant and Gemini - n8n Workflow

Implement a robust Retrieval-Augmented Generation (RAG) system using Qdrant vector database, Google Gemini, and OpenAI. This complete n8n workflow template enables automatic source citations from Google Drive documents.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data scientists and developers looking for robust, production-ready RAG n8n templates.
Businesses needing highly accurate, verifiable AI answers based on internal documents.
Users who want to integrate specialized tools like Qdrant into an automated n8n workflow.
Anyone requiring complex AI orchestration managed through a visual, low-code n8n node approach.

Overview

This comprehensive n8n workflow implements a state-of-the-art Retrieval-Augmented Generation (RAG) system designed to deliver accurate, contextually grounded answers while automatically citing sources. It addresses the challenge of LLM hallucination by ensuring answers are generated strictly based on provided documents stored in Google Drive.

The initial phase uses the Google Drive n8n node to fetch documents, which are then chunked and vectorized using the OpenAI embeddings n8n node. These vectors are securely stored in the Qdrant vector database. When a query is received via the chat n8n trigger, the workflow retrieves the most relevant knowledge, feeds it to the Google Gemini large language model, and uses custom logic within an n8n node to extract and deduplicate the source document names, making this a powerful and reliable n8n template for knowledge management.

How it Works

This n8n workflow operates in two distinct phases: Ingestion/Indexing and Query/Retrieval.

Ingestion Phase (Indexing)


  1. Start: The process begins with the When clicking ‘Test workflow’ manual n8n trigger.

  2. Cleanup & Load: An initial HTTP Request n8n node clears the target Qdrant collection. The Google Drive n8n node then fetches a list of files from a designated source folder.

  3. Iteration: The Loop Over Items n8n node ensures each file is processed sequentially. For every file, the Google Drive n8n node downloads the content as plain text.

  4. Vector Preparation: The Default Data Loader registers the document, attaching crucial metadata (File ID and File Name) used for citations. The Recursive Character Text Splitter chops the text into optimized segments.

  5. Embedding: The Embeddings OpenAI1 n8n node converts these text chunks into high-dimensional vectors.

  6. Storage: The Qdrant Vector Store n8n node inserts the vectors and their associated metadata into the specified Qdrant collection.

Query Phase (RAG)


  1. Query Input: The When chat message received n8n trigger listens for user questions, initiating the retrieval process.

  2. Retrieval: The query is embedded (using Embeddings OpenAI4), and the Retrive sources Qdrant n8n node performs a similarity search, fetching the top 5 relevant document chunks (topK: 5).

  3. LLM Chain: The retrieved context, including the chunk metadata, is routed to the Question and Answer Chain n8n node. This chain uses the powerful Google Gemini Chat Model n8n node to synthesize the final answer.

  4. Source Aggregation: An Aggregate n8n node collects all file IDs and names from the retrieved context. A custom Code n8n node then processes this list to extract and return only the unique file names, ensuring accurate and non-redundant citations.

  5. Output: The final Set n8n node constructs the response, combining the generated text with the list of unique sources (file names), delivering a complete and verifiable response generated by the n8n workflow.

Installation Guide

To deploy this powerful RAG n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON data and paste it into your n8n instance using the 'New' > 'Import workflow from JSON' option.

  2. OpenAI Credentials: Set up your OpenAI API key credentials for the Embeddings OpenAI n8n nodes, necessary for generating vector representations.

  3. Google Gemini Credentials: Configure your Google Gemini (PaLM) API key for the Google Gemini Chat Model n8n node.

  4. Qdrant Setup: You will need two Qdrant credentials:

One for the Qdrant API connection used by the LangChain vector store n8n node (API Key and Host).
One for the generic HTTP Header Auth used by the Clear collection and Create collection n8n nodes (Host URL and API Key).

  1. Qdrant URLs: In the Create collection and Clear collection HTTP Request n8n nodes, replace QDRANTURL and COLLECTION placeholders in the URL and JSON body with your actual Qdrant instance URL and desired collection name.

  2. Google Drive Setup: Configure your Google Drive OAuth2 credentials and ensure the Get folder n8n node is pointed to the folder containing your source documents (PDFs, Docs, etc.).

  3. Execution: Run the Ingestion Phase manually (using the test trigger) once to load documents into Qdrant before using the Chat Trigger for live queries.

Node Details

Manual Trigger & Chat Trigger: The When clicking ‘Test workflow’ n8n trigger initializes the document ingestion phase. The When chat message received n8n trigger is the dedicated entry point for handling user queries in the RAG system.
Google Drive (Get folder/Get file): These n8n nodes manage document acquisition, fetching file lists and downloading individual document content for processing.
HTTP Request (Clear collection): This n8n node interacts directly with the Qdrant API to clear the vector collection before a fresh ingestion run, ensuring data hygiene.
Embeddings OpenAI: The dedicated n8n node responsible for transforming raw text chunks into numerical vector embeddings, using the standard text-embedding-ada-002 model expected by Qdrant.
Recursive Character Text Splitter: A LangChain n8n node that efficiently splits large documents into smaller, contextual chunks (500 size, 50 overlap), optimizing retrieval accuracy.
Qdrant Vector Store: This specialized n8n node handles both the data insertion (indexing phase) and the vector similarity search (retrieval phase) against the Qdrant vector database.
Google Gemini Chat Model: The n8n node providing the final generation capabilities, using the Gemini 1.5 Flash model to synthesize answers based on the context retrieved by the RAG system.
Code (Response): A critical custom n8n node using JavaScript to deduplicate and format the source file names gathered during retrieval, ensuring that the final output includes accurate and clean citations.

Related n8n Workflows

Free

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

Full-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at [email protected] or add me on Linkedin.com/in/davideboizza

Featured*