BigQuery RAG for Documentation Q&A with OpenAI - n8n Workflow

Deploy a powerful n8n workflow using BigQuery and OpenAI for RAG. Answer user questions instantly based on your documentation using this advanced n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Tech documentation teams seeking to create an automated Q&A assistant.
Automation specialists looking for advanced n8n templates integrating BigQuery and OpenAI.
Users who need to leverage existing BigQuery data infrastructure for Retrieval-Augmented Generation (RAG).
Developers aiming to deploy scalable RAG solutions within the n8n environment.

Overview

This comprehensive n8n workflow addresses the challenge of building a robust RAG system when your enterprise data (documentation) resides in Google BigQuery, and you prefer using OpenAI’s powerful Language Models (LLMs) and embeddings. While BigQuery does not natively integrate with OpenAI Cloud models for RAG, this n8n template bridges that gap.

The primary n8n trigger is a chat interface, making it ideal for immediate user queries. The system operates by intelligently routing the user question to a separate retrieval sub-routine. This sub-routine handles creating the vector embedding using an n8n node, querying BigQuery, and returning the most relevant documents. The main n8n workflow then uses these retrieved documents to formulate an accurate and detailed answer via the AI Agent, formatted specifically for clarity and technical accuracy (Markdown, code blocks, etc.). This powerful n8n workflow maximizes efficiency by leveraging existing infrastructure.

How it Works

This advanced n8n workflow operates in two closely linked phases: the Agent front-end and the BigQuery retrieval back-end.

Phase 1: Agent Interaction


  1. n8n Trigger (Chat Message): The flow starts with the When chat message received n8n trigger, initiating the process upon user input.

  2. AI Agent Activation: The input is passed to the AI Agent n8n node, which is configured with a specialized system prompt for answering questions about n8n documentation and instructed to use an external tool for retrieval.

  3. Tool Call (Retrieval): The AI Agent determines it needs documentation and calls the BigQuery RAG OpenAI tool, passing the user's question as the input (vectorsearchquestion).

Phase 2: BigQuery Retrieval (Sub-routine)


  1. Sub-workflow n8n Trigger: The When Executed by Another Workflow n8n trigger activates the retrieval sub-routine, receiving the question.

  2. Embedding Creation: An OpenAI - Create Embedding n8n node sends the question to the OpenAI API using the text-embedding-3-large model to generate a high-quality vector embedding.

  3. Vector Search: The BigQuery - Vector Retriever n8n node executes a SQL query that leverages BigQuery’s VECTOR_SEARCH functionality. It uses the newly created embedding vector to find the 10 most relevant documents (based on cosine similarity) in the BigQuery vector table.

  4. Data Return: The retrieved documents are formatted and returned to the main n8n workflow.

Phase 3: Answer Generation

The AI Agent receives the retrieved documents and uses the OpenAI Chat Model (GPT-4.1 Mini) along with conversation history (managed by the Simple Memory n8n node) to generate the final, comprehensive, Markdown-formatted response for the user.

Installation Guide

To utilize this n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON data and paste it into your n8n instance via the 'Import from JSON' option to deploy this specialized n8n workflow.

  2. Credentials: Set up the necessary credentials for the external services:

OpenAI API: Configure an OpenAI credential for both the chat model and the embedding creation n8n node.
Google BigQuery OAuth2 API: Set up a Google BigQuery credential (OAuth2 is used for API requests) and ensure it has permissions to query your BigQuery project and tables.

  1. BigQuery Configuration: Locate the BigQuery - Vector Retriever - n8n docs n8n node within the sub-routine.

In the URL field, replace with your specific Google Cloud Project ID.
Ensure the table name in the SQL query (n8n-docs-rag.n8ndocs.n8ndocs_embeddings) is updated if you are using your own custom RAG data source. This powerful n8n template is designed to work with BigQuery vector stores.

  1. Activation: Activate the n8n workflow to enable the chat trigger.

Node Details

When chat message received (n8n Trigger): The starting point of the main n8n workflow. It waits for incoming chat messages to begin the RAG process.
AI Agent (n8n node): Orchestrates the conversation. It uses a detailed system message instructing it to leverage the connected tool and format the output in Markdown. It uses memory for context.
OpenAI Chat Model (n8n node): The Language Model used by the Agent. Configured to use gpt-4.1-mini for cost efficiency in this n8n template.
BigQuery RAG OpenAI (n8n Tool Workflow): This is the crucial connection n8n node that calls the retrieval sub-workflow (the RAG logic) whenever documentation is needed.
When Executed by Another Workflow (n8n Trigger): The n8n trigger for the sub-routine, activated only when called by the AI Agent tool, receiving the vectorsearchquestion.
OpenAI - Create Embedding (n8n node): An HTTP Request n8n node dedicated to calling the OpenAI /v1/embeddings API. It uses the text-embedding-3-large model to convert the question into a vector for the search.
BigQuery - Vector Retriever - n8n docs (n8n node): An HTTP Request n8n node that performs the BigQuery API call. It executes a VECTOR_SEARCH SQL query using the embedding generated by the previous n8n node, retrieving the top 10 relevant documents from the vector store.
Documents retrieved (n8n node): A Set n8n node that bundles the results (rows) from the BigQuery query into a single documents field, preparing them for return to the main AI Agent for final answer synthesis. This step ensures clean data passage back to the main n8n workflow.

Related n8n Workflows

Free

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

I am passionate about transforming complex processes into seamless automations with n8n. My expertise spans across creating ETL pipelines, sales automations, and data & AI-driven workflows. As an avid problem solver, I thrive on optimizing workflows to drive efficiency and innovation.

Featured*