@@ -106,11 +106,11 @@ pub struct IndexOptions {
106
106
impl IndexOptions {
107
107
fn validate_self_quantization (
108
108
& self ,
109
- quantization : & QuantizationOptions ,
109
+ quantization : & Option < QuantizationOptions > ,
110
110
) -> Result < ( ) , ValidationError > {
111
111
match quantization {
112
- QuantizationOptions :: Trivial ( _ ) => Ok ( ( ) ) ,
113
- QuantizationOptions :: Scalar ( _) | QuantizationOptions :: Product ( _) => {
112
+ None => Ok ( ( ) ) ,
113
+ Some ( QuantizationOptions :: Scalar ( _) | QuantizationOptions :: Product ( _) ) => {
114
114
if !matches ! ( self . vector. v, VectorKind :: Vecf32 | VectorKind :: Vecf16 ) {
115
115
return Err ( ValidationError :: new (
116
116
"scalar quantization or product quantization is not support for vectors that are not dense vectors" ,
@@ -356,13 +356,13 @@ impl Default for InvertedIndexingOptions {
356
356
pub struct FlatIndexingOptions {
357
357
#[ serde( default ) ]
358
358
#[ validate( nested) ]
359
- pub quantization : QuantizationOptions ,
359
+ pub quantization : Option < QuantizationOptions > ,
360
360
}
361
361
362
362
impl Default for FlatIndexingOptions {
363
363
fn default ( ) -> Self {
364
364
Self {
365
- quantization : QuantizationOptions :: default ( ) ,
365
+ quantization : Default :: default ( ) ,
366
366
}
367
367
}
368
368
}
@@ -379,7 +379,7 @@ pub struct IvfIndexingOptions {
379
379
pub residual_quantization : bool ,
380
380
#[ serde( default ) ]
381
381
#[ validate( nested) ]
382
- pub quantization : QuantizationOptions ,
382
+ pub quantization : Option < QuantizationOptions > ,
383
383
}
384
384
385
385
impl IvfIndexingOptions {
@@ -418,7 +418,7 @@ pub struct HnswIndexingOptions {
418
418
pub ef_construction : u32 ,
419
419
#[ serde( default ) ]
420
420
#[ validate( nested) ]
421
- pub quantization : QuantizationOptions ,
421
+ pub quantization : Option < QuantizationOptions > ,
422
422
}
423
423
424
424
impl HnswIndexingOptions {
@@ -472,37 +472,19 @@ impl Default for RabitqIndexingOptions {
472
472
#[ serde( deny_unknown_fields) ]
473
473
#[ serde( rename_all = "snake_case" ) ]
474
474
pub enum QuantizationOptions {
475
- Trivial ( TrivialQuantizationOptions ) ,
476
475
Scalar ( ScalarQuantizationOptions ) ,
477
476
Product ( ProductQuantizationOptions ) ,
478
477
}
479
478
480
479
impl Validate for QuantizationOptions {
481
480
fn validate ( & self ) -> Result < ( ) , validator:: ValidationErrors > {
482
481
match self {
483
- Self :: Trivial ( x) => x. validate ( ) ,
484
482
Self :: Scalar ( x) => x. validate ( ) ,
485
483
Self :: Product ( x) => x. validate ( ) ,
486
484
}
487
485
}
488
486
}
489
487
490
- impl Default for QuantizationOptions {
491
- fn default ( ) -> Self {
492
- Self :: Trivial ( Default :: default ( ) )
493
- }
494
- }
495
-
496
- #[ derive( Debug , Clone , Serialize , Deserialize , Validate ) ]
497
- #[ serde( deny_unknown_fields) ]
498
- pub struct TrivialQuantizationOptions { }
499
-
500
- impl Default for TrivialQuantizationOptions {
501
- fn default ( ) -> Self {
502
- Self { }
503
- }
504
- }
505
-
506
488
#[ derive( Debug , Clone , Serialize , Deserialize , Validate ) ]
507
489
#[ serde( deny_unknown_fields) ]
508
490
#[ validate( schema( function = "Self::validate_self" ) ) ]
@@ -569,26 +551,16 @@ impl Default for ProductQuantizationOptions {
569
551
#[ derive( Debug , Clone , Serialize , Deserialize , Validate , Alter ) ]
570
552
#[ serde( deny_unknown_fields) ]
571
553
pub struct SearchOptions {
572
- #[ serde( default = "SearchOptions::default_flat_sq_rerank_size" ) ]
573
- #[ validate( range( min = 0 , max = 65535 ) ) ]
574
- pub flat_sq_rerank_size : u32 ,
575
- #[ serde( default = "SearchOptions::default_flat_sq_fast_scan" ) ]
576
- pub flat_sq_fast_scan : bool ,
577
- #[ serde( default = "SearchOptions::default_flat_pq_rerank_size" ) ]
578
- #[ validate( range( min = 0 , max = 65535 ) ) ]
579
- pub flat_pq_rerank_size : u32 ,
580
- #[ serde( default = "SearchOptions::default_flat_pq_fast_scan" ) ]
581
- pub flat_pq_fast_scan : bool ,
582
- #[ serde( default = "SearchOptions::default_ivf_sq_rerank_size" ) ]
554
+ #[ serde( default = "SearchOptions::default_sq_rerank_size" ) ]
583
555
#[ validate( range( min = 0 , max = 65535 ) ) ]
584
- pub ivf_sq_rerank_size : u32 ,
585
- #[ serde( default = "SearchOptions::default_ivf_sq_fast_scan " ) ]
586
- pub ivf_sq_fast_scan : bool ,
587
- #[ serde( default = "SearchOptions::default_ivf_pq_rerank_size " ) ]
556
+ pub sq_rerank_size : u32 ,
557
+ #[ serde( default = "SearchOptions::default_sq_fast_scan " ) ]
558
+ pub sq_fast_scan : bool ,
559
+ #[ serde( default = "SearchOptions::default_pq_rerank_size " ) ]
588
560
#[ validate( range( min = 0 , max = 65535 ) ) ]
589
- pub ivf_pq_rerank_size : u32 ,
590
- #[ serde( default = "SearchOptions::default_ivf_pq_fast_scan " ) ]
591
- pub ivf_pq_fast_scan : bool ,
561
+ pub pq_rerank_size : u32 ,
562
+ #[ serde( default = "SearchOptions::default_pq_fast_scan " ) ]
563
+ pub pq_fast_scan : bool ,
592
564
#[ serde( default = "SearchOptions::default_ivf_nprobe" ) ]
593
565
#[ validate( range( min = 1 , max = 65535 ) ) ]
594
566
pub ivf_nprobe : u32 ,
@@ -609,28 +581,16 @@ pub struct SearchOptions {
609
581
}
610
582
611
583
impl SearchOptions {
612
- pub const fn default_flat_sq_rerank_size ( ) -> u32 {
613
- 0
614
- }
615
- pub const fn default_flat_sq_fast_scan ( ) -> bool {
616
- false
617
- }
618
- pub const fn default_flat_pq_rerank_size ( ) -> u32 {
619
- 0
620
- }
621
- pub const fn default_flat_pq_fast_scan ( ) -> bool {
622
- false
623
- }
624
- pub const fn default_ivf_sq_rerank_size ( ) -> u32 {
584
+ pub const fn default_sq_rerank_size ( ) -> u32 {
625
585
0
626
586
}
627
- pub const fn default_ivf_sq_fast_scan ( ) -> bool {
587
+ pub const fn default_sq_fast_scan ( ) -> bool {
628
588
false
629
589
}
630
- pub const fn default_ivf_pq_rerank_size ( ) -> u32 {
590
+ pub const fn default_pq_rerank_size ( ) -> u32 {
631
591
0
632
592
}
633
- pub const fn default_ivf_pq_fast_scan ( ) -> bool {
593
+ pub const fn default_pq_fast_scan ( ) -> bool {
634
594
false
635
595
}
636
596
pub const fn default_ivf_nprobe ( ) -> u32 {
@@ -656,14 +616,10 @@ impl SearchOptions {
656
616
impl Default for SearchOptions {
657
617
fn default ( ) -> Self {
658
618
Self {
659
- flat_sq_rerank_size : Self :: default_flat_sq_rerank_size ( ) ,
660
- flat_sq_fast_scan : Self :: default_flat_sq_fast_scan ( ) ,
661
- flat_pq_rerank_size : Self :: default_flat_pq_rerank_size ( ) ,
662
- flat_pq_fast_scan : Self :: default_flat_pq_fast_scan ( ) ,
663
- ivf_sq_rerank_size : Self :: default_ivf_sq_rerank_size ( ) ,
664
- ivf_sq_fast_scan : Self :: default_ivf_sq_fast_scan ( ) ,
665
- ivf_pq_rerank_size : Self :: default_ivf_pq_rerank_size ( ) ,
666
- ivf_pq_fast_scan : Self :: default_ivf_pq_fast_scan ( ) ,
619
+ sq_rerank_size : Self :: default_sq_rerank_size ( ) ,
620
+ sq_fast_scan : Self :: default_sq_fast_scan ( ) ,
621
+ pq_rerank_size : Self :: default_pq_rerank_size ( ) ,
622
+ pq_fast_scan : Self :: default_pq_fast_scan ( ) ,
667
623
ivf_nprobe : Self :: default_ivf_nprobe ( ) ,
668
624
hnsw_ef_search : Self :: default_hnsw_ef_search ( ) ,
669
625
rabitq_nprobe : Self :: default_rabitq_nprobe ( ) ,
0 commit comments