Skip to main content

Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI

Workflow preview

Workflow preview
100%
Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow implements a Retrieval Augmented Generation (RAG) system that: Stores vectorized documents in Qdrant , Retrieves relevant content based on user input, Generates AI answers using Googl...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.manualtrigger, @n8n/n8n-nodes-langchain.embeddingsopenai, @n8n/n8n-nodes-langchain.documentdefaultdataloader, @n8n/n8n-nodes-langchain.vectorstoreqdrant, n8n-nodes-base.httprequest, @n8n/n8n-nodes-langchain.textsplitterrecursivecharactertextsplitter, n8n-nodes-base.splitinbatches, n8n-nodes-base.wait

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Davide.

Original n8n.io source

1.1 Workflow description

Title
Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI
Workflow name
Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI

This workflow implements a Retrieval-Augmented Generation (RAG) system that:

  • Stores vectorized documents in Qdrant,
  • Retrieves relevant content based on user input,
  • Generates AI answers using Google Gemini,
  • Automatically cites the document sources (from Google Drive).

Workflow Steps

  1. Create Qdrant Collection A REST API node creates a new collection in Qdrant with specified vector size (1536) and cosine similarity.

  2. Load Files from Google Drive The workflow lists all files in a Google Drive folder, downloads them as plain text, and loops through each.

  3. Text Preprocessing & Embedding

    • Documents are split into chunks (500 characters, with 50-character overlap).
    • Embeddings are created using OpenAI embeddings (text-embedding-3-small assumed).
    • Metadata (file name and ID) is attached to each chunk.
  4. Store in Qdrant All vectors, along with metadata, are inserted into the Qdrant collection.

  5. Chat Input & Retrieval

    • When a chat message is received, the question is embedded and matched against Qdrant.
    • Top 5 relevant document chunks are retrieved.
    • A Gemini model is used to generate the answer based on those sources.
  6. Source Aggregation & Response

    • File IDs and names are deduplicated.

    • The AI response is combined with a list of cited documents (filenames).

    • Final output:

      AI Response
      
      Sources: ["Document1", "Document2"]
      

Main Advantages

  • End-to-end Automation: From document ingestion to chat response generation, fully automated with no manual steps.
  • Scalable Knowledge Base: Easy to expand by simply adding files to the Google Drive folder.
  • Traceable Responses: Each answer includes its source files, increasing transparency and trustworthiness.
  • Modular Design: Each step (embedding, storage, retrieval, response) is isolated and reusable.
  • Multi-provider AI: Combines OpenAI (for embeddings) and Google Gemini (for chat), optimizing performance and flexibility.
  • Secure & Customizable: Uses API credentials and configurable chunk size, collection name, etc.

How It Works

  1. Document Processing & Vectorization

    • The workflow retrieves documents from a specified Google Drive folder.
    • Each file is downloaded, split into chunks (using a recursive text splitter), and converted into embeddings via OpenAI.
    • The embeddings, along with metadata (file ID and name), are stored in a Qdrant vector database under the collection negozio-emporio-verde.
  2. Query Handling & Response Generation

    • When a user submits a chat message, the workflow:
      • Embeds the query using OpenAI.
      • Retrieves the top 5 relevant document chunks from Qdrant.
      • Uses Google Gemini to generate a response based on the retrieved context.
      • Aggregates and deduplicates the source file names from the retrieved chunks.
    • The final output includes both the AI-generated response and a list of source documents (e.g., Sources: ["FAQ.pdf", "Policy.txt"]).

Set Up Steps

  1. Configure Qdrant Collection

    • Replace QDRANTURL and COLLECTION in the "Create collection" HTTP node to initialize the Qdrant collection with:
      • Vector size: 1536 (OpenAI embedding dimension).
      • Distance metric: Cosine.
    • Ensure the "Clear collection" node is configured to reset the collection if needed.
  2. Google Drive & OpenAI Integration

    • Link the Google Drive node to the target folder (Test Negozio in this example).
    • Verify OpenAI and Google Gemini API credentials are correctly set in their respective nodes.
  3. Metadata & Output Customization

    • Adjust the "Aggregate" and "Response" nodes if additional metadata fields are needed.
    • Modify the "Output" node to format the response (e.g., changing Sources: {{...}} to match your preferred style).
  4. Testing

    • Trigger the workflow manually to test document ingestion.
    • Use the chat interface to verify responses include accurate source attribution.

Note: Replace placeholder values (e.g., QDRANTURL) with actual endpoints before deployment.


Need help customizing?

Contact me for consulting and support or add me on Linkedin.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When clicking ‘Test workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 2 - Embeddings OpenAI1

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.1

Block 3 - Default Data Loader1

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 4 - Qdrant Vector Store

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1

Block 5 - Create collection

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 6 - Recursive Character Text Splitter

Type / Role
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - textSplitterRecursiveCharacterTextSplitter
Config choices
Version 1

Block 7 - Loop Over Items

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 8 - Wait

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 9 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 10 - Question and Answer Chain

Type / Role
@n8n/n8n-nodes-langchain.chainRetrievalQa - chainRetrievalQa
Config choices
Version 1.5

Block 11 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 12 - Vector Store Retriever

Type / Role
@n8n/n8n-nodes-langchain.retrieverVectorStore - retrieverVectorStore
Config choices
Version 1

Block 13 - Qdrant Vector Store1

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1.1

Block 14 - Embeddings OpenAI

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 15 - Embeddings OpenAI4

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 16 - Merge1

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 17 - Aggregate

Type / Role
n8n-nodes-base.aggregate - aggregate
Config choices
Version 1

Block 18 - Clear collection

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 19 - Get folder

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 20 - Get file

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 21 - chatInput

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 22 - Retrive sources

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1.1

Block 23 - Output

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 24 - Response

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Showing the first 24 of 29 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI
Complexity advanced
Nodes 29
Categories Internal Wiki, AI RAG
Author Davide
Published 18 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5023/5023.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Build a RAG system with automatic citations using Qdrant, Gemini & OpenAI do?

This workflow implements a Retrieval Augmented Generation (RAG) system that: Stores vectorized documents in Qdrant , Retrieves relevant content based on user input, Generates AI answers using Googl...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.