If you have ever built a RAG (Retrieval-Augmented Generation) system, you know the typical headache: setting up a Python script to chunk text, running an embedding model, pushing vectors to Pinecone or Supabase, and managing the retrieval logic.

The Gemini File Search API changes the game. It abstracts the entire vector database layer. You simply upload a file, and Google handles the chunking, embedding, and retrieval infrastructure—often at a fraction of the cost of dedicated vector stores.

In this guide, I will walk you through the n8n workflow provided in the Gemini File Search.json file. This workflow does not just chat with PDFs; it includes a full Automated Evaluation pipeline to benchmark your agent’s accuracy against a ground truth dataset.

Share by Nate Herk

The Workflow Architecture

The provided n8n JSON is split into three distinct logic flows:

  1. Ingestion: Creating a “File Store” and uploading documents.
  2. The Agent: A chat interface that queries the documents using Gemini’s native tooling.
  3. Evaluation: An automated loop that reads questions from Google Sheets, queries the agent, and uses an LLM to grade the answer’s accuracy.

Part 1: Setup & Ingestion (The Manual & Form Triggers)

Before we can chat, we need to get data into Google’s infrastructure. In the workflow, this is handled by two specific branches.

Step 1: Create the File Store

  • Node: Create File Store (HTTP Request)
  • Trigger: When clicking ‘Execute workflow’
  • The Logic: This sends a POST request to files.stores.create. It creates a logical bucket (a “Store”) to hold your files.
  • Critical Action: When you run this node once, it returns a name (Store ID). You must copy this ID. You will need to hardcode this ID into the “Knowledge Base” tool nodes later in the workflow.

Step 2: Upload and Import

  • Node: Upload File connected to Import File.
  • Trigger: On form submission.
  • The Logic:
    1. Upload: The workflow takes the binary file from the form and sends it to the upload/v1beta/files endpoint. At this stage, the file is on Google Cloud but not yet indexed.
    2. Import: The workflow immediately takes the result of the upload and sends it to the :importFile endpoint.
    3. Result: This links the raw file to the Store ID created in Step 1, triggering Google’s automatic indexing process.

Part 2: The RAG Agent (Chat Trigger)

This section controls the actual conversation logic.

  • Trigger: When chat message received.
  • The Brain: RAG Agent (AI Agent Node).
  • The Tool: Knowledge Base (HTTP Request Tool).

The “Knowledge Base” Tool Configuration

Instead of using a Vector Store node, this workflow uses a custom HTTP Request Tool that calls the Gemini generateContent API directly.

If you look at the JSON body in the Knowledge Base node, you will see this specific structure:

"tools": [
    {
      "file_search": {
        "file_search_store_names": [
          "YOUR FILE STORE"
        ]
      }
    }
]

Setup Requirement: You must replace "YOUR FILE STORE" with the actual Resource ID you generated in Step 1 (e.g., corpora/123456789). This tells the model: “When the user asks a question, look inside this specific folder.”

Part 3: Automated Evaluation (The Secret Sauce)

This is the most advanced part of the workflow. Instead of guessing if your RAG agent is accurate, this flow scientifically tests it.

1. The Test Dataset

  • Node: When fetching a dataset row.
  • Source: Connects to a Google Sheet containing columns for Input (The Question) and Expected Answer (The Ground Truth).

2. The Test Run

  • Node: Eval Agent.
  • Logic: This is a clone of the main RAG Agent. It takes the Input from the Google Sheet and queries the Gemini File Search tool to get an answer.

3. The Judge (LLM Grading)

  • Node: Evaluation.
  • Logic: This node uses a separate LLM (connected via OpenRouter in the workflow) to act as a judge. It compares two things:
    1. The Actual Answer generated by the Eval Agent.
    2. The Expected Answer from the Google Sheet.
  • Scoring: It assigns a score (1-5) based on factual accuracy and provides “Extended Reasoning” for why it gave that score.

4. Reporting

  • Node: Set Metrics.
  • Logic: The workflow writes the calculated Score back into the Google Sheet. This allows you to run a batch of 50 questions and instantly see if your agent is performing at a 3/5 or a 5/5 level.

Implementation Checklist

To get this .json file working, follow these steps:

  1. API Keys: You need a Google Gemini API Key (for the HTTP requests) and an OpenRouter API Key (for the LLM nodes).
  2. Create the Store: Run the manual trigger path once. Copy the resulting Store Name/ID.
  3. Update Tool Nodes: Go to the nodes named Knowledge Base and Knowledge Base1. Open the JSON body and replace "YOUR FILE STORE" with your copied ID.
  4. Google Sheets: Create a sheet with headers Input, Expected Answer, and Score. Link this sheet to the When fetching a dataset row and Set Metrics nodes.
  5. Upload Data: Use the Form URL provided by n8n to upload your PDF documents.

Why This Approach Wins

  • Zero Vector Database Cost: You are not paying monthly fees for Pinecone or Weaviate.
  • Built-in Grounding: Gemini returns citations (source chunks) automatically, reducing hallucinations.
  • Quality Assurance: The inclusion of the Evaluation flow means you aren’t just building an agent; you are building a tested and verified system.

This workflow represents a modern “DevOps for AI” approach—combining ingestion, deployment, and testing into a single n8n canvas.

You may also like

Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments