Hello,
I am trying to use an AI agent to scan pdf files and extract data from the PDF and export and save them in a way I want. There is a node for extracting PDF but it is not working well. And I need to have this system 100% on-prem. I added ollama to it and tried a few Vision models. Can someone please help me to understand how it works?
{
“nodes”: [
{
“parameters”: {
“options”: {
“responseMode”: “responseNodes”
}
},
“type”: “ @n8n/n8n-nodes-langchain.chatTrigger”,
“typeVersion”: 1.3,
“position”: [
-560,
-1124
],
“id”: “c1a7c55f-92ce-4c92-96ec-3c0c813c4491”,
“name”: “When chat message received”,
“webhookId”: “80cc7829-d23a-4132-a726-2d264271cf2c”
},
{
“parameters”: {
“hasOutputParser”: true,
“options”: {
“systemMessage”: “=You are an invoice extraction agent. Output ONLY valid JSON matching this schema:\n{\n "supplier": {"name": "string", "vat_id": "string", "country": "string"},\n "invoice": {"number": "string", "date": "YYYY-MM-DD", "po_number": "string", "currency": "ISO-4217"},\n "totals": {"subtotal": "number", "tax_total": "number", "grand_total": "number"},\n "lines": [{"description": "string", "qty": "number", "unit_price": "number", "vat_rate": "number", "vat_amount": "number", "total": "number"}]\n}\nRules:\n- Use DOCUMENT_TEXT as ground truth.\n- Use retrieved context only to clarify labels or typical field positions (do not invent data).\n- If a field is missing, use "" or 0.\n- Dates must be YYYY-MM-DD; currency must be ISO-4217.\n\nDOCUMENT_TEXT:\nYou have a tool name n8n_vectors_invoice to extract invoices. Use this tool to OCR the invoices and convert to text”,
“passthroughBinaryImages”: true
}
},
“type”: “ @n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 2.2,
“position”: [
272,
-1124
],
“id”: “e042cfe4-2b67-45c1-9dea-0aeb8a54c85c”,
“name”: “AI Agent”
},
{
“parameters”: {
“model”: “granite3.2-vision:2b-fp16”
},
“id”: “7d3cd5c5-456e-4571-989e-32a8f304e65b”,
“name”: “Embeddings (Ollama)”,
“type”: “ @n8n/n8n-nodes-langchain.embeddingsOllama”,
“typeVersion”: 1,
“position”: [
448,
-692
],
“credentials”: {
“ollamaApi”: {
“id”: “YTFD2U2tsK8MQO2p”,
“name”: “Local-Ollama”
}
}
},
{
“parameters”: {
“model”: “granite3.2-vision:2b-fp16”,
“options”: {}
},
“id”: “65b5b6c9-86f3-4b45-ad8f-9264258017fa”,
“name”: “Ollama Chat Model”,
“type”: “ @n8n/n8n-nodes-langchain.lmChatOllama”,
“typeVersion”: 1,
“position”: [
240,
-900
],
“credentials”: {
“ollamaApi”: {
“id”: “YTFD2U2tsK8MQO2p”,
“name”: “Local-Ollama”
}
}
},
{
“parameters”: {
“mode”: “retrieve-as-tool”,
“toolDescription”: “Extract data for requested invoice to scan”,
“tableName”: “n8n_vectors_invoice”,
“options”: {}
},
“type”: “ @n8n/n8n-nodes-langchain.vectorStorePGVector”,
“typeVersion”: 1.3,
“position”: [
368,
-900
],
“id”: “1a931b45-19bd-4b0d-93c5-a0ec82507252”,
“name”: “Postgres PGVector Store”,
“credentials”: {
“postgres”: {
“id”: “2WfaBl97lzCTPO8K”,
“name”: “studio_test”
}
}
},
{
“parameters”: {
“mode”: “insert”,
“tableName”: “n8n_vectors_invoice”,
“options”: {}
},
“type”: “ @n8n/n8n-nodes-langchain.vectorStorePGVector”,
“typeVersion”: 1.3,
“position”: [
-112,
-1248
],
“id”: “d367cd5a-6a2b-4312-96b1-c076f4ab1de2”,
“name”: “Postgres PGVector Store1”,
“credentials”: {
“postgres”: {
“id”: “2WfaBl97lzCTPO8K”,
“name”: “studio_test”
}
}
},
{
“parameters”: {
“model”: “granite3.2-vision:2b-fp16”
},
“type”: “ @n8n/n8n-nodes-langchain.embeddingsOllama”,
“typeVersion”: 1,
“position”: [
-104,
-1024
],
“id”: “4c3d1381-9fd2-4e3c-9bd7-61eb9232c118”,
“name”: “Embeddings Ollama”,
“credentials”: {
“ollamaApi”: {
“id”: “YTFD2U2tsK8MQO2p”,
“name”: “Local-Ollama”
}
}
},
{
“parameters”: {
“dataType”: “binary”,
“loader”: “pdfLoader”,
“options”: {}
},
“type”: “ @n8n/n8n-nodes-langchain.documentDefaultDataLoader”,
“typeVersion”: 1.1,
“position”: [
24,
-1024
],
“id”: “408cb6ff-b561-4dea-9217-abe73008d89c”,
“name”: “Default Data Loader”
},
{
“parameters”: {
“operation”: “download”,
“fileId”: “=01PPIPJ4I52GB32BMW3JBLIQWQXNML3I3P”,
“binaryPropertyName”: “=data”
},
“type”: “n8n-nodes-base.microsoftOneDrive”,
“typeVersion”: 1,
“position”: [
-336,
-1248
],
“id”: “6e09560f-50ff-4a83-b77c-a5a8c226543c”,
“name”: “Download a file”,
“credentials”: {
“microsoftOneDriveOAuth2Api”: {
“id”: “KjKWXftIIlLXqm4E”,
“name”: “Microsoft Drive account”
}
}
},
{
“parameters”: {
“message”: “={{ $json.output }}”,
“waitUserReply”: false,
“options”: {
“memoryConnection”: true
}
},
“type”: “ @n8n/n8n-nodes-langchain.chat”,
“typeVersion”: 1,
“position”: [
736,
-1124
],
“id”: “574e6b70-0b39-4a69-9c50-3da05680db63”,
“name”: “Respond to Chat”
}
],
“connections”: {
“When chat message received”: {
“main”: [
[
{
“node”: “Download a file”,
“type”: “main”,
“index”: 0
},
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“AI Agent”: {
“main”: [
[
{
“node”: “Respond to Chat”,
“type”: “main”,
“index”: 0
}
]
]
},
“Embeddings (Ollama)”: {
“ai_embedding”: [
[
{
“node”: “Postgres PGVector Store”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
},
“Ollama Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Postgres PGVector Store”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Postgres PGVector Store1”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“Embeddings Ollama”: {
“ai_embedding”: [
[
{
“node”: “Postgres PGVector Store1”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
},
“Default Data Loader”: {
“ai_document”: [
[
{
“node”: “Postgres PGVector Store1”,
“type”: “ai_document”,
“index”: 0
}
]
]
},
“Download a file”: {
“main”: [
[
{
“node”: “Postgres PGVector Store1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Respond to Chat”: {
“main”: [
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “a8f1d7b04d456adebda2b06a4daf58d62d7e18980ac63d5ecc40681f1b6fa592”
}
}

