Integrating n8n with GCP for Document Management
This mirrors the Azure RAG architecture but uses Google Cloud Platform services — Vertex AI for embeddings, Vertex AI Search (or AlloyDB/Cloud SQL with pgvector) for vector storage, and n8n as the orchestration layer.
The Full Architecture
Your Documents (PDFs, Docs, Sheets) ↓ Google Cloud Storage (GCS) ↓ Document AI / Dataflow (chunk + clean) ↓ Vertex AI Embeddings (text → vector) ↓ Vertex AI Search / pgvector (store vectors) ↓ n8n Workflow ↓ User gets grounded answer + sources
GCP Services Mapping
| Azure Service | GCP Equivalent | Role |
|---|---|---|
| Azure Data Lake | Google Cloud Storage (GCS) | Store raw documents |
| Azure Data Factory | Cloud Dataflow / Document AI | Process & chunk text |
| Azure OpenAI Embeddings | Vertex AI Embeddings | Convert text → vectors |
| Azure AI Search | Vertex AI Search / pgvector | Store & search vectors |
| Azure OpenAI Chat | Vertex AI Gemini / PaLM | Generate answers |
| n8n | n8n | Orchestrate everything |
Step-by-Step Implementation
Step 1 — Store Documents in GCS
Upload all your PDFs, Word docs, and text files to a GCS bucket:
# Create a bucketgsutil mb gs://my-company-docs# Upload documentsgsutil cp *.pdf gs://my-company-docs/raw/
Bucket structure:
gs://my-company-docs/ ├── raw/ ← original documents ├── processed/ ← cleaned text chunks └── embeddings/ ← vector JSON files
Step 2 — Process & Chunk Documents
Use Google Document AI to extract clean text from PDFs, then split into chunks:
# Cloud Function or Dataflow jobfrom google.cloud import documentai, storagedef chunk_document(text, chunk_size=500, overlap=50): words = text.split() chunks = [] for i in range(0, len(words), chunk_size - overlap): chunk = " ".join(words[i:i + chunk_size]) chunks.append({ "chunk_id": f"chunk_{i}", "text": chunk, "source": "refund_policy.pdf", "page": i // chunk_size + 1 }) return chunks
Output chunk format:
{ "chunk_id": "refund_policy_001", "text": "Refunds are available within 30 days of purchase...", "source": "refund_policy.pdf", "page": 1, "metadata": { "department": "finance", "last_updated": "2026-01-15" }}
Step 3 — Generate Embeddings with Vertex AI
Call the Vertex AI Embeddings API to convert each chunk into a vector:
# REST API callPOST https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_PROJECT/ locations/us-central1/publishers/google/models/text-embedding-004:predictHeaders: Authorization: Bearer $(gcloud auth print-access-token) Content-Type: application/jsonBody:{ "instances": [ { "content": "Refunds are available within 30 days of purchase..." } ]}
Response:
{ "predictions": [ { "embeddings": { "values": [0.023, -0.841, 0.334, ...], "statistics": { "truncated": false, "token_count": 42 } } } ]}
Vertex AI embedding models:
| Model | Dimensions | Best for |
|---|---|---|
text-embedding-004 | 768 | General text, RAG |
text-multilingual-embedding-002 | 768 | Multi-language docs |
text-embedding-preview-0815 | 768 | Latest preview |
Step 4 — Store Vectors
You have two main options on GCP:
Option A — Vertex AI Search (fully managed)
# Create a data storegcloud alpha discovery-engine data-stores create \ --project=YOUR_PROJECT \ --location=global \ --display-name="company-docs" \ --industry-vertical=GENERIC \ --solution-types=SOLUTION_TYPE_SEARCH
Option B — AlloyDB / Cloud SQL with pgvector (more control)
-- Enable pgvector extensionCREATE EXTENSION vector;-- Create table with vector fieldCREATE TABLE document_chunks ( chunk_id TEXT PRIMARY KEY, text TEXT, source TEXT, page INT, metadata JSONB, embedding VECTOR(768) -- matches Vertex AI output dimensions);-- Create HNSW index for fast similarity searchCREATE INDEX ON document_chunksUSING hnsw (embedding vector_cosine_ops)WITH (m = 16, ef_construction = 64);
Insert a chunk with its vector:
INSERT INTO document_chunks (chunk_id, text, source, embedding)VALUES ( 'refund_policy_001', 'Refunds are available within 30 days...', 'refund_policy.pdf', '[0.023, -0.841, 0.334, ...]'::vector);
Step 5 — Build the n8n Workflow
The n8n workflow has these nodes:
Webhook Trigger ↓HTTP Request → Vertex AI Embeddings ↓HTTP Request → pgvector / Vertex AI Search ↓Code Node → Format retrieved context ↓HTTP Request → Vertex AI Gemini (chat) ↓Respond to Webhook
Step 6 — Webhook Receives User Question
Incoming request to n8n:
{ "question": "What is the refund policy?", "user_id": "user_123"}
Step 7 — n8n Calls Vertex AI Embeddings
HTTP Request node configuration:
Method: POSTURL: https://us-central1-aiplatform.googleapis.com/v1/projects/ {{ $env.GCP_PROJECT }}/locations/us-central1/publishers/google/ models/text-embedding-004:predictHeaders: Authorization: Bearer {{ $env.GCP_ACCESS_TOKEN }} Content-Type: application/jsonBody:{ "instances": [ { "content": "{{ $json.question }}" } ]}
Output stored in state:
{ "query_vector": [0.021, -0.834, 0.291, ...] }
Step 8 — n8n Searches pgvector
HTTP Request node (calling Cloud SQL proxy or AlloyDB REST):
-- n8n Code Node generates this querySELECT chunk_id, text, source, page, 1 - (embedding <=> '[0.021, -0.834, 0.291, ...]'::vector) AS similarityFROM document_chunksORDER BY embedding <=> '[0.021, -0.834, 0.291, ...]'::vectorLIMIT 5;
pgvector distance operators:
| Operator | Metric | Use case |
|---|---|---|
<=> | Cosine distance | Text similarity (recommended) |
<-> | Euclidean distance | Image embeddings |
<#> | Negative dot product | Normalized vectors |
Results returned:
[ { "chunk_id": "refund_policy_001", "text": "Refunds are available within 30 days...", "source": "refund_policy.pdf", "similarity": 0.97 }, { "chunk_id": "returns_guide_003", "text": "To initiate a return, visit our portal...", "source": "returns_guide.pdf", "similarity": 0.81 }]
Step 9 — Format Context in n8n Code Node
// n8n Code Nodeconst results = items[0].json.results;const question = $node["Webhook Trigger"].json.question;const context = results .map(r => `Source: ${r.source} (Page ${r.page})\nContent: ${r.text}`) .join("\n\n---\n\n");return [{ json: { question: question, context: context, sources: results.map(r => r.source) }}];
Step 10 — Send Grounded Prompt to Vertex AI Gemini
HTTP Request node:
Method: POSTURL: https://us-central1-aiplatform.googleapis.com/v1/projects/ {{ $env.GCP_PROJECT }}/locations/us-central1/publishers/google/ models/gemini-1.5-pro:generateContentBody:{ "contents": [{ "role": "user", "parts": [{ "text": "You are an internal company assistant.\nAnswer ONLY using the context below.\nIf the answer is not in the context, say: I don't know.\nAlways cite the source document.\n\nContext:\n{{ $json.context }}\n\nQuestion: {{ $json.question }}" }] }], "generationConfig": { "temperature": 0.2, "maxOutputTokens": 512 }}
Step 11 — Return Answer to User
n8n Respond to Webhook node:
{ "answer": "Refunds are available within 30 days of purchase. To initiate a return, visit our returns portal.", "sources": ["refund_policy.pdf", "returns_guide.pdf"], "confidence": "high"}
Complete n8n Workflow Diagram
┌─────────────────────────────────────────────────────────┐│ n8n WORKFLOW ││ ││ [Webhook]──→[Vertex AI Embed]──→[pgvector Search] ││ ↓ ││ [Code: Format] ││ ↓ ││ [Gemini Chat] ││ ↓ ││ [Respond] │└─────────────────────────────────────────────────────────┘
GCP vs Azure — Side by Side
| Step | Azure | GCP |
|---|---|---|
| Document storage | Azure Data Lake | Google Cloud Storage |
| Text extraction | Azure Form Recognizer | Document AI |
| Chunking | Azure Data Factory | Cloud Dataflow / Functions |
| Embedding model | text-embedding-ada-002 | text-embedding-004 |
| Vector dimensions | 1,536 | 768 |
| Vector store | Azure AI Search | AlloyDB pgvector / Vertex AI Search |
| Search algorithm | HNSW (built-in) | HNSW via pgvector |
| LLM | Azure OpenAI Chat | Vertex AI Gemini |
| Orchestration | n8n | n8n |
Security Best Practices on GCP
n8n running on GCP VM / Cloud Run ↓Uses Workload Identity (no hardcoded keys) ↓Accesses GCS, Vertex AI, AlloyDBvia IAM roles: - roles/aiplatform.user - roles/storage.objectViewer - roles/cloudsql.client
Store secrets in Google Secret Manager, not in n8n environment variables directly:
# Store API credentials securelygcloud secrets create vertex-ai-key --data-file=key.json# n8n fetches at runtime via HTTP Request nodeGET https://secretmanager.googleapis.com/v1/projects/YOUR_PROJECT/ secrets/vertex-ai-key/versions/latest:access
Key Takeaway
The GCP RAG pipeline with n8n gives you:
- GCS for durable, scalable document storage
- Document AI for accurate PDF/text extraction
- Vertex AI Embeddings for state-of-the-art semantic vectors
- pgvector on AlloyDB for flexible, SQL-native vector search
- Gemini for grounded, citation-aware answer generation
- n8n as the glue — zero custom application code needed
The result is a fully managed, enterprise-grade document Q&A system where every answer is grounded in your actual documents, with sources always cited.