使用PDF向量和Webhooks构建文档问答API
中级
这是一个Internal Wiki, AI RAG, Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 If, Code, Webhook, PdfVector, RespondToWebhook 等节点。 使用PDF向量和Webhooks构建文档问答API
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "placeholder"
},
"nodes": [
{
"id": "overview-note",
"name": "API 概览",
"type": "n8n-nodes-base.stickyNote",
"position": [
50,
50
],
"parameters": {
"color": 5,
"width": 350,
"height": 160,
"content": "## 🤖 文档问答 API"
},
"typeVersion": 1
},
{
"id": "request-note",
"name": "请求格式",
"type": "n8n-nodes-base.stickyNote",
"position": [
450,
450
],
"parameters": {
"width": 280,
"height": 180,
"content": "## 📥 API 请求"
},
"typeVersion": 1
},
{
"id": "process-note",
"name": "问答处理",
"type": "n8n-nodes-base.stickyNote",
"position": [
850,
450
],
"parameters": {
"width": 260,
"height": 160,
"content": "## 🔍 AI 处理"
},
"typeVersion": 1
},
{
"id": "response-note",
"name": "响应格式",
"type": "n8n-nodes-base.stickyNote",
"position": [
1150,
450
],
"parameters": {
"color": 6,
"width": 260,
"height": 180,
"content": "## 📤 API 响应"
},
"typeVersion": 1
},
{
"id": "webhook-trigger",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"notes": "API endpoint for document Q&A",
"position": [
250,
300
],
"webhookId": "doc-qa-webhook",
"parameters": {
"path": "doc-qa",
"httpMethod": "POST"
},
"typeVersion": 1
},
{
"id": "validate-request",
"name": "验证请求",
"type": "n8n-nodes-base.code",
"notes": "Validate and prepare request",
"position": [
450,
300
],
"parameters": {
"jsCode": "// Validate incoming request\nconst body = $input.first().json.body;\nconst errors = [];\n\nif (!body.documentUrl && !body.documentId) {\n errors.push('Either documentUrl or documentId is required');\n}\nif (!body.question) {\n errors.push('Question is required');\n}\n\n// Generate session ID if not provided\nconst sessionId = body.sessionId || `session-${Date.now()}`;\n\nreturn [{\n json: {\n ...body,\n sessionId,\n valid: errors.length === 0,\n errors,\n timestamp: new Date().toISOString()\n }\n}];"
},
"typeVersion": 2
},
{
"id": "check-valid",
"name": "有效请求?",
"type": "n8n-nodes-base.if",
"position": [
650,
300
],
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json.valid }}",
"value2": true
}
]
}
},
"typeVersion": 1
},
{
"id": "pdfvector-ask",
"name": "PDF 向量 - 提问",
"type": "n8n-nodes-pdfvector.pdfVector",
"notes": "Get answer from document",
"position": [
850,
250
],
"parameters": {
"url": "={{ $json.documentUrl }}",
"prompt": "Answer the following question about this document or image: {{ $json.question }}",
"resource": "document",
"inputType": "url",
"operation": "ask"
},
"typeVersion": 1
},
{
"id": "format-success",
"name": "格式化成功响应",
"type": "n8n-nodes-base.code",
"notes": "Prepare successful response",
"position": [
1050,
250
],
"parameters": {
"jsCode": "// Prepare successful response\nconst answer = $json.answer;\nconst request = $node['Validate Request'].json;\n\n// Calculate confidence score based on answer length and keywords\nlet confidence = 0.8; // Base confidence\nif (answer.length > 100) confidence += 0.1;\nif (answer.toLowerCase().includes('specifically') || answer.toLowerCase().includes('according to')) confidence += 0.1;\nconfidence = Math.min(confidence, 1.0);\n\nreturn [{\n json: {\n success: true,\n data: {\n answer,\n confidence,\n sessionId: request.sessionId,\n documentUrl: request.documentUrl,\n question: request.question\n },\n metadata: {\n processedAt: new Date().toISOString(),\n responseTime: Date.now() - new Date(request.timestamp).getTime(),\n creditsUsed: 1\n }\n }\n}];"
},
"typeVersion": 2
},
{
"id": "format-error",
"name": "格式化错误响应",
"type": "n8n-nodes-base.code",
"notes": "Prepare error response",
"position": [
850,
350
],
"parameters": {
"jsCode": "// Prepare error response\nconst errors = $json.errors || ['An error occurred processing your request'];\n\nreturn [{\n json: {\n success: false,\n errors,\n message: 'Invalid request',\n timestamp: new Date().toISOString()\n }\n}];"
},
"typeVersion": 2
},
{
"id": "webhook-response",
"name": "发送响应",
"type": "n8n-nodes-base.respondToWebhook",
"notes": "Send API response",
"position": [
1250,
300
],
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify($json) }}",
"responseHeaders": {
"entries": [
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 1
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Validate Request",
"type": "main",
"index": 0
}
]
]
},
"Valid Request?": {
"main": [
[
{
"node": "PDF Vector - Ask Question",
"type": "main",
"index": 0
}
],
[
{
"node": "Format Error Response",
"type": "main",
"index": 0
}
]
]
},
"Validate Request": {
"main": [
[
{
"node": "Valid Request?",
"type": "main",
"index": 0
}
]
]
},
"Format Error Response": {
"main": [
[
{
"node": "Send Response",
"type": "main",
"index": 0
}
]
]
},
"Format Success Response": {
"main": [
[
{
"node": "Send Response",
"type": "main",
"index": 0
}
]
]
},
"PDF Vector - Ask Question": {
"main": [
[
{
"node": "Format Success Response",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 内部知识库, AI RAG 检索增强, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用GPT-4和多数据库搜索自动化学术文献综述
使用GPT-4和多数据库搜索自动化学术文献综述
If
Set
Code
+4
13 节点PDF Vector
文档提取
使用PDF向量、Google Drive和数据库提取和存储发票数据
使用PDF向量、Google Drive和数据库提取和存储发票数据
If
Code
Slack
+7
26 节点PDF Vector
发票处理
使用GPT-4和PDF Vector生成多格式研究论文摘要
使用GPT-4和PDF Vector生成多格式研究论文摘要
Code
Open Ai
Webhook
+3
9 节点PDF Vector
AI 摘要总结
跨五个数据库的学术研究搜索,含PDF向量和多重导出
跨五个数据库的学术研究搜索,含PDF向量和多重导出
Set
Code
Pdf Vector
+2
9 节点PDF Vector
AI RAG 检索增强
使用PDF向量、GPT-4和Neo4j构建学术知识图谱
使用PDF向量、GPT-4和Neo4j从研究论文构建学术知识图谱
Code
Neo4j
Open Ai
+4
10 节点PDF Vector
AI RAG 检索增强
使用 PDF 向量、OCR、GPT-4 和 Google Drive 的研究论文分析系统
使用 PDF 向量、OCR、GPT-4 和 Google Drive 的研究论文分析系统
Code
Open Ai
Postgres
+4
11 节点PDF Vector
文档提取
工作流信息
难度等级
中级
节点数量11
分类3
节点类型6
作者
PDF Vector
@pdfvectorA fully featured PDF APIs for developers - Parse any PDF or Word document, extract structured data, and access millions of academic papers - all through simple APIs.
外部链接
在 n8n.io 查看 →
分享此工作流