This workflow follows the HTTP Request → Postgres 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 →
{
"name": "Question Answering Workflow",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "ask",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "// Extract query from request\nconst query = $input.body.query;\n\nif (!query) {\n throw new Error('Query is required');\n}\n\nreturn { query };"
},
"name": "Extract Query",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
450,
300
]
},
{
"parameters": {
"url": "={{$env.PYTHON_SERVICE_URL}}/generate-embedding",
"method": "POST",
"sendBody": true,
"bodyParametersUi": {
"parameter": [
{
"name": "text",
"value": "={{ $node[\"Extract Query\"].json.query }}"
}
]
},
"options": {}
},
"name": "Generate Query Embedding",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
650,
300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "=SELECT content, metadata, 1 - (embedding <=> '{{$node[\"Generate Query Embedding\"].json.embedding}}') as similarity\nFROM document_vectors\nWHERE 1 - (embedding <=> '{{$node[\"Generate Query Embedding\"].json.embedding}}') > 0.7\nORDER BY similarity DESC\nLIMIT 5;"
},
"name": "Similarity Search",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
850,
300
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"functionCode": "// Prepare for Gemini\nconst query = $input.json.query;\nconst relevantDocs = $node[\"Similarity Search\"].json;\n\n// Create context from relevant documents\nconst context = relevantDocs.map(doc => doc.content).join('\\n\\n');\n\n// Format prompt for Gemini\nconst prompt = `\nYou are a helpful assistant that answers questions based on the following context.\nIf the answer cannot be found in the context, say \"I don't have enough information to answer that question.\"\nDo not make up or hallucinate information not in the context.\n\nCONTEXT:\n${context}\n\nQUESTION:\n${query}\n\nANSWER:\n`;\n\nreturn { prompt, relevantDocs };"
},
"name": "Prepare Prompt",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1050,
300
]
},
{
"parameters": {
"url": "https://generativelanguage.googleapis.com/v1/models/gemini-2.0-flash:generateContent",
"options": {
"params": {
"key": "={{$env.GEMINI_API_KEY}}"
}
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "contents",
"value": "={{ [{\"parts\":[{\"text\":$node[\"Prepare Prompt\"].json.prompt}]}] }}"
}
]
}
},
"name": "Ask Gemini",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
1250,
300
]
},
{
"parameters": {
"functionCode": "// Extract the answer from Gemini response\nconst geminiResponse = $input.json;\nconst relevantDocs = $node[\"Prepare Prompt\"].json.relevantDocs;\n\nlet answer = \"Sorry, I couldn't generate an answer.\";\n\nif (geminiResponse && geminiResponse.candidates && geminiResponse.candidates[0] && \n geminiResponse.candidates[0].content && geminiResponse.candidates[0].content.parts) {\n answer = geminiResponse.candidates[0].content.parts[0].text;\n}\n\nreturn {\n answer,\n sources: relevantDocs.map(doc => ({\n content: doc.content.substring(0, 200) + '...',\n metadata: doc.metadata\n }))\n};"
},
"name": "Format Response",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1450,
300
]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "=$node[\"Format Response\"].json"
},
"name": "Respond",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
1650,
300
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Extract Query",
"type": "main",
"index": 0
}
]
]
},
"Extract Query": {
"main": [
[
{
"node": "Generate Query Embedding",
"type": "main",
"index": 0
}
]
]
},
"Generate Query Embedding": {
"main": [
[
{
"node": "Similarity Search",
"type": "main",
"index": 0
}
]
]
},
"Similarity Search": {
"main": [
[
{
"node": "Prepare Prompt",
"type": "main",
"index": 0
}
]
]
},
"Prepare Prompt": {
"main": [
[
{
"node": "Ask Gemini",
"type": "main",
"index": 0
}
]
]
},
"Ask Gemini": {
"main": [
[
{
"node": "Format Response",
"type": "main",
"index": 0
}
]
]
},
"Format Response": {
"main": [
[
{
"node": "Respond",
"type": "main",
"index": 0
}
]
]
}
}
}
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.
postgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Question Answering Workflow. Uses httpRequest, postgres. Webhook trigger; 8 nodes.
Source: https://github.com/RaghavGupta-01/pdf-rag-app/blob/a76b1cda308e6b4ef824cc91c45e79b188846939/n8n-workflows/qa-workflow.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This template is for developers, teams, and automation enthusiasts who want a private, PIN-protected Telegram chatbot that answers questions from their own documents — without relying on external AI A
Eu Clara – Funil Kiwify Completo. Uses postgres, openAi, httpRequest, gmail. Webhook trigger; 70 nodes.
Lua Nova - Sistema Completo. Uses postgres, httpRequest, openAi. Webhook trigger; 55 nodes.
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
Jambvant Hindi Voice Bot. Uses httpRequest, deepl, postgres, openai. Webhook trigger; 22 nodes.