-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathSurvey Insights with Qdrant, Python and Information Extractor.json
More file actions
1272 lines (1272 loc) · 28.6 KB
/
Survey Insights with Qdrant, Python and Information Extractor.json
File metadata and controls
1272 lines (1272 loc) · 28.6 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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"meta": {
"instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9"
},
"nodes": [
{
"id": "0404384b-10b6-4666-84a4-8870db30c607",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
1220,
280
],
"parameters": {
"model": "text-embedding-3-small",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "a6741f04-5a5b-47a9-ac08-eb562f9f6052",
"name": "Default Data Loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
1340,
280
],
"parameters": {
"options": {
"metadata": {
"metadataValues": [
{
"name": "question",
"value": "={{ $json.question }}"
},
{
"name": "participant",
"value": "={{ $json.participant }}"
},
{
"name": "survey",
"value": "={{ $('Get Survey Results').params.documentId.cachedResultName }}"
}
]
}
},
"jsonData": "={{ $json.answer }}",
"jsonMode": "expressionData"
},
"typeVersion": 1
},
{
"id": "7663c3dd-f713-4034-bef6-0c000285f54f",
"name": "Convert to Question Answer Pairs",
"type": "n8n-nodes-base.set",
"position": [
720,
160
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "6b593ffb-ffbd-4cf5-a508-cd4f2a6d1004",
"name": "data",
"type": "array",
"value": "={{\n Object.keys($json)\n .filter(key => !['row_number', 'Participant'].includes(key))\n .map(key => ({ question: key, answer: $json[key], participant: $json.Participant }))\n}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "84873f0c-81ce-442f-a33c-d7c6c2efa11b",
"name": "Recursive Character Text Splitter",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"position": [
1340,
420
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "da9a8ee8-5e3f-49db-8d1f-26a61ca82344",
"name": "Get Survey Results",
"type": "n8n-nodes-base.googleSheets",
"position": [
540,
160
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-168Vm-1kCeHkqGLAs6odha4DhPE93njfHlYIviKE50/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1-168Vm-1kCeHkqGLAs6odha4DhPE93njfHlYIviKE50",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-168Vm-1kCeHkqGLAs6odha4DhPE93njfHlYIviKE50/edit?usp=drivesdk",
"cachedResultName": "Remote Working Survey Responses"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.4
},
{
"id": "4bad90b2-eefe-49c8-8caa-41cd4cb5e60f",
"name": "Get Survey Headers",
"type": "n8n-nodes-base.googleSheets",
"position": [
740,
940
],
"parameters": {
"options": {
"dataLocationOnSheet": {
"values": {
"range": "A1:Z2",
"rangeDefinition": "specifyRangeA1"
}
}
},
"sheetName": {
"__rl": true,
"mode": "id",
"value": "={{ $('Execute Workflow Trigger').first().json.sheetName }}"
},
"documentId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Execute Workflow Trigger').first().json.sheetID }}"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.4
},
{
"id": "47c64994-9d1f-42ca-a849-3eeab5335b66",
"name": "Extract Questions",
"type": "n8n-nodes-base.set",
"position": [
940,
940
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d655b165-dfa2-46cb-bc27-140399bc4227",
"name": "question",
"type": "array",
"value": "={{\n Object.keys($('Get Survey Headers').item.json)\n .filter(key => key.includes('?'))\n}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c237d523-b290-41ca-b323-4cc7c7f6ff37",
"name": "Questions to List",
"type": "n8n-nodes-base.splitOut",
"position": [
940,
1120
],
"parameters": {
"options": {},
"fieldToSplitOut": "question"
},
"typeVersion": 1
},
{
"id": "7f44a770-4c5d-4404-ae95-d9dee8348380",
"name": "Find All Answers",
"type": "n8n-nodes-base.httpRequest",
"position": [
1460,
1120
],
"parameters": {
"url": "=http://qdrant:6333/collections/{{ $('Set Variables').item.json.collectionName }}/points/scroll",
"method": "POST",
"options": {},
"jsonBody": "={\n \"limit\": 500,\n \"filter\":{\n \"must\": [\n {\n \"key\": \"metadata.question\",\n \"match\": { \"value\": \"{{ $('For Each Question...').item.json.question }}\" }\n },\n {\n \"key\": \"metadata.survey\",\n \"match\": { \"value\": \"{{ $('Set Variables').item.json.surveyName }}\" }\n }\n ]\n },\n \"with_vector\":true\n}",
"sendBody": true,
"specifyBody": "json",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "qdrantApi"
},
"credentials": {
"qdrantApi": {
"id": "NyinAS3Pgfik66w5",
"name": "QdrantApi account"
}
},
"typeVersion": 4.2
},
{
"id": "2b6dc317-f8f3-4201-a9e1-d35ee578e79e",
"name": "Get Payload of Points",
"type": "n8n-nodes-base.httpRequest",
"position": [
2380,
800
],
"parameters": {
"url": "=http://qdrant:6333/collections/{{ $('Set Variables').first().json.collectionName }}/points",
"method": "POST",
"options": {},
"jsonBody": "={{\n {\n \"ids\": $json.points,\n \"with_payload\": true\n }\n}}",
"sendBody": true,
"specifyBody": "json",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "qdrantApi"
},
"credentials": {
"qdrantApi": {
"id": "NyinAS3Pgfik66w5",
"name": "QdrantApi account"
}
},
"typeVersion": 4.2
},
{
"id": "d4a37d97-975a-4243-a7ea-81b3e30558a5",
"name": "Clusters To List",
"type": "n8n-nodes-base.splitOut",
"position": [
2180,
800
],
"parameters": {
"options": {},
"fieldToSplitOut": "output"
},
"typeVersion": 1
},
{
"id": "c78f1bf6-8390-48ee-88f4-7d1a893a8ade",
"name": "Set Variables",
"type": "n8n-nodes-base.set",
"position": [
200,
1060
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b77c94a0-d865-4bd6-b078-a09b2ddb2a99",
"name": "collectionName",
"type": "string",
"value": "ux_survey_insights"
},
{
"id": "7b0a4d14-b5f9-4597-84c0-8cfdb363c3d3",
"name": "surveyName",
"type": "string",
"value": "={{ $json.properties.title }}"
},
{
"id": "45434b3b-3b74-4262-82e0-7ed02155caad",
"name": "insightsSheetName",
"type": "string",
"value": "=Insights-{{ $now.format('yyyyMMdd') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "fbb1f3c3-06ad-44b5-b020-6fc3c8eda7c4",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
2560,
980
],
"parameters": {
"model": "gpt-4o-mini",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "83d3b413-a661-4c4c-9b8d-6ee395a15348",
"name": "Prep Output For Export",
"type": "n8n-nodes-base.set",
"position": [
3160,
1300
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "={{ {\n ...$json.output,\n \"Number of Response\": $('Get Payload of Points').item.json.result.length,\n \"Participant IDs\": $('Get Payload of Points').item.json.result.map(item =>\n item.payload.metadata.participant\n ).join(','),\n \"Raw Responses\": $('Get Payload of Points').item.json.result.map(item =>\n `Participant ${item.payload.metadata.participant},${item.payload.content.replaceAll('\"', '\\\"')}`\n ).join('\\n')\n} }}\n"
},
"typeVersion": 3.4
},
{
"id": "14784dff-a8ea-4b6b-8379-b0c9051a8f98",
"name": "Export To Sheets",
"type": "n8n-nodes-base.googleSheets",
"position": [
3360,
1300
],
"parameters": {
"columns": {
"value": {},
"schema": [
{
"id": "What is your name?",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "What is your name?",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "The responses indicate that two participants have the same name, 'Kwame Nkosi', which suggests a commonality in names or cultural naming traditions among the respondents. This could highlight the importance of understanding cultural context in survey responses.",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "The responses indicate that two participants have the same name, 'Kwame Nkosi', which suggests a commonality in names or cultural naming traditions among the respondents. This could highlight the importance of understanding cultural context in survey responses.",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "neutral",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "neutral",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "3",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "3",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "77,17,54",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "77,17,54",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Participant 77,Kwame Nkosi\nParticipant 17,Kwame Nkosi\nParticipant 54,Kwame Nkansah",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Participant 77,Kwame Nkosi\nParticipant 17,Kwame Nkosi\nParticipant 54,Kwame Nkansah",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "autoMapInputData",
"matchingColumns": []
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "name",
"value": "={{ $('Set Variables').first().json.insightsSheetName }}"
},
"documentId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Execute Workflow Trigger').first().json.sheetID }}"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.4
},
{
"id": "779b9411-db3e-44f3-ad2a-c9d40a70580d",
"name": "Export To Sheets1",
"type": "n8n-nodes-base.googleSheets",
"position": [
2360,
1300
],
"parameters": {
"columns": {
"value": {},
"schema": [],
"mappingMode": "autoMapInputData",
"matchingColumns": []
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "name",
"value": "={{ $('Set Variables').first().json.insightsSheetName }}"
},
"documentId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Execute Workflow Trigger').first().json.sheetID }}"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.4
},
{
"id": "a31ab677-f57c-4b78-a290-d4a913ed4f8e",
"name": "For Each Question...",
"type": "n8n-nodes-base.splitInBatches",
"position": [
1280,
940
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "dcfaf927-6ecd-4ebe-aee0-5fb3367b2725",
"name": "Trigger Insights",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
1980,
160
],
"parameters": {
"options": {},
"workflowId": "={{ $workflow.id }}"
},
"typeVersion": 1
},
{
"id": "2579adf0-9c00-4b87-b53e-740044577ab0",
"name": "Prep Values For Trigger",
"type": "n8n-nodes-base.set",
"position": [
1800,
160
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "24dd90ad-390f-444e-ba6c-8c06a41e836e",
"name": "sheetID",
"type": "string",
"value": "={{ $('Get Survey Results').params.documentId.value }}"
},
{
"id": "90199bbb-3938-411c-a7a8-faa7ccba6059",
"name": "sheetName",
"type": "string",
"value": "={{ $('Get Survey Results').params.sheetName.value }}"
}
]
}
},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "9b29e850-b9d0-4358-af62-92c20ab3b088",
"name": "Execute Workflow Trigger",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
20,
900
],
"parameters": {},
"typeVersion": 1
},
{
"id": "70a0dcec-9f74-4af2-bd64-0ab762a77e51",
"name": "Create Insights Sheet",
"type": "n8n-nodes-base.googleSheets",
"position": [
420,
900
],
"parameters": {
"title": "={{ $('Set Variables').first().json.insightsSheetName }}",
"options": {},
"operation": "create",
"documentId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Execute Workflow Trigger').first().json.sheetID }}"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.4,
"alwaysOutputData": true
},
{
"id": "f31400fb-dd7a-4c62-90ec-e9d78bbaa5e8",
"name": "Prep Values For Export",
"type": "n8n-nodes-base.set",
"position": [
2180,
1300
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "={\n \"Question\": \"{{ $('For Each Question...').item.json.question }}\",\n \"Insight\": \"No Insight Found\"\n}\n"
},
"typeVersion": 3.4
},
{
"id": "506c20df-5109-422c-8c9e-0eb50fbd3ff9",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
459.27570452141345,
-42.168106366729035
],
"parameters": {
"color": 7,
"width": 617.2130261221611,
"height": 420.7389587470384,
"content": "## Step 1. Import Survey Responses\n[Read more about Google Sheets](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlesheets)\n\nOur approach requires to import all participant responses as vectors with metadata linking them to the questions being answered. To do this, we'll generate questiona and answer pairs from the survey."
},
"typeVersion": 1
},
{
"id": "bddcafa8-6f54-4829-93c9-37bbb9e7edf3",
"name": "QA Pairs to List",
"type": "n8n-nodes-base.splitOut",
"position": [
900,
160
],
"parameters": {
"options": {},
"fieldToSplitOut": "data"
},
"typeVersion": 1
},
{
"id": "8d6e6bf6-c94c-43cb-a29e-5d10207cb8bd",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1100,
-102.05898437632061
],
"parameters": {
"color": 7,
"width": 563.8350682199533,
"height": 678.1641960508446,
"content": "## Step 2. Vectorize Each Response Into Qdrant\n[Read more about using Qdrant](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoreqdrant)\n\nSpecial attention is given to how metadata is captured as it becomes key to this workflow is being able to retrieve subsets of the data for analysis."
},
"typeVersion": 1
},
{
"id": "613d4a32-a87a-423e-a1d1-ee23db0de6d1",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1680,
-30.440883940004255
],
"parameters": {
"color": 7,
"width": 519.6419932444072,
"height": 429.11782776909047,
"content": "## Step 3. Trigger Insights SubWorkflow\n[Learn more about Workflow Triggers](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflow)\n\nA subworkflow is used to trigger the analysis for the survey. This separation is optional but used here to better demonstrate the two part process."
},
"typeVersion": 1
},
{
"id": "1e858e4a-b91b-4411-8e2a-6eb76647b796",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-57.47778952966382,
710.393394209128
],
"parameters": {
"color": 7,
"width": 668.3083616841852,
"height": 528.2386658883073,
"content": "## Step 4. Create Insights Sheet\n[Learn more about Workflow Triggers](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger)\n\nTo capture the generated insights, we'll create a new unique sheet within the survey spreadsheet. This is optional and you may want to capture in other datastores depending on your needs."
},
"typeVersion": 1
},
{
"id": "9170c566-07d3-49dc-aafb-2dbe79940d2c",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
640,
683.5153164275844
],
"parameters": {
"color": 7,
"width": 536.9288458983389,
"height": 622.1362463986454,
"content": "## Step 5. Get List Of Questions From Survey\n[Read more about using Google Sheets](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlesheets)\n\nNext we'll fetch the survey for metadata and questions, splitting them into separate workflow items. Our intention is to process each question end-to-end before moving to the next. This approach is a little \"safer\" in the scenario where an interruption occurs we won't lose all our work."
},
"typeVersion": 1
},
{
"id": "8488df77-055d-41cc-94f1-92ac5d54ef10",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1200,
673.291535602609
],
"parameters": {
"color": 7,
"width": 823.147012265536,
"height": 868.2579789328703,
"content": "## Step 6. Find Groups of Similar Answers For Each Question\n[Learn more about using the Code Node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/)\n\nGiving all the responses to an LLM to analyse is the common but naive approach; the summarisation is usually too high level for real insights and loses a lot of detail such as the number and identity of respondants. What we want to do instead is find and group popular answers for each question to ensure all perspectives are considered.\n\nOur approach does this by mapping our answer vectors to a 2D grid and then identifying where the vector points are \"clustered\"; where a group of points are within close proximity to each other."
},
"typeVersion": 1
},
{
"id": "f4748b6d-5bd8-48cf-942f-3a0dc681078d",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
2060,
1180
],
"parameters": {
"color": 7,
"width": 536.9288458983389,
"height": 359.90385684071794,
"content": "## Step 7b. Skip If No Clusters Found\nWhere no clusters were found, it means the answers were unique enough to not show any pattern. eg. \"What's you name?\""
},
"typeVersion": 1
},
{
"id": "d55d6a47-da8c-46ae-bd10-0eb671dcd121",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
2060,
611.6915003841909
],
"parameters": {
"color": 7,
"width": 871.451300407926,
"height": 541.1135860445843,
"content": "## Step 7a. Summarise the Top Groups of Similar Answers\n[Read more about using the Information Extractor Node](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.information-extractor)\n\nEach discovered cluster will return a reference vector which is used to fetch all related answers in the group.\nThe group is then sent to the LLM to summarise as well as assign a sentiment score."
},
"typeVersion": 1
},
{
"id": "e5d5f88f-5832-43fc-a5b9-f747d08e7e77",
"name": "Sticky Note8",
"type": "n8n-nodes-base.stickyNote",
"position": [
2620,
1180
],
"parameters": {
"color": 7,
"width": 924.2798021207429,
"height": 363.07347551845976,
"content": "## Step 8. Write To Insights Sheet\nFinally, our completed insights to appended to\nthe Insights Sheet we created earlier in the workflow."
},
"typeVersion": 1
},
{
"id": "49ac1504-7b43-4fa1-b4ce-15c7a53c9018",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"position": [
460,
400
],
"parameters": {
"color": 5,
"width": 323.2987132716669,
"height": 80,
"content": "### Run this once! \nIf for any reason you need to run more than once, be sure to clear the existing data first."
},
"typeVersion": 1
},
{
"id": "450f89c5-ef0f-4bf8-8db9-6347247c7f4d",
"name": "Has Clusters?",
"type": "n8n-nodes-base.if",
"position": [
1820,
1120
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "40b6bb62-a2d6-4422-8fbb-7ae49898bad9",
"operator": {
"type": "array",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json.output }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2
},
{
"id": "1652a108-8fb8-4229-a76d-abf9fbcff626",
"name": "Sticky Note10",
"type": "n8n-nodes-base.stickyNote",
"position": [
20,
-400
],
"parameters": {
"width": 400.381109509268,
"height": 679.5610243514676,
"content": "## Try It Out!\n\n### This workflow generates highly-detailed insights from survey responses. Works best when dealing with a large number of participants.\n\n* Import survey responses and vectorise in Qdrant vectorstore.\n* Identify clusters of popular responses to questions using K-means clustering algorithm. \n* Each valid cluster is analysed and summarised by LLM.\n* Export LLM response and cluster results back into sheet.\n\nCheck out the reference google sheet here: https://docs.google.com/spreadsheets/d/e/2PACX-1vT6m8XH8JWJTUAfwojc68NAUGC7q0lO7iV738J7aO5fuVjiVzdTRRPkMmT1C4N8TwejaiT0XrmF1Q48/pubhtml\n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/XPKeKXeB7d) or ask in the [Forum](https://community.n8n.io/)!\n\nHappy Hacking!"
},
"typeVersion": 1
},
{
"id": "6eef981e-b2ce-433c-b71f-78be64812a56",
"name": "Sticky Note11",
"type": "n8n-nodes-base.stickyNote",
"position": [
1260,
1340
],
"parameters": {
"color": 5,
"width": 323.2987132716669,
"height": 110.05160146874424,
"content": "### First Time Running?\nThere is a slight delay on first run because the code node has to download the required packages."
},
"typeVersion": 1
},
{
"id": "fa0c14be-03f4-4ed2-bd60-e93817382ded",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
240,
100
],
"parameters": {},
"typeVersion": 1
},
{
"id": "30323019-59ba-4a19-a46e-196d469f097d",
"name": "Get Sheet Details",
"type": "n8n-nodes-base.httpRequest",
"position": [
200,
900
],
"parameters": {
"url": "=https://sheets.googleapis.com/v4/spreadsheets/{{ $json.sheetID }}",
"options": {},
"authentication": "predefinedCredentialType",
"nodeCredentialType": "googleSheetsOAuth2Api"
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.2
},
{
"id": "6ced8012-1dd3-4da3-8c27-e4f4dfc959f6",
"name": "Only Clusters With 3+ points",
"type": "n8n-nodes-base.filter",
"position": [
2180,
960
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "328f806c-0792-4d90-9bee-a1e10049e78f",
"operator": {
"type": "array",
"operation": "lengthGt",
"rightType": "number"
},
"leftValue": "={{ $json.points }}",
"rightValue": 2
}
]
}
},
"typeVersion": 2
},
{
"id": "8ae81a55-75e2-40a3-bef6-0935ff08128f",
"name": "Apply K-means Clustering Algorithm",
"type": "n8n-nodes-base.code",
"position": [
1640,
1120
],
"parameters": {
"language": "python",
"pythonCode": "import numpy as np\nfrom sklearn.cluster import KMeans\n\n# get vectors for all answers\npoint_ids = [item.id for item in _input.first().json.result.points]\nvectors = [item.vector.to_py() for item in _input.first().json.result.points]\nvectors_array = np.array(vectors)\n\n# apply k-means clustering where n_clusters = 10\n# this is a max and we'll discard some of these clusters later\nkmeans = KMeans(n_clusters=min(len(vectors), 10), random_state=42).fit(vectors_array)\nlabels = kmeans.labels_\nunique_labels = set(labels)\n\n# Extract and print points in each cluster\nclusters = {}\nfor label in set(labels):\n clusters[label] = vectors_array[labels == label]\n\n# return Qdrant point ids for each cluster\n# we'll use these ids to fetch the payloads from the vector store.\noutput = []\nfor cluster_id, cluster_points in clusters.items():\n points = [point_ids[i] for i in range(len(labels)) if labels[i] == cluster_id]\n output.append({\n \"id\": f\"Cluster {cluster_id}\",\n \"total\": len(cluster_points),\n \"points\": points\n })\n\nreturn {\"json\": {\"output\": output } }"
},
"typeVersion": 2
},
{
"id": "cbb42384-d46b-471f-a7d8-27e3de042492",
"name": "Qdrant Vector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
"position": [
1220,
100
],
"parameters": {
"mode": "insert",
"options": {},
"qdrantCollection": {
"__rl": true,
"mode": "list",
"value": "ux_survey_insights",
"cachedResultName": "ux_survey_insights"
}
},
"credentials": {
"qdrantApi": {
"id": "NyinAS3Pgfik66w5",
"name": "QdrantApi account"
}
},
"typeVersion": 1
},
{
"id": "17584901-15d6-421f-ad69-3ba872276055",
"name": "Survey Insights Agent",
"type": "@n8n/n8n-nodes-langchain.informationExtractor",
"position": [
2580,
800
],
"parameters": {
"text": "=The {{ $json.result.length }} participant responses were:\n{{\n$json.result.map(item =>\n`* Participant ${item.payload.metadata.participant}: \"${item.payload.content.replaceAll('\"', '\\\"')}\"`\n).join('\\n')\n}}",
"options": {
"systemPromptTemplate": "=You help summarise a selection of participant responses to a specific question for a survey called \"{{ $json.result[0].payload.metadata.survey }}\".\nThe question asked was \"{{ $json.result[0].payload.metadata.question }}\".\nThe {{ $json.result.length }} participant responses were selected because their answers were similar in context.\n\nYour task is to: \n* summarise the given participant responses into a short paragraph. Provide an insight from this summary and what we could learn from the answers.\n* determine if the overall sentiment of all the listed responses to be either negative, mildy negative, neutral, mildy positive or positive."
},
"schemaType": "fromJson",
"jsonSchemaExample": "{\n\t\"Question\": \"What do you enjoy most about working remotely, and why?\",\n\t\"Insight\": \"\",\n \"Sentiment\": \"Positive\"\n}"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Has Clusters?": {
"main": [
[
{
"node": "Clusters To List",
"type": "main",
"index": 0
}
],
[
{
"node": "Prep Values For Export",
"type": "main",
"index": 0
}
]
]
},
"Set Variables": {
"main": [
[
{
"node": "Create Insights Sheet",
"type": "main",
"index": 0
}
]
]
},
"Clusters To List": {
"main": [
[
{
"node": "Only Clusters With 3+ points",
"type": "main",
"index": 0
}
]
]
},
"Export To Sheets": {
"main": [
[
{
"node": "For Each Question...",
"type": "main",
"index": 0
}
]
]
},
"Find All Answers": {
"main": [
[
{
"node": "Apply K-means Clustering Algorithm",
"type": "main",