@@ -31,7 +31,6 @@ use pyo3::{
3131use pyo3:: { prelude:: * , IntoPyObjectExt } ;
3232use snafu:: location;
3333
34- use lance:: dataset:: builder:: DatasetBuilder ;
3534use lance:: dataset:: refs:: { Ref , TagContents } ;
3635use lance:: dataset:: scanner:: {
3736 DatasetRecordBatchStream , ExecutionStatsCallback , MaterializationStyle ,
@@ -54,6 +53,7 @@ use lance::dataset::{
5453use lance:: dataset:: { ColumnAlteration , ProjectionRequest } ;
5554use lance:: index:: vector:: utils:: get_vector_type;
5655use lance:: index:: { vector:: VectorIndexParams , DatasetIndexInternalExt } ;
56+ use lance:: { dataset:: builder:: DatasetBuilder , index:: vector:: IndexFileVersion } ;
5757use lance_arrow:: as_fixed_size_list_array;
5858use lance_index:: scalar:: inverted:: query:: {
5959 BooleanQuery , BoostQuery , FtsQuery , MatchQuery , MultiMatchQuery , Operator , PhraseQuery ,
@@ -2027,6 +2027,7 @@ fn prepare_vector_index_params(
20272027 let mut hnsw_params = HnswBuildParams :: default ( ) ;
20282028 let mut pq_params = PQBuildParams :: default ( ) ;
20292029 let mut sq_params = SQBuildParams :: default ( ) ;
2030+ let mut index_file_version = IndexFileVersion :: V3 ;
20302031
20312032 if let Some ( kwargs) = kwargs {
20322033 // Parse metric type
@@ -2143,9 +2144,15 @@ fn prepare_vector_index_params(
21432144 let codebook = as_fixed_size_list_array ( batch. column ( 0 ) ) ;
21442145 pq_params. codebook = Some ( codebook. values ( ) . clone ( ) )
21452146 } ;
2147+
2148+ if let Some ( version) = kwargs. get_item ( "index_file_version" ) ? {
2149+ let version: String = version. extract ( ) ?;
2150+ index_file_version = IndexFileVersion :: try_from ( & version)
2151+ . map_err ( |e| PyValueError :: new_err ( format ! ( "Invalid index_file_version: {e}" ) ) ) ?;
2152+ }
21462153 }
21472154
2148- match index_type {
2155+ let mut params = match index_type {
21492156 "IVF_FLAT" => Ok ( Box :: new ( VectorIndexParams :: ivf_flat (
21502157 ivf_params. num_partitions ,
21512158 m_type,
@@ -2178,7 +2185,9 @@ fn prepare_vector_index_params(
21782185 _ => Err ( PyValueError :: new_err ( format ! (
21792186 "Index type '{index_type}' is not supported."
21802187 ) ) ) ,
2181- }
2188+ } ?;
2189+ params. version ( index_file_version) ;
2190+ Ok ( params)
21822191}
21832192
21842193#[ pyclass( name = "_FragmentWriteProgress" , module = "_lib" ) ]
0 commit comments