AutomationFlowsAI & RAG › AI Document Q&A RAG Pipeline

AI Document Q&A RAG Pipeline

Original n8n title: Document Q&a RAG Pipeline

Document Q&A RAG Pipeline. Uses openAi, httpRequest. Webhook trigger; 6 nodes.

Webhook trigger★★★★☆ complexityAI-powered6 nodesOpenAIHTTP Request
AI & RAG Trigger: Webhook Nodes: 6 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the HTTP Request → OpenAI recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Document Q&A RAG Pipeline",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ask",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000001",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Convert the following user question into an optimized search query for a vector database. Return ONLY the search query string, no explanation. Focus on key concepts and remove filler words."
            },
            {
              "role": "user",
              "content": "={{ $json.body.question }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1,
          "maxTokens": 128
        }
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000002",
      "name": "Optimize Query",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        500,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/embeddings",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ input: $json.text, model: 'text-embedding-3-small' }) }}",
        "options": {}
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000003",
      "name": "Generate Embedding",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        750,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://your-index-name-abc123.svc.pinecone.io/query",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ vector: $json.data[0].embedding, topK: 5, includeMetadata: true, namespace: 'documents' }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000004",
      "name": "Pinecone Vector Search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1000,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a knowledgeable document assistant. Answer the user's question using ONLY the provided context from our document database. If the context doesn't contain enough information to answer, say so clearly. Always cite which document(s) you're referencing.\n\nRules:\n1. Only use information from the provided context\n2. If uncertain, indicate your confidence level\n3. Quote relevant passages when helpful\n4. If the question cannot be answered from the context, say: \"I don't have enough information in the available documents to answer this question.\""
            },
            {
              "role": "user",
              "content": "=Question: {{ $('Webhook').item.json.body.question }}\n\nRelevant Document Context:\n{{ $json.matches ? $json.matches.map((m, i) => `[Doc ${i+1}] (score: ${m.score.toFixed(3)}) ${m.metadata.source || 'Unknown'}:\\n${m.metadata.text}`).join('\\n\\n') : 'No matching documents found.' }}"
            }
          ]
        },
        "options": {
          "temperature": 0.3,
          "maxTokens": 1024
        }
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000005",
      "name": "OpenAI Answer",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        1250,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ answer: $json.text, question: $('Webhook').item.json.body.question, sources: ($('Pinecone Vector Search').item.json.matches || []).map(m => ({ source: m.metadata.source, score: m.score })) }) }}"
      },
      "id": "a7b8c9d0-7777-4000-8000-000000000006",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1500,
        300
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Optimize Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Optimize Query": {
      "main": [
        [
          {
            "node": "Generate Embedding",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Embedding": {
      "main": [
        [
          {
            "node": "Pinecone Vector Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Search": {
      "main": [
        [
          {
            "node": "OpenAI Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Answer": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Document Q&A RAG Pipeline. Uses openAi, httpRequest. Webhook trigger; 6 nodes.

Source: https://github.com/mlnjsh/n8n-workflows-mega/blob/main/workflows/ai-agents/07-document-qa-rag-pipeline.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This powerful n8n automation workflow is designed to execute advanced B2B lead enrichment and hyper-personalization for cold email outreach. By orchestrating a complex chain of data scraping, AI analy

OpenAI, HTTP Request, Airtable
AI & RAG

Eu Clara – Funil Kiwify Completo. Uses postgres, openAi, httpRequest, gmail. Webhook trigger; 70 nodes.

Postgres, OpenAI, HTTP Request +1
AI & RAG

This workflow bridges the gap between raw product data and revenue sales tools. It automates the entire Product Qualified Lead (PQL) lifecycle—from real-time intent routing to churn prevention—reducin

HTTP Request, Anthropic, OpenAI
AI & RAG

Lua Nova - Sistema Completo. Uses postgres, httpRequest, openAi. Webhook trigger; 55 nodes.

Postgres, HTTP Request, OpenAI
AI & RAG

User Signup & Verification: The workflow starts when a user signs up. It generates a verification code and sends it via SMS using Twilio. Code Validation: The user replies with the code. The workflow

Postgres, HTTP Request, OpenAI +2