{
  "name": "Bestpass KB - Vector Store Ingestion",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Upload Knowledge Base - Bestpass",
        "formDescription": "Faça upload do arquivo de conhecimento (.txt, .pdf, .docx, .json, .jsonl, .md)",
        "formFields": {
          "values": [
            {
              "fieldLabel": "data",
              "fieldType": "file",
              "acceptFileTypes": ".txt,.pdf,.docx,.json,.jsonl,.md",
              "requiredField": true
            }
          ]
        },
        "options": {
          "appendAttribution": false
        }
      },
      "id": "form-trigger",
      "name": "On Form Submission",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -400,
        0
      ],
      "webhookId": "bestpass-kb-upload-form"
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "documents",
        "filterType": "string",
        "filterString": "=metadata->>source=eq.bestpass_kb"
      },
      "id": "delete-old",
      "name": "Limpar KB Antiga",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        -200,
        -200
      ],
      "alwaysOutputData": true,
      "executeOnce": true,
      "credentials": {
        "supabaseApi": {
          "id": "REPLACE_WITH_YOUR_SUPABASE_CRED_ID",
          "name": "Supabase account"
        }
      }
    },
    {
      "parameters": {},
      "id": "merge",
      "name": "Aguardar Limpeza",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "id": "supabase-vectorstore",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.1,
      "position": [
        300,
        0
      ],
      "credentials": {
        "supabaseApi": {
          "id": "REPLACE_WITH_YOUR_SUPABASE_CRED_ID",
          "name": "Supabase account"
        }
      }
    },
    {
      "parameters": {
        "dataType": "binary",
        "binaryMode": "specificField",
        "binaryDataKey": "data",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "source",
                "value": "bestpass_kb"
              },
              {
                "name": "file_name",
                "value": "={{ $('On Form Submission').item.binary.data.fileName }}"
              },
              {
                "name": "uploaded_at",
                "value": "={{ $now.toISO() }}"
              }
            ]
          }
        }
      },
      "id": "data-loader",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1,
      "position": [
        300,
        220
      ]
    },
    {
      "parameters": {
        "separators": [
          {
            "separator": "\n---\n"
          },
          {
            "separator": "\n\n"
          },
          {
            "separator": "\n"
          },
          {
            "separator": " "
          }
        ],
        "chunkSize": 1000,
        "chunkOverlap": 100
      },
      "id": "text-splitter",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "typeVersion": 1,
      "position": [
        420,
        420
      ]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "options": {}
      },
      "id": "embeddings",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        160,
        220
      ],
      "credentials": {
        "openAiApi": {
          "id": "REPLACE_WITH_YOUR_OPENAI_CRED_ID",
          "name": "OpenAI account"
        }
      }
    }
  ],
  "connections": {
    "On Form Submission": {
      "main": [
        [
          {
            "node": "Limpar KB Antiga",
            "type": "main",
            "index": 0
          },
          {
            "node": "Aguardar Limpeza",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limpar KB Antiga": {
      "main": [
        [
          {
            "node": "Aguardar Limpeza",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Aguardar Limpeza": {
      "main": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
