RAG System (Google Drive, Supabase, GPT-5)

    This workflow creates a RAG system that: - Monitors Google Drive for new PDFs and automatically extracts/processes their content - Splits documents into chunks with AI-generated context and stores them in a vector database - Provides a chat interface where users can ask questions about the stored documents - Uses hybrid search with reranking to find the most relevant information and generate AI responses - Includes deduplication to avoid reprocessing unchanged files

    Shared 8/31/2025

    367 views

    Visual Workflow

    JSON Code

    {
      "meta": {
        "instanceId": "125637e355429ab06f8886794f7df9252a3e338f92a1957141a8989e48f2b612",
        "templateCredsSetupCompleted": true
      },
      "nodes": [
        {
          "id": "752d6927-36f7-4ce0-bdcd-69b0ad2ae28e",
          "name": "Watch RAG Documents Folder",
          "type": "n8n-nodes-base.googleDriveTrigger",
          "position": [
            -1808,
            224
          ],
          "parameters": {
            "event": "fileCreated",
            "options": {},
            "pollTimes": {
              "item": [
                {
                  "mode": "everyMinute"
                }
              ]
            },
            "triggerOn": "specificFolder",
            "folderToWatch": {
              "__rl": true,
              "mode": "list",
              "value": "18GZCn7S-cgTYvmgsMcrfzshI201pISmL",
              "cachedResultUrl": "https://drive.google.com/drive/folders/18GZCn7S-cgTYvmgsMcrfzshI201pISmL",
              "cachedResultName": "RAG Masterclass"
            }
          },
          "credentials": {
            "googleDriveOAuth2Api": {
              "id": "qI7DvSNzK02Lcs3f",
              "name": "Main Account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "eda49867-32d5-407b-910d-508ca882fb53",
          "name": "Process Each New File",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            -1584,
            224
          ],
          "parameters": {
            "options": {}
          },
          "typeVersion": 3
        },
        {
          "id": "73786502-c23f-48db-9383-fbdc0ef602b8",
          "name": "Download for Hash Check",
          "type": "n8n-nodes-base.googleDrive",
          "position": [
            -1360,
            -32
          ],
          "parameters": {
            "fileId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $json.id }}"
            },
            "options": {},
            "operation": "download"
          },
          "credentials": {
            "googleDriveOAuth2Api": {
              "id": "qI7DvSNzK02Lcs3f",
              "name": "Main Account"
            }
          },
          "typeVersion": 3
        },
        {
          "id": "f6ebd04d-46db-41a9-aebd-5b778e9fe88b",
          "name": "Extract PDF Content",
          "type": "n8n-nodes-base.extractFromFile",
          "position": [
            208,
            -32
          ],
          "parameters": {
            "options": {},
            "operation": "pdf"
          },
          "typeVersion": 1
        },
        {
          "id": "916737d3-fc1f-4f3f-bd49-42b5980d095d",
          "name": "Format Extracted Text",
          "type": "n8n-nodes-base.set",
          "position": [
            432,
            -32
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "ca82f663-7c00-427c-9c02-90b74e6c8fc6",
                  "name": "text",
                  "type": "string",
                  "value": "={{ $json.text }}"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "d4b2e9b5-6c02-478f-ba5e-2816729571b6",
          "name": "Store Contextualized Chunks",
          "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
          "position": [
            1936,
            48
          ],
          "parameters": {
            "mode": "insert",
            "options": {},
            "tableName": {
              "__rl": true,
              "mode": "list",
              "value": "documents_hybrid",
              "cachedResultName": "documents_hybrid"
            }
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "typeVersion": 1.3
        },
        {
          "id": "7a958b78-4ebe-4836-b713-d4be8570cc5a",
          "name": "Generate Embeddings for Storage",
          "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
          "position": [
            1904,
            272
          ],
          "parameters": {
            "options": {}
          },
          "credentials": {
            "openAiApi": {
              "id": "YlmU06HqWiBuScWV",
              "name": "OpenAi account"
            }
          },
          "typeVersion": 1.2
        },
        {
          "id": "7886f44d-4113-4b83-843d-9665372fecc4",
          "name": "Load Document for Vectorization",
          "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
          "position": [
            2032,
            272
          ],
          "parameters": {
            "options": {
              "metadata": {
                "metadataValues": [
                  {
                    "name": "google_drive_file_id",
                    "value": "={{ $('Download for Hash Check').item.json.id }}"
                  }
                ]
              }
            },
            "textSplittingMode": "custom"
          },
          "typeVersion": 1.1
        },
        {
          "id": "d1cd1764-566a-4f08-b3b2-e7bcb22ecc08",
          "name": "Generate File Hash",
          "type": "n8n-nodes-base.crypto",
          "position": [
            -1136,
            -32
          ],
          "parameters": {
            "type": "SHA256",
            "binaryData": true,
            "dataPropertyName": "hash"
          },
          "typeVersion": 1
        },
        {
          "id": "5f79ac29-1bee-4957-b22a-122ba9d8c550",
          "name": "Create Hash Record",
          "type": "n8n-nodes-base.supabase",
          "position": [
            -240,
            -128
          ],
          "parameters": {
            "tableId": "record_manager_hybrid",
            "fieldsUi": {
              "fieldValues": [
                {
                  "fieldId": "google_drive_file_id",
                  "fieldValue": "={{ $('Download for Hash Check').item.json.id }}"
                },
                {
                  "fieldId": "hash",
                  "fieldValue": "={{ $('Generate File Hash').item.json.hash }}"
                }
              ]
            }
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "ca933518-7584-4d93-b200-cc15d6dd6591",
          "name": "Check File Status",
          "type": "n8n-nodes-base.switch",
          "position": [
            -688,
            -48
          ],
          "parameters": {
            "rules": {
              "values": [
                {
                  "conditions": {
                    "options": {
                      "version": 2,
                      "leftValue": "",
                      "caseSensitive": true,
                      "typeValidation": "strict"
                    },
                    "combinator": "and",
                    "conditions": [
                      {
                        "id": "546738cb-1f11-44bf-a5e7-f9526a378a67",
                        "operator": {
                          "type": "object",
                          "operation": "empty",
                          "singleValue": true
                        },
                        "leftValue": "={{ $json }}",
                        "rightValue": ""
                      }
                    ]
                  }
                },
                {
                  "conditions": {
                    "options": {
                      "version": 2,
                      "leftValue": "",
                      "caseSensitive": true,
                      "typeValidation": "strict"
                    },
                    "combinator": "and",
                    "conditions": [
                      {
                        "id": "64ffb26a-de94-4923-9382-0357c47ad43f",
                        "operator": {
                          "type": "string",
                          "operation": "equals"
                        },
                        "leftValue": "={{ $json.hash }}",
                        "rightValue": "={{ $('Generate File Hash').item.json.hash }}"
                      }
                    ]
                  }
                },
                {
                  "conditions": {
                    "options": {
                      "version": 2,
                      "leftValue": "",
                      "caseSensitive": true,
                      "typeValidation": "strict"
                    },
                    "combinator": "and",
                    "conditions": [
                      {
                        "id": "015a91c1-8f02-4c05-945b-0b009034d418",
                        "operator": {
                          "type": "string",
                          "operation": "notEquals"
                        },
                        "leftValue": "={{ $json.hash }}",
                        "rightValue": "={{ $('Generate File Hash').item.json.hash }}"
                      }
                    ]
                  }
                }
              ]
            },
            "options": {}
          },
          "typeVersion": 3.2
        },
        {
          "id": "cb67fdad-1feb-482d-9ccb-3e1c35a6a07f",
          "name": "Get Existing Hash Record",
          "type": "n8n-nodes-base.supabase",
          "position": [
            -912,
            -32
          ],
          "parameters": {
            "limit": 1,
            "filters": {
              "conditions": [
                {
                  "keyName": "google_drive_file_id",
                  "keyValue": "={{ $('Download for Hash Check').item.json.id }}",
                  "condition": "eq"
                }
              ]
            },
            "tableId": "record_manager_hybrid",
            "operation": "getAll"
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "typeVersion": 1,
          "alwaysOutputData": true
        },
        {
          "id": "53397b18-51df-42c3-aaf6-94951c7fde05",
          "name": "Delete Old Vector Entries",
          "type": "n8n-nodes-base.supabase",
          "position": [
            -464,
            64
          ],
          "parameters": {
            "tableId": "documents_hybrid",
            "operation": "delete",
            "filterType": "string",
            "filterString": "=metadata->>google_drive_file_id=like.*{{ $('Process Each New File').item.json.id }}*"
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "typeVersion": 1,
          "alwaysOutputData": true
        },
        {
          "id": "8dd347ff-327d-4ff6-b636-2a4dc95c25f8",
          "name": "Update Hash Record",
          "type": "n8n-nodes-base.supabase",
          "position": [
            -240,
            64
          ],
          "parameters": {
            "filters": {
              "conditions": [
                {
                  "keyName": "google_drive_file_id",
                  "keyValue": "={{ $('Download for Hash Check').item.json.id }}",
                  "condition": "eq"
                }
              ]
            },
            "tableId": "record_manager_hybrid",
            "fieldsUi": {
              "fieldValues": [
                {
                  "fieldId": "hash",
                  "fieldValue": "={{ $('Generate File Hash').item.json.hash }}"
                }
              ]
            },
            "operation": "update"
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "executeOnce": true,
          "typeVersion": 1
        },
        {
          "id": "3ab3df4c-7dff-4e1f-92d3-ae3f645b4301",
          "name": "Download for Processing",
          "type": "n8n-nodes-base.googleDrive",
          "position": [
            -16,
            -32
          ],
          "parameters": {
            "fileId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Download for Hash Check').item.json.id }}"
            },
            "options": {},
            "operation": "download"
          },
          "credentials": {
            "googleDriveOAuth2Api": {
              "id": "qI7DvSNzK02Lcs3f",
              "name": "Main Account"
            }
          },
          "typeVersion": 3
        },
        {
          "id": "ab9009da-34bd-4683-bf14-a1db1a870331",
          "name": "Receive User Query",
          "type": "@n8n/n8n-nodes-langchain.chatTrigger",
          "position": [
            -1808,
            816
          ],
          "webhookId": "f2556a1c-5eea-4fde-bbf2-db10a9ae9119",
          "parameters": {
            "options": {}
          },
          "typeVersion": 1.3
        },
        {
          "id": "ab005482-0a84-4049-8ae0-0eb261bd3a13",
          "name": "RAG Chat Agent",
          "type": "@n8n/n8n-nodes-langchain.agent",
          "position": [
            -1536,
            704
          ],
          "parameters": {
            "options": {
              "systemMessage": "You are an AI assistant with access to a knowledge base about Artificial Intelligence and Machine Learning. You have to make use of the Vector Store tool you have to access that information. \n\nAlways base your responses on the provided context documents. If information is not available in the context, clearly state \"I don't have information about that in my knowledge base\" rather than guessing. \n\nWhen answering, cite which section or part of the document your information comes from. \n\nProvide comprehensive answers by combining relevant information from multiple parts of the context when needed. Keep responses accurate, concise, and directly address what the user is asking."
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "3806415e-74c5-4663-b875-cedcbca059b0",
          "name": "Chat Language Model",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
          "position": [
            -1584,
            928
          ],
          "parameters": {
            "model": {
              "__rl": true,
              "mode": "list",
              "value": "gpt-5-mini",
              "cachedResultName": "gpt-5-mini"
            },
            "options": {}
          },
          "credentials": {
            "openAiApi": {
              "id": "YlmU06HqWiBuScWV",
              "name": "OpenAi account"
            }
          },
          "typeVersion": 1.2
        },
        {
          "id": "f3c6562f-65a4-4cd9-af4b-f33538b48ad7",
          "name": "Conversation Memory",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            -1456,
            928
          ],
          "parameters": {},
          "typeVersion": 1.3
        },
        {
          "id": "e81bb20f-9c7f-4edf-b6a3-f87d3669d658",
          "name": "Vector Knowledge Base",
          "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
          "position": [
            -1600,
            1136
          ],
          "parameters": {
            "mode": "retrieve-as-tool",
            "topK": 20,
            "options": {},
            "tableName": {
              "__rl": true,
              "mode": "list",
              "value": "documents",
              "cachedResultName": "documents"
            },
            "toolDescription": "Retrieve information about AI and Machine Learning using this tool"
          },
          "credentials": {
            "supabaseApi": {
              "id": "yNO2GlywefQ14UXh",
              "name": "temp"
            }
          },
          "typeVersion": 1.3
        },
        {
          "id": "2ee7b091-3566-46d5-99b0-4856c996419c",
          "name": "Query Embeddings",
          "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
          "position": [
            -1808,
            1136
          ],
          "parameters": {
            "options": {}
          },
          "credentials": {
            "openAiApi": {
              "id": "YlmU06HqWiBuScWV",
              "name": "OpenAi account"
            }
          },
          "typeVersion": 1.2
        },
        {
          "id": "34bfbc84-a1f8-4d80-9a3c-cf130c2f3d8d",
          "name": "Hybrid Search Tool",
          "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
          "position": [
            -1328,
            928
          ],
          "parameters": {
            "workflowId": {
              "__rl": true,
              "mode": "list",
              "value": "5ViKzpZyfSvupWl9",
              "cachedResultName": "My workflow 6"
            },
            "description": "Use this to fetch data from the vector store knowledgebase.",
            "workflowInputs": {
              "value": {
                "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', ``, 'string') }}"
              },
              "schema": [
                {
                  "id": "query",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "query",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                }
              ],
              "mappingMode": "defineBelow",
              "matchingColumns": [
                "query"
              ],
              "attemptToConvertTypes": false,
              "convertFieldsToString": false
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "890cd10f-e3ff-4e20-8b8e-10cb07dea5ed",
          "name": "Hybrid Search Trigger",
          "type": "n8n-nodes-base.executeWorkflowTrigger",
          "position": [
            -1024,
            784
          ],
          "parameters": {
            "workflowInputs": {
              "values": [
                {
                  "name": "query"
                }
              ]
            }
          },
          "typeVersion": 1.1
        },
        {
          "id": "c2984fc9-e022-4e9f-be2b-981a19414514",
          "name": "Create Query Embedding",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            -800,
            784
          ],
          "parameters": {
            "url": "https://api.openai.com/v1/embeddings",
            "method": "POST",
            "options": {},
            "sendBody": true,
            "authentication": "predefinedCredentialType",
            "bodyParameters": {
              "parameters": [
                {
                  "name": "input",
                  "value": "={{ $json.query }}"
                },
                {
                  "name": "model",
                  "value": "text-embedding-3-small"
                }
              ]
            },
            "nodeCredentialType": "openAiApi"
          },
          "credentials": {
            "openAiApi": {
              "id": "YlmU06HqWiBuScWV",
              "name": "OpenAi account"
            }
          },
          "typeVersion": 4.2
        },
        {
          "id": "1730b13f-c20a-4e5e-96c0-306d89830517",
          "name": "Perform Hybrid Search",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            -576,
            784
          ],
          "parameters": {
            "url": "https://rdchjzbhgspucjrydzmz.supabase.co/functions/v1/hybrid_search",
            "method": "POST",
            "options": {},
            "jsonBody": "={\n  \"query_text\": \"{{ $('Hybrid Search Trigger').item.json.query }}\",\n  \"query_embedding\": {{ JSON.stringify($json.data[0].embedding) }}\n}",
            "sendBody": true,
            "sendHeaders": true,
            "specifyBody": "json",
            "headerParameters": {
              "parameters": [
                {
                  "name": "Authorization",
                  "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJkY2hqemJoZ3NwdWNqcnlkem16Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ2NDY3MjcsImV4cCI6MjA3MDIyMjcyN30.QN21Xc_h9dzLfYWViT25TF_uIsr0YjNG2VX1cqmY_38"
                }
              ]
            }
          },
          "typeVersion": 4.2,
          "alwaysOutputData": true
        },
        {
          "id": "aa70c460-0759-47b9-b7d1-3903c153756e",
          "name": "Rerank with Cohere",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            -128,
            784
          ],
          "parameters": {
            "url": "https://api.cohere.com/v2/rerank",
            "method": "POST",
            "options": {},
            "jsonBody": "={\n  \"model\": \"rerank-v3.5\",\n  \"query\": \"{{ $('Hybrid Search Trigger').item.json.query }}\",\n  \"top_n\": 5,\n  \"documents\": {{ JSON.stringify($json.content) }}\n  \n} ",
            "sendBody": true,
            "sendHeaders": true,
            "specifyBody": "json",
            "headerParameters": {
              "parameters": [
                {
                  "name": "accept",
                  "value": "application/json"
                },
                {
                  "name": "Authorization",
                  "value": "bearer Un446vPHJqg6ICTkatbNyHyyyWTB8KnAmsUEuBgH"
                }
              ]
            }
          },
          "typeVersion": 4.2
        },
        {
          "id": "71a8ccf4-b29f-4e37-af33-bda0cc1ae0bd",
          "name": "Aggregate Search Results",
          "type": "n8n-nodes-base.aggregate",
          "position": [
            -352,
            784
          ],
          "parameters": {
            "options": {},
            "fieldsToAggregate": {
              "fieldToAggregate": [
                {
                  "renameField": true,
                  "outputFieldName": "content",
                  "fieldToAggregate": "content"
                }
              ]
            }
          },
          "typeVersion": 1
        },
        {
          "id": "587e0db3-3442-4109-ab6f-b7c8af460ac9",
          "name": "Process Reranked Results",
          "type": "n8n-nodes-base.code",
          "position": [
            96,
            784
          ],
          "parameters": {
            "jsCode": "// Get the reranking results from the previous HTTP Request2 node\nconst rerankResults = $input.all()[0].json;\n\n// Get the original aggregated content from the Aggregate node\nconst originalContent = $('Aggregate Search Results').first().json.content\n\n// Extract the reordered results from Cohere's response\nconst reorderedResults = rerankResults.results;\n\n// Create the reordered chunks array\nconst reorderedChunks = reorderedResults.map((result, newIndex) => {\n  return {\n    original_index: result.index,\n    new_index: newIndex,\n    relevance_score: result.relevance_score,\n    content: originalContent[result.index],\n    document: result.document\n  };\n});\n\nreturn [\n  {\n    json: {\n      reordered_chunks: reorderedChunks,\n    }\n  }\n];"
          },
          "typeVersion": 2
        },
        {
          "id": "c8010a3e-69e1-4631-9dc7-894545af85ed",
          "name": "Create Text Chunks",
          "type": "n8n-nodes-base.code",
          "position": [
            656,
            -32
          ],
          "parameters": {
            "jsCode": "//  Define chunk size and overlap\nconst chunkSize = 1000;\nconst chunkOverlap = 200;\n\n//  Function to split text into overlapping chunks\nfunction createChunks(text) {\n\tconst chunks = [];\n\tlet remainingText = text;\n\n\twhile (remainingText.length > 0) {\n\t\tlet splitPoint;\n\n\t\t//  Try paragraph split first\n\t\tsplitPoint = remainingText.lastIndexOf(\"\\n\\n\", chunkSize);\n\n\t\t//  If no paragraph split, try sentence split\n\t\tif (splitPoint === -1) {\n\t\t\tsplitPoint = remainingText.lastIndexOf(\". \", chunkSize);\n\t\t}\n\n\t\t//  If no sentence split, try word split\n\t\tif (splitPoint === -1) {\n\t\t\tsplitPoint = remainingText.lastIndexOf(\" \", chunkSize);\n\t\t}\n\n\t\t//  If still no split point, hard cut at chunkSize\n\t\tif (splitPoint === -1 || splitPoint < chunkSize * 0.5) {\n\t\t\tsplitPoint = chunkSize;\n\t\t}\n\n\t\t//  Extract chunk\n\t\tconst chunk = remainingText.substring(0, splitPoint).trim();\n\t\tchunks.push(chunk);\n\n\t\t//  Move pointer forward with overlap\n\t\tremainingText = remainingText.substring(Math.max(0, splitPoint - chunkOverlap)).trim();\n\n\t\t//  Stop if remaining text too small\n\t\tif (remainingText.length < chunkSize * 0.2) {\n\t\t\tif (remainingText.length > 0) {\n\t\t\t\tchunks.push(remainingText);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn chunks;\n}\n\n//  Take first incoming item's document and create chunks\nconst text = $input.first().json.text || '';\nconst chunks = createChunks(text);\n\n//  Return one item per chunk\nreturn chunks.map(chunk => ({ json: { chunk } }));\n"
          },
          "typeVersion": 2
        },
        {
          "id": "0cd281fc-8031-47cc-98f1-050a5cae72a9",
          "name": "Process Document Chunks",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            1104,
            48
          ],
          "parameters": {
            "options": {},
            "batchSize": 10
          },
          "typeVersion": 3
        },
        {
          "id": "1ffe6941-7528-4ea7-bcbf-26eeb4421d19",
          "name": "Add Contextual Information",
          "type": "@n8n/n8n-nodes-langchain.openAi",
          "position": [
            1328,
            -32
          ],
          "parameters": {
            "modelId": {
              "__rl": true,
              "mode": "list",
              "value": "gpt-5-nano-2025-08-07",
              "cachedResultName": "GPT-5-NANO-2025-08-07"
            },
            "options": {},
            "messages": {
              "values": [
                {
                  "content": "=<document> \n{{ $('Format Extracted Text').item.json.text }}\n</document> \nHere is the chunk we want to situate within the whole document \n<chunk> \n{{ $('Process Document Chunks').item.json.chunk }}\n</chunk> \nPlease give a short succinct context to situate this chunk within the overall document for the purposes of improving search retrieval of the chunk. Answer only with the succinct context and nothing else. Start with: \"This chunk contains...\""
                }
              ]
            }
          },
          "credentials": {
            "openAiApi": {
              "id": "YlmU06HqWiBuScWV",
              "name": "OpenAi account"
            }
          },
          "retryOnFail": true,
          "typeVersion": 1.8,
          "waitBetweenTries": 5000
        },
        {
          "id": "70c36956-12f1-4655-badb-3375f780f524",
          "name": "Combine Context with Chunks",
          "type": "n8n-nodes-base.set",
          "position": [
            1680,
            -32
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "02c135df-ab85-4e76-affb-22ed7ecfd061",
                  "name": "content",
                  "type": "string",
                  "value": "={{ $json.message.content }} - {{ $('Process Document Chunks').item.json.chunk }}"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "c7f468c3-e43e-45ba-bfe2-ca5232a6019e",
          "name": "Split Text for Vectorization",
          "type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter",
          "position": [
            2112,
            480
          ],
          "parameters": {
            "chunkSize": 2000
          },
          "typeVersion": 1
        }
      ],
      "pinData": {},
      "connections": {
        "Query Embeddings": {
          "ai_embedding": [
            [
              {
                "node": "Vector Knowledge Base",
                "type": "ai_embedding",
                "index": 0
              }
            ]
          ]
        },
        "Check File Status": {
          "main": [
            [
              {
                "node": "Create Hash Record",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Process Each New File",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Delete Old Vector Entries",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Create Hash Record": {
          "main": [
            [
              {
                "node": "Download for Processing",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Create Text Chunks": {
          "main": [
            [
              {
                "node": "Process Document Chunks",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Generate File Hash": {
          "main": [
            [
              {
                "node": "Get Existing Hash Record",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Hybrid Search Tool": {
          "ai_tool": [
            [
              {
                "node": "RAG Chat Agent",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "Receive User Query": {
          "main": [
            [
              {
                "node": "RAG Chat Agent",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Rerank with Cohere": {
          "main": [
            [
              {
                "node": "Process Reranked Results",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Update Hash Record": {
          "main": [
            [
              {
                "node": "Download for Processing",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Chat Language Model": {
          "ai_languageModel": [
            [
              {
                "node": "RAG Chat Agent",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Conversation Memory": {
          "ai_memory": [
            [
              {
                "node": "RAG Chat Agent",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Extract PDF Content": {
          "main": [
            [
              {
                "node": "Format Extracted Text",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Format Extracted Text": {
          "main": [
            [
              {
                "node": "Create Text Chunks",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Hybrid Search Trigger": {
          "main": [
            [
              {
                "node": "Create Query Embedding",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Perform Hybrid Search": {
          "main": [
            [
              {
                "node": "Aggregate Search Results",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Process Each New File": {
          "main": [
            [],
            [
              {
                "node": "Download for Hash Check",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Create Query Embedding": {
          "main": [
            [
              {
                "node": "Perform Hybrid Search",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Download for Hash Check": {
          "main": [
            [
              {
                "node": "Generate File Hash",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Download for Processing": {
          "main": [
            [
              {
                "node": "Extract PDF Content",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Process Document Chunks": {
          "main": [
            [
              {
                "node": "Process Each New File",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Add Contextual Information",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Aggregate Search Results": {
          "main": [
            [
              {
                "node": "Rerank with Cohere",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get Existing Hash Record": {
          "main": [
            [
              {
                "node": "Check File Status",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Delete Old Vector Entries": {
          "main": [
            [
              {
                "node": "Update Hash Record",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Add Contextual Information": {
          "main": [
            [
              {
                "node": "Combine Context with Chunks",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Watch RAG Documents Folder": {
          "main": [
            [
              {
                "node": "Process Each New File",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Combine Context with Chunks": {
          "main": [
            [
              {
                "node": "Store Contextualized Chunks",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Store Contextualized Chunks": {
          "main": [
            [
              {
                "node": "Process Document Chunks",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Split Text for Vectorization": {
          "ai_textSplitter": [
            [
              {
                "node": "Load Document for Vectorization",
                "type": "ai_textSplitter",
                "index": 0
              }
            ]
          ]
        },
        "Generate Embeddings for Storage": {
          "ai_embedding": [
            [
              {
                "node": "Store Contextualized Chunks",
                "type": "ai_embedding",
                "index": 0
              }
            ]
          ]
        },
        "Load Document for Vectorization": {
          "ai_document": [
            [
              {
                "node": "Store Contextualized Chunks",
                "type": "ai_document",
                "index": 0
              }
            ]
          ]
        }
      }
    }