@@ -170,7 +170,8 @@ describe("vectorize help", () => {
170170 -v, --version Show version number [boolean]
171171
172172 OPTIONS
173- --vector Vector to query the Vectorize Index [array] [required]
173+ --vector Vector to query the Vectorize Index [array]
174+ --vector-id Identifier for a vector in the index against which the index should be queried [string]
174175 --top-k The number of results (nearest neighbors) to return [number] [default: 5]
175176 --return-values Specify if the vector values should be included in the results [boolean] [default: false]
176177 --return-metadata Specify if the vector metadata should be included in the results [string] [choices: \\"all\\", \\"indexed\\", \\"none\\"] [default: \\"none\\"]
@@ -514,87 +515,25 @@ describe("vectorize commands", () => {
514515 await runWrangler (
515516 "vectorize query test-index --vector 1 2 3 '4' 1.5 '2.6' a 'b' null 7 abc 8 undefined"
516517 ) ;
517- expect ( std . out ) . toMatchInlineSnapshot ( `
518- "📋 Searching for relevant vectors...
519- {
520- \\"count\\": 2,
521- \\"matches\\": [
522- {
523- \\"id\\": \\"a\\",
524- \\"score\\": 0.5,
525- \\"values\\": [
526- 1,
527- 2,
528- 3,
529- 4
530- ],
531- \\"namespace\\": \\"abcd\\",
532- \\"metadata\\": {
533- \\"a\\": true,
534- \\"b\\": 123
535- }
536- },
537- {
538- \\"id\\": \\"b\\",
539- \\"score\\": 0.75,
540- \\"values\\": [
541- 5,
542- 6,
543- 7,
544- 8
545- ],
546- \\"metadata\\": {
547- \\"c\\": false,
548- \\"b\\": \\"123\\"
549- }
550- }
551- ]
552- }"
553- ` ) ;
518+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
519+ } ) ;
520+
521+ it ( "should handle a query with a vector-id" , async ( ) => {
522+ mockVectorizeV2Request ( ) ;
523+ await runWrangler ( "vectorize query test-index --vector-id some-vector-id" ) ;
524+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
525+
526+ // No warning or error
527+ expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
528+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
554529 } ) ;
555530
556531 it ( "should handle a query on a vectorize index with all options" , async ( ) => {
557532 mockVectorizeV2Request ( ) ;
558533 await runWrangler (
559534 `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" }'`
560535 ) ;
561- expect ( std . out ) . toMatchInlineSnapshot ( `
562- "📋 Searching for relevant vectors...
563- {
564- \\"count\\": 2,
565- \\"matches\\": [
566- {
567- \\"id\\": \\"a\\",
568- \\"score\\": 0.5,
569- \\"values\\": [
570- 1,
571- 2,
572- 3,
573- 4
574- ],
575- \\"namespace\\": \\"abcd\\",
576- \\"metadata\\": {
577- \\"a\\": true,
578- \\"b\\": 123
579- }
580- },
581- {
582- \\"id\\": \\"b\\",
583- \\"score\\": 0.75,
584- \\"values\\": [
585- 5,
586- 6,
587- 7,
588- 8
589- ],
590- \\"metadata\\": {
591- \\"c\\": false,
592- \\"b\\": \\"123\\"
593- }
594- }
595- ]
596- }"
597- ` ) ;
536+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
598537
599538 // No warning > Valid filter
600539 expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
@@ -605,43 +544,7 @@ describe("vectorize commands", () => {
605544 await runWrangler (
606545 "vectorize query test-index --vector 1 2 3 '4' --filter='{ 'p1': [1,2,3] }'"
607546 ) ;
608- expect ( std . out ) . toMatchInlineSnapshot ( `
609- "📋 Searching for relevant vectors...
610- {
611- \\"count\\": 2,
612- \\"matches\\": [
613- {
614- \\"id\\": \\"a\\",
615- \\"score\\": 0.5,
616- \\"values\\": [
617- 1,
618- 2,
619- 3,
620- 4
621- ],
622- \\"namespace\\": \\"abcd\\",
623- \\"metadata\\": {
624- \\"a\\": true,
625- \\"b\\": 123
626- }
627- },
628- {
629- \\"id\\": \\"b\\",
630- \\"score\\": 0.75,
631- \\"values\\": [
632- 5,
633- 6,
634- 7,
635- 8
636- ],
637- \\"metadata\\": {
638- \\"c\\": false,
639- \\"b\\": \\"123\\"
640- }
641- }
642- ]
643- }"
644- ` ) ;
547+ expect ( std . out ) . toMatchInlineSnapshot ( querySnapshot ) ;
645548
646549 expect ( std . warn ) . toMatchInlineSnapshot ( `
647550 "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m🚨 Invalid query filter. Please use the recommended format.[0m
@@ -660,6 +563,34 @@ describe("vectorize commands", () => {
660563 expect ( std . warn ) . toMatchInlineSnapshot ( `
661564 "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mCould not find any relevant vectors[0m
662565
566+ "
567+ ` ) ;
568+ } ) ;
569+
570+ it ( "should fail query when neither vector nor vector-id is provided" , async ( ) => {
571+ mockVectorizeV2RequestError ( ) ;
572+ await runWrangler (
573+ "vectorize query test-index --top-k=2 --return-values=true"
574+ ) ;
575+ expect ( std . out ) . toMatchInlineSnapshot ( `""` ) ;
576+
577+ expect ( std . err ) . toMatchInlineSnapshot ( `
578+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 Either vector or vector-id param must be provided, but not both.[0m
579+
580+ "
581+ ` ) ;
582+ } ) ;
583+
584+ it ( "should fail query when both vector and vector-id are provided" , async ( ) => {
585+ mockVectorizeV2RequestError ( ) ;
586+ await runWrangler (
587+ "vectorize query test-index --vector 1 2 3 '4' --vector-id some-vector-id"
588+ ) ;
589+ expect ( std . out ) . toMatchInlineSnapshot ( `""` ) ;
590+
591+ expect ( std . err ) . toMatchInlineSnapshot ( `
592+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 Either vector or vector-id param must be provided, but not both.[0m
593+
663594"
664595 ` ) ;
665596 } ) ;
@@ -857,6 +788,43 @@ describe("vectorize query filter", () => {
857788 } ) ;
858789} ) ;
859790
791+ const querySnapshot = `
792+ "📋 Searching for relevant vectors...
793+ {
794+ \\"count\\": 2,
795+ \\"matches\\": [
796+ {
797+ \\"id\\": \\"a\\",
798+ \\"score\\": 0.5,
799+ \\"values\\": [
800+ 1,
801+ 2,
802+ 3,
803+ 4
804+ ],
805+ \\"namespace\\": \\"abcd\\",
806+ \\"metadata\\": {
807+ \\"a\\": true,
808+ \\"b\\": 123
809+ }
810+ },
811+ {
812+ \\"id\\": \\"b\\",
813+ \\"score\\": 0.75,
814+ \\"values\\": [
815+ 5,
816+ 6,
817+ 7,
818+ 8
819+ ],
820+ \\"metadata\\": {
821+ \\"c\\": false,
822+ \\"b\\": \\"123\\"
823+ }
824+ }
825+ ]
826+ }"` ;
827+
860828/** Create a mock handler for the Vectorize API */
861829function mockVectorizeRequest ( ) {
862830 msw . use (
0 commit comments