@@ -346,7 +346,7 @@ export function uiConfigToWorkspaceFlow(
346
346
edges . push ( ...searchWorkspaceFlow . edges ) ;
347
347
348
348
return {
349
- nodes,
349
+ nodes : nodes . map ( ( node ) => addDefaults ( node ) ) ,
350
350
edges,
351
351
} ;
352
352
}
@@ -368,73 +368,42 @@ function ingestConfigToWorkspaceFlow(
368
368
height : 400 ,
369
369
} ,
370
370
className : 'reactflow__group-node__ingest' ,
371
- selectable : false ,
372
- draggable : false ,
373
- deletable : false ,
374
371
} as ReactFlowComponent ;
375
372
376
373
nodes . push ( parentNode ) ;
377
374
375
+ // By default, always include a document node and an index node.
376
+ const docNodeId = generateId ( COMPONENT_CLASS . DOCUMENT ) ;
377
+ const docNode = {
378
+ id : docNodeId ,
379
+ position : { x : 100 , y : 70 } ,
380
+ data : initComponentData ( new Document ( ) . toObj ( ) , docNodeId ) ,
381
+ type : NODE_CATEGORY . CUSTOM ,
382
+ parentNode : parentNode . id ,
383
+ extent : 'parent' ,
384
+ } as ReactFlowComponent ;
385
+ const indexNodeId = generateId ( COMPONENT_CLASS . KNN_INDEXER ) ;
386
+ const indexNode = {
387
+ id : indexNodeId ,
388
+ position : { x : 900 , y : 70 } ,
389
+ data : initComponentData ( new KnnIndexer ( ) . toObj ( ) , indexNodeId ) ,
390
+ type : NODE_CATEGORY . CUSTOM ,
391
+ parentNode : parentNode . id ,
392
+ extent : 'parent' ,
393
+ } as ReactFlowComponent ;
394
+ nodes . push ( docNode , indexNode ) ;
395
+
378
396
// Get nodes/edges from the sub-configurations
379
- const sourceWorkspaceFlow = sourceConfigToWorkspaceFlow (
380
- ingestConfig . source ,
381
- parentNode . id
382
- ) ;
383
397
const enrichWorkspaceFlow = enrichConfigToWorkspaceFlow (
384
398
ingestConfig . enrich ,
385
399
parentNode . id
386
400
) ;
387
- const indexWorkspaceFlow = indexConfigToWorkspaceFlow (
388
- ingestConfig . index ,
389
- parentNode . id
390
- ) ;
391
401
392
- nodes . push (
393
- ...sourceWorkspaceFlow . nodes ,
394
- ...enrichWorkspaceFlow . nodes ,
395
- ...indexWorkspaceFlow . nodes
396
- ) ;
397
- edges . push (
398
- ...sourceWorkspaceFlow . edges ,
399
- ...enrichWorkspaceFlow . edges ,
400
- ...indexWorkspaceFlow . edges
401
- ) ;
402
+ nodes . push ( ...enrichWorkspaceFlow . nodes ) ;
403
+ edges . push ( ...enrichWorkspaceFlow . edges ) ;
402
404
403
405
// Link up the set of localized nodes/edges per sub-workflow
404
- edges . push (
405
- ...getIngestEdges (
406
- sourceWorkspaceFlow ,
407
- enrichWorkspaceFlow ,
408
- indexWorkspaceFlow
409
- )
410
- ) ;
411
-
412
- return {
413
- nodes,
414
- edges,
415
- } ;
416
- }
417
-
418
- // TODO: make more generic.
419
- // Currently hardcoding a single Document node as the source.
420
- function sourceConfigToWorkspaceFlow (
421
- sourceConfig : IConfig ,
422
- parentNodeId : string
423
- ) : WorkspaceFlowState {
424
- const nodes = [ ] as ReactFlowComponent [ ] ;
425
- const edges = [ ] as ReactFlowEdge [ ] ;
426
-
427
- const docNodeId = generateId ( COMPONENT_CLASS . DOCUMENT ) ;
428
- nodes . push ( {
429
- id : docNodeId ,
430
- position : { x : 100 , y : 70 } ,
431
- data : initComponentData ( new Document ( ) . toObj ( ) , docNodeId ) ,
432
- type : NODE_CATEGORY . CUSTOM ,
433
- parentNode : parentNodeId ,
434
- extent : 'parent' ,
435
- draggable : true ,
436
- deletable : false ,
437
- } ) ;
406
+ edges . push ( ...getIngestEdges ( docNode , enrichWorkspaceFlow , indexNode ) ) ;
438
407
439
408
return {
440
409
nodes,
@@ -481,107 +450,43 @@ function enrichConfigToWorkspaceFlow(
481
450
type : NODE_CATEGORY . CUSTOM ,
482
451
parentNode : parentNodeId ,
483
452
extent : 'parent' ,
484
- draggable : true ,
485
- deletable : false ,
486
453
} ) ;
487
454
return {
488
455
nodes,
489
456
edges,
490
457
} ;
491
458
}
492
459
493
- function indexConfigToWorkspaceFlow (
494
- indexConfig : IndexConfig ,
495
- parentNodeId : string
496
- ) : WorkspaceFlowState {
497
- const nodes = [ ] as ReactFlowComponent [ ] ;
498
- const edges = [ ] as ReactFlowEdge [ ] ;
499
-
500
- const indexNodeId = generateId ( COMPONENT_CLASS . KNN_INDEXER ) ;
501
- nodes . push ( {
502
- id : indexNodeId ,
503
- position : { x : 900 , y : 70 } ,
504
- data : initComponentData ( new KnnIndexer ( ) . toObj ( ) , indexNodeId ) ,
505
- type : NODE_CATEGORY . CUSTOM ,
506
- parentNode : parentNodeId ,
507
- extent : 'parent' ,
508
- draggable : true ,
509
- deletable : false ,
510
- } ) ;
511
-
512
- return {
513
- nodes,
514
- edges,
515
- } ;
516
- }
517
-
518
460
// Given the set of localized flows per sub-configuration, generate the global ingest-level edges.
519
461
// This takes the assumption the flow is linear, and all sub-configuration flows are fully connected.
520
462
function getIngestEdges (
521
- sourceFlow : WorkspaceFlowState ,
463
+ docNode : ReactFlowComponent ,
522
464
enrichFlow : WorkspaceFlowState ,
523
- indexFlow : WorkspaceFlowState
465
+ indexNode : ReactFlowComponent
524
466
) : ReactFlowEdge [ ] {
525
- const startAndEndNodesSource = getStartAndEndNodes ( sourceFlow ) as {
526
- startNode : ReactFlowComponent ;
527
- endNode : ReactFlowComponent ;
528
- } ;
529
- // May be undefined if no ingest processors defined
530
467
const startAndEndNodesEnrich = getStartAndEndNodes ( enrichFlow ) ;
531
- const startAndEndNodesIndex = getStartAndEndNodes ( indexFlow ) as {
532
- startNode : ReactFlowComponent ;
533
- endNode : ReactFlowComponent ;
534
- } ;
535
468
536
469
// Users may omit search request processors altogether. Need to handle cases separately.
537
470
if ( startAndEndNodesEnrich !== undefined ) {
538
471
const sourceToEnrichEdgeId = generateId ( 'edge' ) ;
539
472
const enrichToIndexEdgeId = generateId ( 'edge' ) ;
540
473
541
474
return [
542
- {
543
- id : sourceToEnrichEdgeId ,
544
- key : sourceToEnrichEdgeId ,
545
- source : startAndEndNodesSource . endNode . id ,
546
- target : startAndEndNodesEnrich . startNode . id ,
547
- markerEnd : {
548
- type : MarkerType . ArrowClosed ,
549
- width : 20 ,
550
- height : 20 ,
551
- } ,
552
- zIndex : 2 ,
553
- deletable : false ,
554
- } ,
555
- {
556
- id : enrichToIndexEdgeId ,
557
- key : enrichToIndexEdgeId ,
558
- source : startAndEndNodesEnrich . endNode . id ,
559
- target : startAndEndNodesIndex . startNode . id ,
560
- markerEnd : {
561
- type : MarkerType . ArrowClosed ,
562
- width : 20 ,
563
- height : 20 ,
564
- } ,
565
- zIndex : 2 ,
566
- deletable : false ,
567
- } ,
475
+ generateReactFlowEdge (
476
+ sourceToEnrichEdgeId ,
477
+ docNode . id ,
478
+ startAndEndNodesEnrich . startNode . id
479
+ ) ,
480
+ generateReactFlowEdge (
481
+ enrichToIndexEdgeId ,
482
+ startAndEndNodesEnrich . endNode . id ,
483
+ indexNode . id
484
+ ) ,
568
485
] as ReactFlowEdge [ ] ;
569
486
} else {
570
487
const sourceToIndexEdgeId = generateId ( 'edge' ) ;
571
488
return [
572
- {
573
- id : sourceToIndexEdgeId ,
574
- key : sourceToIndexEdgeId ,
575
- source : startAndEndNodesSource . endNode . id ,
576
- target : startAndEndNodesIndex . startNode . id ,
577
- markerEnd : {
578
- type : MarkerType . ArrowClosed ,
579
- width : 20 ,
580
- height : 20 ,
581
- } ,
582
- zIndex : 2 ,
583
- deletable : false ,
584
- } ,
489
+ generateReactFlowEdge ( sourceToIndexEdgeId , docNode . id , indexNode . id ) ,
585
490
] as ReactFlowEdge [ ] ;
586
491
}
587
492
}
@@ -603,14 +508,20 @@ function searchConfigToWorkspaceFlow(
603
508
height : 400 ,
604
509
} ,
605
510
className : 'reactflow__group-node__search' ,
606
- selectable : true ,
607
- draggable : true ,
608
- deletable : false ,
609
511
} as ReactFlowComponent ;
610
512
611
513
nodes . push ( parentNode ) ;
612
514
613
- // By default, always include an index node and a results node.
515
+ // By default, always include a query node, an index node, and a results node.
516
+ const queryNodeId = generateId ( COMPONENT_CLASS . NEURAL_QUERY ) ;
517
+ const queryNode = {
518
+ id : queryNodeId ,
519
+ position : { x : 100 , y : 70 } ,
520
+ data : initComponentData ( new NeuralQuery ( ) . toObj ( ) , queryNodeId ) ,
521
+ type : NODE_CATEGORY . CUSTOM ,
522
+ parentNode : parentNode . id ,
523
+ extent : 'parent' ,
524
+ } as ReactFlowComponent ;
614
525
const indexNodeId = generateId ( COMPONENT_CLASS . KNN_INDEXER ) ;
615
526
const indexNode = {
616
527
id : indexNodeId ,
@@ -619,8 +530,6 @@ function searchConfigToWorkspaceFlow(
619
530
type : NODE_CATEGORY . CUSTOM ,
620
531
parentNode : parentNode . id ,
621
532
extent : 'parent' ,
622
- draggable : true ,
623
- deletable : false ,
624
533
} as ReactFlowComponent ;
625
534
const resultsNodeId = generateId ( COMPONENT_CLASS . RESULTS ) ;
626
535
const resultsNode = {
@@ -630,16 +539,10 @@ function searchConfigToWorkspaceFlow(
630
539
type : NODE_CATEGORY . CUSTOM ,
631
540
parentNode : parentNode . id ,
632
541
extent : 'parent' ,
633
- draggable : true ,
634
- deletable : false ,
635
542
} as ReactFlowComponent ;
636
- nodes . push ( indexNode , resultsNode ) ;
543
+ nodes . push ( queryNode , indexNode , resultsNode ) ;
637
544
638
545
// Get nodes/edges from the sub-configurations
639
- const requestWorkspaceFlow = requestConfigToWorkspaceFlow (
640
- searchConfig . request ,
641
- parentNode . id
642
- ) ;
643
546
const enrichRequestWorkspaceFlow = enrichRequestConfigToWorkspaceFlow (
644
547
searchConfig . enrichRequest ,
645
548
parentNode . id
@@ -650,20 +553,18 @@ function searchConfigToWorkspaceFlow(
650
553
) ;
651
554
652
555
nodes . push (
653
- ...requestWorkspaceFlow . nodes ,
654
556
...enrichRequestWorkspaceFlow . nodes ,
655
557
...enrichResponseWorkspaceFlow . nodes
656
558
) ;
657
559
edges . push (
658
- ...requestWorkspaceFlow . edges ,
659
560
...enrichRequestWorkspaceFlow . edges ,
660
561
...enrichResponseWorkspaceFlow . edges
661
562
) ;
662
563
663
564
// Link up the set of localized nodes/edges per sub-workflow
664
565
edges . push (
665
566
...getSearchEdges (
666
- requestWorkspaceFlow ,
567
+ queryNode ,
667
568
enrichRequestWorkspaceFlow ,
668
569
indexNode ,
669
570
enrichResponseWorkspaceFlow ,
@@ -677,33 +578,6 @@ function searchConfigToWorkspaceFlow(
677
578
} ;
678
579
}
679
580
680
- // TODO: make more generic.
681
- // Currently hardcoding a single NeuralQuery node as the source.
682
- function requestConfigToWorkspaceFlow (
683
- requestConfig : IConfig ,
684
- parentNodeId : string
685
- ) : WorkspaceFlowState {
686
- const nodes = [ ] as ReactFlowComponent [ ] ;
687
- const edges = [ ] as ReactFlowEdge [ ] ;
688
-
689
- const queryNodeId = generateId ( COMPONENT_CLASS . NEURAL_QUERY ) ;
690
- nodes . push ( {
691
- id : queryNodeId ,
692
- position : { x : 100 , y : 70 } ,
693
- data : initComponentData ( new NeuralQuery ( ) . toObj ( ) , queryNodeId ) ,
694
- type : NODE_CATEGORY . CUSTOM ,
695
- parentNode : parentNodeId ,
696
- extent : 'parent' ,
697
- draggable : true ,
698
- deletable : false ,
699
- } ) ;
700
-
701
- return {
702
- nodes,
703
- edges,
704
- } ;
705
- }
706
-
707
581
// TODO: implement this
708
582
function enrichRequestConfigToWorkspaceFlow (
709
583
enrichConfig : IConfig ,
@@ -735,19 +609,13 @@ function enrichResponseConfigToWorkspaceFlow(
735
609
// Given the set of localized flows per sub-configuration, generate the global search-level edges.
736
610
// This takes the assumption the flow is linear, and all sub-configuration flows are fully connected.
737
611
function getSearchEdges (
738
- requestFlow : WorkspaceFlowState ,
612
+ queryNode : ReactFlowComponent ,
739
613
enrichRequestFlow : WorkspaceFlowState ,
740
614
indexNode : ReactFlowComponent ,
741
615
enrichResponseFlow : WorkspaceFlowState ,
742
616
resultsNode : ReactFlowComponent
743
617
) : ReactFlowEdge [ ] {
744
- const startAndEndNodesRequest = getStartAndEndNodes ( requestFlow ) as {
745
- startNode : ReactFlowComponent ;
746
- endNode : ReactFlowComponent ;
747
- } ;
748
- // May be undefined if no search request processors defined
749
618
const startAndEndNodesEnrichRequest = getStartAndEndNodes ( enrichRequestFlow ) ;
750
- // May be undefined if no search response processors defined
751
619
const startAndEndNodesEnrichResponse = getStartAndEndNodes (
752
620
enrichResponseFlow
753
621
) ;
@@ -759,49 +627,24 @@ function getSearchEdges(
759
627
const enrichRequestToIndexEdgeId = generateId ( 'edge' ) ;
760
628
edges . push (
761
629
...( [
762
- {
763
- id : requestToEnrichRequestEdgeId ,
764
- key : requestToEnrichRequestEdgeId ,
765
- source : startAndEndNodesRequest ?. endNode . id ,
766
- target : startAndEndNodesEnrichRequest . startNode . id ,
767
- markerEnd : {
768
- type : MarkerType . ArrowClosed ,
769
- width : 20 ,
770
- height : 20 ,
771
- } ,
772
- zIndex : 2 ,
773
- deletable : false ,
774
- } ,
775
- {
776
- id : enrichRequestToIndexEdgeId ,
777
- key : enrichRequestToIndexEdgeId ,
778
- source : startAndEndNodesEnrichRequest . endNode . id ,
779
- target : indexNode . id ,
780
- markerEnd : {
781
- type : MarkerType . ArrowClosed ,
782
- width : 20 ,
783
- height : 20 ,
784
- } ,
785
- zIndex : 2 ,
786
- deletable : false ,
787
- } ,
630
+ generateReactFlowEdge (
631
+ requestToEnrichRequestEdgeId ,
632
+ queryNode . id ,
633
+ startAndEndNodesEnrichRequest . startNode . id
634
+ ) ,
635
+
636
+ generateReactFlowEdge (
637
+ enrichRequestToIndexEdgeId ,
638
+ startAndEndNodesEnrichRequest . endNode . id ,
639
+ indexNode . id
640
+ ) ,
788
641
] as ReactFlowEdge [ ] )
789
642
) ;
790
643
} else {
791
644
const requestToIndexEdgeId = generateId ( 'edge' ) ;
792
- edges . push ( {
793
- id : requestToIndexEdgeId ,
794
- key : requestToIndexEdgeId ,
795
- source : startAndEndNodesRequest ?. endNode . id ,
796
- target : indexNode . id ,
797
- markerEnd : {
798
- type : MarkerType . ArrowClosed ,
799
- width : 20 ,
800
- height : 20 ,
801
- } ,
802
- zIndex : 2 ,
803
- deletable : false ,
804
- } as ReactFlowEdge ) ;
645
+ edges . push (
646
+ generateReactFlowEdge ( requestToIndexEdgeId , queryNode . id , indexNode . id )
647
+ ) ;
805
648
}
806
649
807
650
// Users may omit search response processors altogether. Need to handle cases separately.
@@ -811,49 +654,23 @@ function getSearchEdges(
811
654
812
655
edges . push (
813
656
...( [
814
- {
815
- id : indexToEnrichResponseEdgeId ,
816
- key : indexToEnrichResponseEdgeId ,
817
- source : indexNode . id ,
818
- target : startAndEndNodesEnrichResponse . startNode . id ,
819
- markerEnd : {
820
- type : MarkerType . ArrowClosed ,
821
- width : 20 ,
822
- height : 20 ,
823
- } ,
824
- zIndex : 2 ,
825
- deletable : false ,
826
- } ,
827
- {
828
- id : enrichResponseToResultsEdgeId ,
829
- key : enrichResponseToResultsEdgeId ,
830
- source : startAndEndNodesEnrichResponse . endNode . id ,
831
- target : resultsNode . id ,
832
- markerEnd : {
833
- type : MarkerType . ArrowClosed ,
834
- width : 20 ,
835
- height : 20 ,
836
- } ,
837
- zIndex : 2 ,
838
- deletable : false ,
839
- } ,
657
+ generateReactFlowEdge (
658
+ indexToEnrichResponseEdgeId ,
659
+ indexNode . id ,
660
+ startAndEndNodesEnrichResponse . startNode . id
661
+ ) ,
662
+ generateReactFlowEdge (
663
+ enrichResponseToResultsEdgeId ,
664
+ startAndEndNodesEnrichResponse . endNode . id ,
665
+ resultsNode . id
666
+ ) ,
840
667
] as ReactFlowEdge [ ] )
841
668
) ;
842
669
} else {
843
670
const indexToResultsEdgeId = generateId ( 'edge' ) ;
844
- edges . push ( {
845
- id : indexToResultsEdgeId ,
846
- key : indexToResultsEdgeId ,
847
- source : indexNode . id ,
848
- target : resultsNode . id ,
849
- markerEnd : {
850
- type : MarkerType . ArrowClosed ,
851
- width : 20 ,
852
- height : 20 ,
853
- } ,
854
- zIndex : 2 ,
855
- deletable : false ,
856
- } as ReactFlowEdge ) ;
671
+ edges . push (
672
+ generateReactFlowEdge ( indexToResultsEdgeId , indexNode . id , resultsNode . id )
673
+ ) ;
857
674
}
858
675
859
676
return edges ;
@@ -891,3 +708,32 @@ function getStartAndEndNodes(
891
708
) [ 0 ] ,
892
709
} ;
893
710
}
711
+
712
+ function addDefaults ( component : ReactFlowComponent ) : ReactFlowComponent {
713
+ return {
714
+ ...component ,
715
+ draggable : false ,
716
+ selectable : false ,
717
+ deletable : false ,
718
+ } ;
719
+ }
720
+
721
+ function generateReactFlowEdge (
722
+ id : string ,
723
+ source : string ,
724
+ target : string
725
+ ) : ReactFlowEdge {
726
+ return {
727
+ id,
728
+ key : id ,
729
+ source,
730
+ target,
731
+ markerEnd : {
732
+ type : MarkerType . ArrowClosed ,
733
+ width : 20 ,
734
+ height : 20 ,
735
+ } ,
736
+ zIndex : 2 ,
737
+ deletable : false ,
738
+ } as ReactFlowEdge ;
739
+ }
0 commit comments