@@ -431,7 +431,8 @@ void ParameterSpace::set_index_parameter (
431431 // and fall through to also enable it on sub-indexes
432432 }
433433 if (DC (IndexPreTransform)) {
434- index = ix->index ;
434+ set_index_parameter (ix->index , name, val);
435+ return ;
435436 }
436437 if (DC (IndexShards)) {
437438 // call on all sub-indexes
@@ -440,30 +441,28 @@ void ParameterSpace::set_index_parameter (
440441 }
441442 return ;
442443 }
443- if (name == " verbose" ) {
444- index->verbose = int (val);
445- // in case it was an IndexPreTransform
446- }
447444 if (DC (IndexRefineFlat)) {
448445 if (name == " k_factor_rf" ) {
449446 ix->k_factor = int (val);
450447 return ;
451448 }
452- index = ix->base_index ;
453- }
454- if (DC (IndexPreTransform)) {
455- index = ix->index ;
449+ // otherwise it is for the sub-index
450+ set_index_parameter (&ix->refine_index , name, val);
451+ return ;
456452 }
453+
457454 if (name == " verbose" ) {
458455 index->verbose = int (val);
459456 return ; // last verbose that we could find
460457 }
458+
461459 if (name == " nprobe" ) {
462460 if ( DC (IndexIVF)) {
463461 ix->nprobe = int (val);
464462 return ;
465463 }
466464 }
465+
467466 if (name == " ht" ) {
468467 if (DC (IndexPQ)) {
469468 if (val >= ix->pq .code_size * 8 ) {
@@ -685,7 +684,6 @@ Index *index_factory (int d, const char *description_in, MetricType metric)
685684 tok;
686685 tok = strtok_r (nullptr , " ," , &ptr)) {
687686 int d_out, opq_M, nbit, M, M2 ;
688- char option[100 ];
689687 std::string stok (tok);
690688
691689 // to avoid mem leaks with exceptions:
@@ -776,10 +774,9 @@ Index *index_factory (int d, const char *description_in, MetricType metric)
776774 del_coarse_quantizer.release ();
777775 index_ivf->own_fields = true ;
778776 index_1 = index_ivf;
779- } else if (!index && sscanf (tok, " PQ%d%10s" , &M, option) == 2 ) {
780- std::string soption = option;
781- // np to disable polysemous trainign
782- FAISS_THROW_IF_NOT (soption == " " || soption == " np" );
777+ } else if (!index && (sscanf (tok, " PQ%d" , &M) == 1 ||
778+ sscanf (tok, " PQ%dnp" , &M) == 1 )) {
779+ bool do_polysemous_training = stok.find (" np" ) == std::string::npos;
783780 if (coarse_quantizer) {
784781 IndexIVFPQ *index_ivf = new IndexIVFPQ (
785782 coarse_quantizer, d, ncentroids, M, 8 );
@@ -789,11 +786,11 @@ Index *index_factory (int d, const char *description_in, MetricType metric)
789786 index_ivf->cp .spherical = metric == METRIC_INNER_PRODUCT ;
790787 del_coarse_quantizer.release ();
791788 index_ivf->own_fields = true ;
792- index_ivf->do_polysemous_training = soption != " np " ;
789+ index_ivf->do_polysemous_training = do_polysemous_training ;
793790 index_1 = index_ivf;
794791 } else {
795792 IndexPQ *index_pq = new IndexPQ (d, M, 8 , metric);
796- index_pq->do_polysemous_training = soption != " np " ;
793+ index_pq->do_polysemous_training = do_polysemous_training ;
797794 index_1 = index_pq;
798795 }
799796
0 commit comments