AI Document Q&A Assistant with Google Drive and RAG - n8n Workflow

Use this powerful n8n workflow to create an AI assistant that monitors Google Drive for company documents, automatically processes them into a knowledge base using OpenAI embeddings, and answers user queries via a webhook. Leverage advanced n8n templates for RAG implementation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Companies needing automated internal document support.
Developers building conversational AI interfaces.
Users looking for advanced LangChain and n8n templates.
Anyone wanting to turn unstructured data into a searchable knowledge base using an n8n workflow.

Overview

This sophisticated n8n workflow solves the problem of decentralized knowledge management by creating a real-time, searchable knowledge base directly from Google Drive files. It operates in two parallel streams: document ingestion and AI querying. The ingestion stream ensures that any new document added to a monitored Drive folder is immediately processed, chunked, embedded via OpenAI, and stored. The querying stream uses a webhook as an n8n trigger to receive user questions, which are then routed to an AI Agent. This Agent uses a specialized RAG tool to search the knowledge base before formulating a precise, context-aware response using the power of GPT-4. This approach ensures high accuracy and provides traceable citations, significantly enhancing the utility of the n8n automation solution.

How it Works

This n8n workflow consists of two primary, independent execution paths:

Path 1: Knowledge Base Ingestion (Document Processing)


  1. Watch Company Docs Folder (n8n trigger): This Google Drive n8n trigger node constantly monitors a designated folder for new file uploads.

  2. Fetch New Document: Upon detection, the n8n workflow downloads the document using a Google Service Account credential.

  3. Load Document Content: The LangChain Document Loader prepares the binary file for processing.

  4. Split into Searchable Chunks: A Recursive Character Text Splitter divides the document into smaller, manageable chunks (with 200 character overlap) to optimize retrieval performance.

  5. Generate Document Embeddings: The OpenAI Embeddings n8n node converts the text chunks into numerical vector representations.

  6. Store in Knowledge Base: The vector embeddings are saved into an in-memory vector store, designated by the memory key "company docs".

Path 2: AI Query and Retrieval (Chat Interface)


  1. Receive User Question (n8n trigger): A Webhook n8n trigger listens for POST requests containing the user's question and a sessionid.

  2. Conversation History: The Buffer Window n8n node uses the provided sessionid to maintain context for ongoing conversations.

  3. Search Company Documents: This vector store n8n node is configured as an Agent Tool, allowing the AI to semantically search the "company docs" knowledge base, retrieving the top 5 relevant document chunks.

  4. OpenAI Chat Model: The workflow leverages the gpt-4.1-mini model as the LLM for the Agent.

  5. Company Knowledge Assistant (Agent): The LangChain Agent n8n node orchestrates the process: receiving the query, checking memory, deciding to use the retrieval tool, synthesizing the answer based on the retrieved context, and ensuring compliance with system instructions (citing sources).

  6. Send Answer to User: The final response from the AI Agent is sent back through the Respond to Webhook n8n node.

Installation Guide

To deploy and utilize this powerful n8n workflow using these n8n templates, follow these setup steps:


  1. Import the n8n Workflow: Copy the provided JSON and import it directly into your n8n instance.

  2. Google Drive Trigger Setup:

Provide OAuth2 credentials for the Watch Company Docs Folder n8n trigger.
Select the specific Google Drive folder you wish to monitor for new company documents.

  1. Google Drive Download Setup:

The Fetch New Document n8n node requires a Google Service Account credential for secure document downloads.

  1. OpenAI Credentials:

Ensure your OpenAI API key is connected to both the Generate Document Embeddings n8n node and the OpenAI Chat Model n8n node.

  1. Activate and Test: Activate the n8n workflow. Test the ingestion pipeline by adding a document to the monitored Drive folder. Test the chat interface by sending a POST request to the Webhook URL (e.g., YOURN8NURL/webhook/chat-input) with a JSON body like: {"data": "What is the policy on vacation time?", "sessionid": "testuser_1"}.

Node Details

This n8n workflow relies heavily on the LangChain suite of nodes for sophisticated RAG functionality.

Watch Company Docs Folder (n8n trigger): Triggers the workflow when a file is created in a specified Google Drive folder.
Fetch New Document (Google Drive n8n node): Downloads the detected file's binary content, essential for ingestion.
Store in Knowledge Base (LangChain Vector Store In Memory n8n node): Serves as the vector database. It uses the insert mode to save embeddings under the key company docs.
Generate Document Embeddings (LangChain Embeddings OpenAI n8n node): Converts text into searchable vectors using OpenAI's embedding model.
Conversation History (LangChain Memory Buffer Window n8n node): Manages conversational context, using the incoming session_id to track individual user chats.
Search Company Documents (LangChain Vector Store In Memory n8n node): Configured for RAG. It operates in retrieve-as-tool mode, pulling the top 5 chunks relevant to the user's query from the company docs key.
OpenAI Chat Model (LangChain LLM n8n node): Defines the large language model used for generation, specifically configured to use gpt-4.1-mini.
Company Knowledge Assistant (LangChain Agent n8n node): The core intelligence. It is prompted with strict instructions to use the Search Company Documents tool for accurate, cited answers, providing a powerful layer of AI automation to the n8n setup.

Related n8n Workflows

Free

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

I love building smart n8n automations that actually work reliably. My focus is on making everyday tasks like email, social media, and CRM workflows simpler using AI. I've shared templates in the n8n community, including a WhatsApp Expense Tracker that people really enjoy. What keeps me excited is constantly trying new things - testing fresh nodes, playing with AI tools like LangChain, and discovering creative ways to connect systems!

Featured*