Un sistema basado en RAG (Retrieval-Augmented Generation) que utiliza Supabase para almacenamiento vectorial y OpenAI para procesamiento de lenguaje natural. Permite gestionar documentos y responder consultas complejas utilizando datos preprocesados y almacenados en una base de datos vectorial.
Creado: 2024-12-09
21 nodos
Instrucciones
Editar Workflow
Visualización del Workflow
{
"name": "Supabase RAG",
"nodes": [
{
"parameters": {
"options": {}
},
"id": "8202d491-4cfd-451b-aa28-361d91595d97",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1,
"position": [
360,
-560
]
},
{
"parameters": {
"options": {}
},
"id": "3400880d-4aab-451b-8146-194830485548",
"name": "OpenAI Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1,
"position": [
1180,
-620
]
},
{
"parameters": {
"jsonMode": "expressionData",
"jsonData": "={{ $json.data }}",
"options": {
"metadata": {
"metadataValues": [
{
"name": "=file_id",
"value": "={{ $('Set File ID').item.json.file_id }}"
}
]
}
}
},
"id": "e039e8ea-62ed-4c6a-a1a3-78655f72fe12",
"name": "Default Data Loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"typeVersion": 1,
"position": [
1320,
-80
]
},
{
"parameters": {
"model": "text-embedding-3-small",
"options": {}
},
"id": "9e41ae2b-9588-4a43-a63b-c8d6a07dc0bf",
"name": "Embeddings OpenAI1",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1,
"position": [
1160,
-80
]
},
{
"parameters": {
"name": "user_documents",
"description": "Contains all the user's documents that you can check for context to answer user questions."
},
"id": "59dc9715-b342-491d-9a86-ab742b6ebe90",
"name": "Retrieve Documents",
"type": "@n8n/n8n-nodes-langchain.toolVectorStore",
"typeVersion": 1,
"position": [
960,
-800
]
},
{
"parameters": {
"content": "## Herramientas de Agentes para RAG",
"height": 528.85546469693,
"width": 583.4552380860637,
"color": 4
},
"id": "be4dffb5-3273-411b-bd31-ddda7e0cd6ba",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
780,
-920
]
},
{
"parameters": {
"content": "## Herramienta para Agregar un Archivo de Google Drive a una Base de Datos Vectorial",
"height": 671.8877842322804,
"width": 2070.8894079025763,
"color": 5
},
"id": "9641f7d3-7a47-4e03-94cd-55a080c7c357",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-440,
-380
]
},
{
"parameters": {
"operation": "download",
"fileId": {
"__rl": true,
"value": "={{ $('Set File ID').item.json.file_id }}",
"mode": "id"
},
"options": {
"googleFileConversion": {
"conversion": {
"docsToFormat": "text/plain"
}
}
}
},
"id": "7a61f3f8-cd25-4888-9400-a398e1644097",
"name": "Download File",
"type": "n8n-nodes-base.googleDrive",
"typeVersion": 3,
"position": [
660,
-200
],
"executeOnce": true
},
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"value": "1914m3M7kRzkd5RJqAfzRY9EBcJrKemZC",
"mode": "list",
"cachedResultName": "Meeting Notes",
"cachedResultUrl": "https://drive.google.com/drive/folders/1914m3M7kRzkd5RJqAfzRY9EBcJrKemZC"
},
"event": "fileCreated",
"options": {}
},
"id": "8edc96a2-a6e5-442b-94ca-7f2889417563",
"name": "File Created",
"type": "n8n-nodes-base.googleDriveTrigger",
"typeVersion": 1,
"position": [
-380,
-300
],
"credentials": {
"googleDriveOAuth2Api": {
"id": "kkUKUPjPqG6ENSMu",
"name": "Google tuxed@redaven.com"
}
}
},
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"value": "1914m3M7kRzkd5RJqAfzRY9EBcJrKemZC",
"mode": "list",
"cachedResultName": "Meeting Notes",
"cachedResultUrl": "https://drive.google.com/drive/folders/1914m3M7kRzkd5RJqAfzRY9EBcJrKemZC"
},
"event": "fileUpdated",
"options": {
"fileType": "all"
}
},
"id": "483a73ad-6723-403a-bc2e-d0052f18de75",
"name": "File Updated",
"type": "n8n-nodes-base.googleDriveTrigger",
"typeVersion": 1,
"position": [
-380,
-80
],
"credentials": {
"googleDriveOAuth2Api": {
"id": "kkUKUPjPqG6ENSMu",
"name": "Google tuxed@redaven.com"
}
}
},
{
"parameters": {
"operation": "text",
"options": {}
},
"id": "614dd424-0c37-4ee7-90e4-998b6068b424",
"name": "Extract Document Text",
"type": "n8n-nodes-base.extractFromFile",
"typeVersion": 1,
"position": [
920,
-200
],
"alwaysOutputData": true
},
{
"parameters": {
"model": "text-embedding-3-small",
"options": {}
},
"id": "55925637-26af-4db1-be79-65ea79ed5840",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1,
"position": [
1000,
-520
]
},
{
"parameters": {},
"id": "218455f6-5232-44f5-9b66-1c7591d6deed",
"name": "Postgres Chat Memory",
"type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
"typeVersion": 1,
"position": [
500,
-560
],
"notesInFlow": false
},
{
"parameters": {
"options": {}
},
"id": "c862a2c7-4e70-4ea2-8a0d-a803706e7802",
"name": "Recursive Character Text Splitter",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"typeVersion": 1,
"position": [
1320,
120
]
},
{
"parameters": {
"operation": "delete",
"tableId": "documents",
"filterType": "string",
"filterString": "=metadata->>file_id=like.*{{ $json.file_id }}*"
},
"id": "cbcaa635-ee36-4e5c-973c-bbb81d3c4a63",
"name": "Delete Old Doc Rows",
"type": "n8n-nodes-base.supabase",
"typeVersion": 1,
"position": [
360,
-200
],
"alwaysOutputData": true,
"credentials": {
"supabaseApi": {
"id": "BsSfMJvS3jGqfqc9",
"name": "Supabase N1mbox"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "10646eae-ae46-4327-a4dc-9987c2d76173",
"name": "file_id",
"value": "={{ $json.id }}",
"type": "string"
}
]
},
"options": {}
},
"id": "7a136950-0036-43f9-b416-f1391a401eb8",
"name": "Set File ID",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
40,
-200
]
},
{
"parameters": {
"content": "## Agente de IA con RAG y una Interfaz de Chat ",
"height": 464.8027193303974,
"width": 692.7866482806627
},
"id": "78c7cd51-2e1a-4010-8387-7ba96659b05d",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
80,
-860
]
},
{
"parameters": {
"public": true,
"options": {}
},
"id": "24f7ad35-e76d-4e3f-be42-f6f79f24fc29",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"typeVersion": 1.1,
"position": [
140,
-780
],
"webhookId": "e985d15f-b2f6-456d-be15-97e0b1544a40"
},
{
"parameters": {
"promptType": "define",
"text": "={{ $('When chat message received').item.json.chatInput }}",
"options": {
"systemMessage": "You are a personal assistant who helps answer questions from a corpus of documents when you don't know the answer yourself."
}
},
"id": "14ecdc54-6a3c-4c53-9c50-c1cfa0fb77db",
"name": "RAG AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.6,
"position": [
460,
-780
]
},
{
"parameters": {
"tableName": {
"__rl": true,
"value": "documents",
"mode": "list",
"cachedResultName": "documents"
},
"options": {
"queryName": "match_documents"
}
},
"id": "551e9f94-5b6a-4a52-bfda-9d6afb686f35",
"name": "Supabase Vector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"typeVersion": 1,
"position": [
840,
-640
]
},
{
"parameters": {
"mode": "insert",
"tableName": {
"__rl": true,
"value": "documents",
"mode": "list",
"cachedResultName": "documents"
},
"options": {
"queryName": "match_documents"
}
},
"id": "315f4dc1-ed9a-46b2-9b03-880f22dee7ce",
"name": "Insert into Supabase Vectorstore",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"typeVersion": 1,
"position": [
1200,
-300
]
}
],
"pinData": {},
"connections": {
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "RAG AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "Retrieve Documents",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Retrieve Documents": {
"ai_tool": [
[
{
"node": "RAG AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Download File": {
"main": [
[
{
"node": "Extract Document Text",
"type": "main",
"index": 0
}
]
]
},
"File Created": {
"main": [
[
{
"node": "Set File ID",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI": {
"ai_embedding": [
[
{
"node": "Supabase Vector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Extract Document Text": {
"main": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI1": {
"ai_embedding": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Default Data Loader": {
"ai_document": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "ai_document",
"index": 0
}
]
]
},
"Postgres Chat Memory": {
"ai_memory": [
[
{
"node": "RAG AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Recursive Character Text Splitter": {
"ai_textSplitter": [
[
{
"node": "Default Data Loader",
"type": "ai_textSplitter",
"index": 0
}
]
]
},
"Delete Old Doc Rows": {
"main": [
[
{
"node": "Download File",
"type": "main",
"index": 0
}
]
]
},
"Set File ID": {
"main": [
[
{
"node": "Delete Old Doc Rows",
"type": "main",
"index": 0
}
]
]
},
"File Updated": {
"main": [
[
{
"node": "Set File ID",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "RAG AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Supabase Vector Store": {
"ai_vectorStore": [
[
{
"node": "Retrieve Documents",
"type": "ai_vectorStore",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "65c28a45-d380-4b86-9f01-56cb304c7274",
"meta": {
"instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6"
},
"id": "LDh13q1qJPMGJwM5",
"tags": []
}