@@ -173,7 +173,8 @@ describe("vectorize help", () => {
173
173
-v, --version Show version number [boolean]
174
174
175
175
OPTIONS
176
- --vector Vector to query the Vectorize Index [array] [required]
176
+ --vector Vector to query the Vectorize Index [array]
177
+ --vector-id Identifier for a vector in the index against which the index should be queried [string]
177
178
--top-k The number of results (nearest neighbors) to return [number] [default: 5]
178
179
--return-values Specify if the vector values should be included in the results [boolean] [default: false]
179
180
--return-metadata Specify if the vector metadata should be included in the results [string] [choices: \\"all\\", \\"indexed\\", \\"none\\"] [default: \\"none\\"]
@@ -523,87 +524,25 @@ describe("vectorize commands", () => {
523
524
await runWrangler (
524
525
"vectorize query test-index --vector 1 2 3 '4' 1.5 '2.6' a 'b' null 7 abc 8 undefined"
525
526
) ;
526
- expect ( std . out ) . toMatchInlineSnapshot ( `
527
- "📋 Searching for relevant vectors...
528
- {
529
- \\"count\\": 2,
530
- \\"matches\\": [
531
- {
532
- \\"id\\": \\"a\\",
533
- \\"score\\": 0.5,
534
- \\"values\\": [
535
- 1,
536
- 2,
537
- 3,
538
- 4
539
- ],
540
- \\"namespace\\": \\"abcd\\",
541
- \\"metadata\\": {
542
- \\"a\\": true,
543
- \\"b\\": 123
544
- }
545
- },
546
- {
547
- \\"id\\": \\"b\\",
548
- \\"score\\": 0.75,
549
- \\"values\\": [
550
- 5,
551
- 6,
552
- 7,
553
- 8
554
- ],
555
- \\"metadata\\": {
556
- \\"c\\": false,
557
- \\"b\\": \\"123\\"
558
- }
559
- }
560
- ]
561
- }"
562
- ` ) ;
527
+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
528
+ } ) ;
529
+
530
+ it ( "should handle a query with a vector-id" , async ( ) => {
531
+ mockVectorizeV2Request ( ) ;
532
+ await runWrangler ( "vectorize query test-index --vector-id some-vector-id" ) ;
533
+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
534
+
535
+ // No warning or error
536
+ expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
537
+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
563
538
} ) ;
564
539
565
540
it ( "should handle a query on a vectorize index with all options" , async ( ) => {
566
541
mockVectorizeV2Request ( ) ;
567
542
await runWrangler (
568
543
`vectorize query test-index --vector 1 2 3 '4' --top-k=2 --return-values=true --return-metadata=indexed --namespace=abc --filter '{ "p1": "abc", "p2": { "$ne": true }, "p3": 10, "p4": false, "nested.p5": "abcd" }'`
569
544
) ;
570
- expect ( std . out ) . toMatchInlineSnapshot ( `
571
- "📋 Searching for relevant vectors...
572
- {
573
- \\"count\\": 2,
574
- \\"matches\\": [
575
- {
576
- \\"id\\": \\"a\\",
577
- \\"score\\": 0.5,
578
- \\"values\\": [
579
- 1,
580
- 2,
581
- 3,
582
- 4
583
- ],
584
- \\"namespace\\": \\"abcd\\",
585
- \\"metadata\\": {
586
- \\"a\\": true,
587
- \\"b\\": 123
588
- }
589
- },
590
- {
591
- \\"id\\": \\"b\\",
592
- \\"score\\": 0.75,
593
- \\"values\\": [
594
- 5,
595
- 6,
596
- 7,
597
- 8
598
- ],
599
- \\"metadata\\": {
600
- \\"c\\": false,
601
- \\"b\\": \\"123\\"
602
- }
603
- }
604
- ]
605
- }"
606
- ` ) ;
545
+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
607
546
608
547
// No warning > Valid filter
609
548
expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
@@ -614,43 +553,7 @@ describe("vectorize commands", () => {
614
553
await runWrangler (
615
554
"vectorize query test-index --vector 1 2 3 '4' --filter='{ 'p1': [1,2,3] }'"
616
555
) ;
617
- expect ( std . out ) . toMatchInlineSnapshot ( `
618
- "📋 Searching for relevant vectors...
619
- {
620
- \\"count\\": 2,
621
- \\"matches\\": [
622
- {
623
- \\"id\\": \\"a\\",
624
- \\"score\\": 0.5,
625
- \\"values\\": [
626
- 1,
627
- 2,
628
- 3,
629
- 4
630
- ],
631
- \\"namespace\\": \\"abcd\\",
632
- \\"metadata\\": {
633
- \\"a\\": true,
634
- \\"b\\": 123
635
- }
636
- },
637
- {
638
- \\"id\\": \\"b\\",
639
- \\"score\\": 0.75,
640
- \\"values\\": [
641
- 5,
642
- 6,
643
- 7,
644
- 8
645
- ],
646
- \\"metadata\\": {
647
- \\"c\\": false,
648
- \\"b\\": \\"123\\"
649
- }
650
- }
651
- ]
652
- }"
653
- ` ) ;
556
+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
654
557
655
558
expect ( std . warn ) . toMatchInlineSnapshot ( `
656
559
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m🚨 Invalid query filter. Please use the recommended format.[0m
@@ -669,6 +572,34 @@ describe("vectorize commands", () => {
669
572
expect ( std . warn ) . toMatchInlineSnapshot ( `
670
573
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mCould not find any relevant vectors[0m
671
574
575
+ "
576
+ ` ) ;
577
+ } ) ;
578
+
579
+ it ( "should fail query when neither vector nor vector-id is provided" , async ( ) => {
580
+ mockVectorizeV2RequestError ( ) ;
581
+ await runWrangler (
582
+ "vectorize query test-index --top-k=2 --return-values=true"
583
+ ) ;
584
+ expect ( std . out ) . toMatchInlineSnapshot ( `""` ) ;
585
+
586
+ expect ( std . err ) . toMatchInlineSnapshot ( `
587
+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 Either vector or vector-id parameter must be provided, but not both.[0m
588
+
589
+ "
590
+ ` ) ;
591
+ } ) ;
592
+
593
+ it ( "should fail query when both vector and vector-id are provided" , async ( ) => {
594
+ mockVectorizeV2RequestError ( ) ;
595
+ await runWrangler (
596
+ "vectorize query test-index --vector 1 2 3 '4' --vector-id some-vector-id"
597
+ ) ;
598
+ expect ( std . out ) . toMatchInlineSnapshot ( `""` ) ;
599
+
600
+ expect ( std . err ) . toMatchInlineSnapshot ( `
601
+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 Either vector or vector-id parameter must be provided, but not both.[0m
602
+
672
603
"
673
604
` ) ;
674
605
} ) ;
@@ -866,6 +797,43 @@ describe("vectorize query filter", () => {
866
797
} ) ;
867
798
} ) ;
868
799
800
+ const querySnapshot = `
801
+ "📋 Searching for relevant vectors...
802
+ {
803
+ \\"count\\": 2,
804
+ \\"matches\\": [
805
+ {
806
+ \\"id\\": \\"a\\",
807
+ \\"score\\": 0.5,
808
+ \\"values\\": [
809
+ 1,
810
+ 2,
811
+ 3,
812
+ 4
813
+ ],
814
+ \\"namespace\\": \\"abcd\\",
815
+ \\"metadata\\": {
816
+ \\"a\\": true,
817
+ \\"b\\": 123
818
+ }
819
+ },
820
+ {
821
+ \\"id\\": \\"b\\",
822
+ \\"score\\": 0.75,
823
+ \\"values\\": [
824
+ 5,
825
+ 6,
826
+ 7,
827
+ 8
828
+ ],
829
+ \\"metadata\\": {
830
+ \\"c\\": false,
831
+ \\"b\\": \\"123\\"
832
+ }
833
+ }
834
+ ]
835
+ }"` ;
836
+
869
837
/** Create a mock handler for the Vectorize API */
870
838
function mockVectorizeRequest ( ) {
871
839
msw . use (
0 commit comments