{ "name": "RAG Test", "nodes": [ { "parameters": { "operation": "executeQuery", "query": "select *\nfrom public.match_knowledge_embeddings(\n $1::vector(1536),\n 0.3::double precision,\n 3\n);", "options": { "queryReplacement": "=={{ $json.embedding }}" } }, "type": "n8n-nodes-base.postgres", "typeVersion": 2.6, "position": [ -384, 48 ], "id": "1d733cd5-7e14-42b6-9abd-faf896d94ab7", "name": "Execute a SQL query", "credentials": { "postgres": { "id": "Fybq1JpiX9XAfX8w", "name": "Postgres account" } } }, { "parameters": { "jsCode": "return {\n json: {\n query_text: \"What time will you close?\"\n }\n};" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -1296, 48 ], "id": "3c822e31-5bfc-480a-addb-49456da71a3d", "name": "Single Query" }, { "parameters": { "method": "POST", "url": "https://openrouter.ai/api/v1/embeddings", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Bearer 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" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "model", "value": "=openai/text-embedding-3-small" }, { "name": "input", "value": "={{ $json.query_text }}" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ -1024, 48 ], "id": "b5a9c78f-8264-4798-8e57-2131c324e6be", "name": "Embedding" }, { "parameters": { "jsCode": "const embedding = $json?.data?.[0]?.embedding;\nif (!Array.isArray(embedding)) throw new Error(\"Missing query embedding\");\nreturn { json: { ...$json, embedding } };" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -720, 48 ], "id": "452ca9a5-9c05-45d8-8eed-b5b617b53929", "name": "Extract Query Embedding" }, { "parameters": { "jsCode": "const rows = $input.all().map(i => i.json);\n\nlet context = \"Relevant knowledge base entries:\\n\";\nrows.forEach((r, idx) => {\n context += `\\n[${idx + 1}] ${r.content}\\n(similarity: ${Number(r.similarity).toFixed(3)})\\n`;\n});\n\nreturn [{ json: { knowledge_context: context, matches: rows.length } }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -144, 32 ], "id": "f2a7867a-cf15-4da2-94e4-656a4f97f8ab", "name": "Build the knowledge_context" } ], "pinData": { "Execute a SQL query": [ { "json": { "id": "1", "content": "Q: What are your business hours?\nA: We're open Monday to Friday, 9 AM to 6 PM Eastern Time. We're closed on weekends and major holidays.\nCategory: general", "metadata": { "kb_id": 1, "category": "general", "question": "What are your business hours?" }, "similarity": 0.490192056286809 } } ] }, "connections": { "Execute a SQL query": { "main": [ [ { "node": "Build the knowledge_context", "type": "main", "index": 0 } ] ] }, "Single Query": { "main": [ [ { "node": "Embedding", "type": "main", "index": 0 } ] ] }, "Embedding": { "main": [ [ { "node": "Extract Query Embedding", "type": "main", "index": 0 } ] ] }, "Extract Query Embedding": { "main": [ [ { "node": "Execute a SQL query", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "binaryMode": "separate", "availableInMCP": false }, "versionId": "e13b04f2-d343-4f88-9448-927d0dba109a", "meta": { "instanceId": "86e40966ec50420e5d15bcd1dde77ea07adba792a75f16ea8e1aeab3d840cb1f" }, "id": "frg5tLGMpk77WvIB", "tags": [] }