forked from enescingoz/awesome-n8n-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpsert huge documents in a vector store with Supabase and Notion.json
More file actions
839 lines (839 loc) · 14.7 KB
/
Copy pathUpsert huge documents in a vector store with Supabase and Notion.json
File metadata and controls
839 lines (839 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
{
"id": "JxFP8FJ2W7e4Kmqn",
"meta": {
"instanceId": "fb8bc2e315f7f03c97140b30aa454a27bc7883a19000fa1da6e6b571bf56ad6d",
"templateCredsSetupCompleted": true
},
"name": "RAG on living data",
"tags": [],
"nodes": [
{
"id": "49086cdf-a38c-4cb8-9be9-d3e6ea5bdde5",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
1740,
1040
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "X7Jf0zECd3IkQdSw",
"name": "OpenAi (octionicsolutions)"
}
},
"typeVersion": 1
},
{
"id": "f0670721-92f4-422a-99c9-f9c2aa6fe21f",
"name": "Token Splitter",
"type": "@n8n/n8n-nodes-langchain.textSplitterTokenSplitter",
"position": [
2380,
540
],
"parameters": {
"chunkSize": 500
},
"typeVersion": 1
},
{
"id": "fe80ecac-4f79-4b07-ad8e-60ab5f980cba",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
1180,
-200
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "81b79248-08e8-4214-872b-1796e51ad0a4",
"name": "Question and Answer Chain",
"type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
"position": [
744,
495
],
"parameters": {
"options": {}
},
"typeVersion": 1.3
},
{
"id": "e78f7b63-baef-4834-8f1b-aecfa9102d6c",
"name": "Vector Store Retriever",
"type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
"position": [
844,
715
],
"parameters": {},
"typeVersion": 1
},
{
"id": "1d5ffbd0-b2cf-4660-a291-581d18608ecd",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
704,
715
],
"parameters": {
"model": "gpt-4o",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "X7Jf0zECd3IkQdSw",
"name": "OpenAi (octionicsolutions)"
}
},
"typeVersion": 1
},
{
"id": "37a3063f-aa21-4347-a72f-6dd316c58366",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
524,
495
],
"webhookId": "74479a54-418f-4de2-b70d-cfb3e3fdd5a7",
"parameters": {
"public": true,
"options": {}
},
"typeVersion": 1.1
},
{
"id": "5924bc01-1694-4b5c-8a06-7c46ee4c6425",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
520,
-200
],
"parameters": {
"rule": {
"interval": [
{
"field": "minutes",
"minutesInterval": 1
}
]
}
},
"typeVersion": 1.2
},
{
"id": "5067eda6-8bbe-407a-a6af-93e81be53661",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
620,
0
],
"parameters": {
"width": 329.16412916774584,
"height": 312.52803480051045,
"content": "## Switch trigger (optional)\nIf you are on the cloud plan, consider switching to the Notion Trigger Node instead, to save on executions."
},
"typeVersion": 1
},
{
"id": "33458828-484d-426b-a3d1-974a81c6162e",
"name": "Limit",
"type": "n8n-nodes-base.limit",
"position": [
1620,
-60
],
"parameters": {},
"typeVersion": 1
},
{
"id": "4d39503a-378e-4942-a5d4-8c62785aac44",
"name": "Limit1",
"type": "n8n-nodes-base.limit",
"position": [
2660,
-60
],
"parameters": {},
"typeVersion": 1
},
{
"id": "0e0b1391-3fe5-4d80-a2eb-a2483b79d9a6",
"name": "Delete old embeddings if exist",
"type": "n8n-nodes-base.supabase",
"position": [
1400,
-60
],
"parameters": {
"tableId": "documents",
"operation": "delete",
"filterType": "string",
"filterString": "=metadata->>id=eq.{{ $('Input Reference').item.json.id }}"
},
"credentials": {
"supabaseApi": {
"id": "DjIb4HMTYXhTU8Uc",
"name": "Supabase (VectorStore)"
}
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "4a8614e4-0a53-4731-bc68-57505d7d0a09",
"name": "Get page blocks",
"type": "n8n-nodes-base.notion",
"position": [
1840,
-60
],
"parameters": {
"blockId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Input Reference').item.json.id }}"
},
"resource": "block",
"operation": "getAll",
"returnAll": true,
"fetchNestedBlocks": true
},
"credentials": {
"notionApi": {
"id": "ObmaBA0dJss3JJPv",
"name": "Notion (octionicsolutions / Test)"
}
},
"executeOnce": true,
"typeVersion": 2.2
},
{
"id": "8c922895-49d6-4778-8356-6f6cf49e5420",
"name": "Default Data Loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
2300,
260
],
"parameters": {
"options": {
"metadata": {
"metadataValues": [
{
"name": "id",
"value": "={{ $('Input Reference').item.json.id }}"
},
{
"name": "name",
"value": "={{ $('Input Reference').item.json.name }}"
}
]
}
}
},
"typeVersion": 1
},
{
"id": "8ad7ff2e-4bc2-4821-ae03-bab2dc11d947",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
2220,
400
],
"parameters": {
"width": 376.2098538932132,
"height": 264.37628764336097,
"content": "## Adjust chunk size and overlap\nFor more accurate search results, increase the overlap. For the *text-embedding-ada-002* model the chunk size plus overlap must not exceed 8191"
},
"typeVersion": 1
},
{
"id": "8078d59a-f45f-4e96-a8ec-6c2f1c328e84",
"name": "Input Reference",
"type": "n8n-nodes-base.noOp",
"position": [
960,
-200
],
"parameters": {},
"typeVersion": 1
},
{
"id": "aae6c517-a316-40e3-aee9-1cc4b448689f",
"name": "Notion Trigger",
"type": "n8n-nodes-base.notionTrigger",
"disabled": true,
"position": [
740,
120
],
"parameters": {
"event": "pagedUpdatedInDatabase",
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"databaseId": {
"__rl": true,
"mode": "list",
"value": "ec6dc7b4-9ce0-47f7-8025-ef09295999fd",
"cachedResultUrl": "https://www.notion.so/ec6dc7b49ce047f78025ef09295999fd",
"cachedResultName": "Knowledge Base"
}
},
"credentials": {
"notionApi": {
"id": "ObmaBA0dJss3JJPv",
"name": "Notion (octionicsolutions / Test)"
}
},
"typeVersion": 1
},
{
"id": "3a43d66d-d4e3-4ca1-aee9-85ac65160e45",
"name": "Get updated pages",
"type": "n8n-nodes-base.notion",
"position": [
740,
-200
],
"parameters": {
"filters": {
"conditions": [
{
"key": "Last edited time|last_edited_time",
"condition": "equals",
"lastEditedTime": "={{ $now.minus(1, 'minutes').toISO() }}"
}
]
},
"options": {},
"resource": "databasePage",
"operation": "getAll",
"databaseId": {
"__rl": true,
"mode": "list",
"value": "ec6dc7b4-9ce0-47f7-8025-ef09295999fd",
"cachedResultUrl": "https://www.notion.so/ec6dc7b49ce047f78025ef09295999fd",
"cachedResultName": "Knowledge Base"
},
"filterType": "manual"
},
"credentials": {
"notionApi": {
"id": "ObmaBA0dJss3JJPv",
"name": "Notion (octionicsolutions / Test)"
}
},
"typeVersion": 2.2
},
{
"id": "bbf1296f-4e2b-4a38-bdf3-ae2b63cc7774",
"name": "Sticky Note23",
"type": "n8n-nodes-base.stickyNote",
"position": [
900,
-300
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "This placeholder serves as a reference point so it is easier to swap the data source with a different service"
},
"typeVersion": 1
},
{
"id": "631e1e10-0b52-4a17-89a4-769ac563321f",
"name": "Sticky Note24",
"type": "n8n-nodes-base.stickyNote",
"position": [
1340,
-160
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "All chunks of a previous version of the document are being deleted by filtering the meta data by the given ID"
},
"typeVersion": 1
},
{
"id": "6c830c83-4b70-4719-8e2a-26846e60085c",
"name": "Sticky Note25",
"type": "n8n-nodes-base.stickyNote",
"position": [
1560,
-160
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Reduce the active streams/items to just 1 to prevent the following nodes from double-processing"
},
"typeVersion": 1
},
{
"id": "46c8e4e4-0a5e-4ede-947b-5773710d4e55",
"name": "Sticky Note26",
"type": "n8n-nodes-base.stickyNote",
"position": [
1780,
-160
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Retrieve all page contents/blocks"
},
"typeVersion": 1
},
{
"id": "0369e610-d074-4812-9d04-8615b42965a5",
"name": "Sticky Note27",
"type": "n8n-nodes-base.stickyNote",
"position": [
2600,
-160
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Reduce the active streams/items to just 1 to prevent the following nodes from double-processing"
},
"typeVersion": 1
},
{
"id": "4f3bce54-1650-45fa-abb0-c881358c7e8d",
"name": "Sticky Note28",
"type": "n8n-nodes-base.stickyNote",
"position": [
2220,
-160
],
"parameters": {
"color": 7,
"width": 375.9283286479995,
"height": 275.841854198618,
"content": "Embed item and store in Vector Store. Depending on the length the content is being split up into multiple chunks/embeds"
},
"typeVersion": 1
},
{
"id": "44125921-e068-4a5d-a56b-b0e63c103556",
"name": "Supabase Vector Store1",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
924,
935
],
"parameters": {
"options": {},
"tableName": {
"__rl": true,
"mode": "list",
"value": "documents",
"cachedResultName": "documents"
}
},
"credentials": {
"supabaseApi": {
"id": "DjIb4HMTYXhTU8Uc",
"name": "Supabase (VectorStore)"
}
},
"typeVersion": 1
},
{
"id": "467322a9-949d-4569-aac6-92196da46ba5",
"name": "Sticky Note30",
"type": "n8n-nodes-base.stickyNote",
"position": [
460,
400
],
"parameters": {
"color": 7,
"width": 730.7522093855692,
"height": 668.724737081502,
"content": "Simple chat bot to ask specific questions while having access to the context of the Notion Knowledge Base which was stored in the Vector Store"
},
"typeVersion": 1
},
{
"id": "27f078cf-b309-4dd1-a8ce-b4fc504d6e29",
"name": "Sticky Note31",
"type": "n8n-nodes-base.stickyNote",
"position": [
1660,
900
],
"parameters": {
"color": 7,
"width": 219.31927574471658,
"height": 275.841854198618,
"content": "Model used for both creating and reading embeddings"
},
"typeVersion": 1
},
{
"id": "2f59cba1-4318-47e7-bf0b-b908d4186b86",
"name": "Supabase Vector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
2280,
-60
],
"parameters": {
"mode": "insert",
"options": {},
"tableName": {
"__rl": true,
"mode": "list",
"value": "documents",
"cachedResultName": "documents"
}
},
"credentials": {
"supabaseApi": {
"id": "DjIb4HMTYXhTU8Uc",
"name": "Supabase (VectorStore)"
}
},
"typeVersion": 1
},
{
"id": "729849e7-0eff-40c2-ae00-ae660c1eec69",
"name": "Sticky Note32",
"type": "n8n-nodes-base.stickyNote",
"position": [
1120,
-300
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Process each page/document separately."
},
"typeVersion": 1
},
{
"id": "3f632a24-ca0a-45c4-801d-041aa3f887a7",
"name": "Sticky Note29",
"type": "n8n-nodes-base.stickyNote",
"position": [
2220,
120
],
"parameters": {
"color": 7,
"width": 376.0759088111347,
"height": 275.841854198618,
"content": "Store additional meta data with each embed, especially the Notion ID, which can be later used to find all belonging entries of one page, even if they got split into multiple embeds."
},
"typeVersion": 1
},
{
"id": "ffaf3861-5287-4f57-8372-09216a18cb4d",
"name": "Sticky Note33",
"type": "n8n-nodes-base.stickyNote",
"position": [
460,
-300
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Using a manual approach for polling data from Notion for more accuracy."
},
"typeVersion": 1
},
{
"id": "cbbedfc0-4d64-42a6-8f55-21e04887305f",
"name": "Sticky Note34",
"type": "n8n-nodes-base.stickyNote",
"position": [
680,
-300
],
"parameters": {
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "## Select Database\nChoose the database which represents your Knowledge Base"
},
"typeVersion": 1
},
{
"id": "8b6767f2-1bc9-42fb-b319-f39f6734b9f2",
"name": "Sticky Note35",
"type": "n8n-nodes-base.stickyNote",
"position": [
2000,
-160
],
"parameters": {
"color": 7,
"width": 216.47293010628914,
"height": 275.841854198618,
"content": "Combine all contents to a single text formatted into one line which can be easily stored as an embed"
},
"typeVersion": 1
},
{
"id": "cdff1756-77d7-421e-8672-25c9862840b0",
"name": "Concatenate to single string",
"type": "n8n-nodes-base.summarize",
"position": [
2060,
-60
],
"parameters": {
"options": {},
"fieldsToSummarize": {
"values": [
{
"field": "content",
"separateBy": "\n",
"aggregation": "concatenate"
}
]
}
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "51075175-868a-4a3a-9580-5ad55e25ac71",
"connections": {
"Limit": {
"main": [
[
{
"node": "Get page blocks",
"type": "main",
"index": 0
}
]
]
},
"Limit1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Notion Trigger": {
"main": [
[
{
"node": "Input Reference",
"type": "main",
"index": 0
}
]
]
},
"Token Splitter": {
"ai_textSplitter": [
[
{
"node": "Default Data Loader",
"type": "ai_textSplitter",
"index": 0
}
]
]
},
"Get page blocks": {
"main": [
[
{
"node": "Concatenate to single string",
"type": "main",
"index": 0
}
]
]
},
"Input Reference": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Delete old embeddings if exist",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get updated pages",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI": {
"ai_embedding": [
[
{
"node": "Supabase Vector Store",
"type": "ai_embedding",
"index": 0
},
{
"node": "Supabase Vector Store1",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Get updated pages": {
"main": [
[
{
"node": "Input Reference",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Question and Answer Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Default Data Loader": {
"ai_document": [
[
{
"node": "Supabase Vector Store",
"type": "ai_document",
"index": 0
}
]
]
},
"Supabase Vector Store": {
"main": [
[
{
"node": "Limit1",
"type": "main",
"index": 0
}
]
]
},
"Supabase Vector Store1": {
"ai_vectorStore": [
[
{
"node": "Vector Store Retriever",
"type": "ai_vectorStore",
"index": 0
}
]
]
},
"Vector Store Retriever": {
"ai_retriever": [
[
{
"node": "Question and Answer Chain",
"type": "ai_retriever",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "Question and Answer Chain",
"type": "main",
"index": 0
}
]
]
},
"Concatenate to single string": {
"main": [
[
{
"node": "Supabase Vector Store",
"type": "main",
"index": 0
}
]
]
},
"Delete old embeddings if exist": {
"main": [
[
{
"node": "Limit",
"type": "main",
"index": 0
}
]
]
}
}
}