Repository: qdrant/qdrant
File: lib/collection/src/config.rs (Rust)

Code before:
                sparse_vector_params.modifier = Some(modifier);
            }

            if let Some(index) = index {
                if let Some(existing_index) = &mut sparse_vector_params.index {
                    existing_index.update_from_other(index);
                } else {
                    sparse_vector_params.index.replace(index);
                }
            }
        }
        Ok(())
    }

    /// Convert into unoptimized named vector data configs
    ///
    /// It is the job of the segment optimizer to change this configuration with optimized settings
    /// based on threshold configurations.
    pub fn to_base_vector_data(
        &self,
        collection_quantization: &Option<QuantizationConfig>,
    ) -> CollectionResult<HashMap<VectorNameBuf, VectorDataConfig>> {
        let quantization_fn = |quantization_config: &Option<QuantizationConfig>| {
            common::flags::feature_flags()
                .appendable_quantization
                .then(|| {
                    if let Some(quantization_config) = quantization_config {
                        quantization_config
                            .is_appendable()
                            .then(|| quantization_config.clone())
                    } else if let Some(collection_quantization) = collection_quantization {
                        // Only if there is no `quantization_config` we may start using `collection_quantization` (to avoid mixing quantizations between segments)
                        collection_quantization
                            .is_appendable()
                            .then(|| collection_quantization.clone())
                    } else {
                        None
                    }
                })
                .flatten()
        };

        Ok(self
            .vectors
            .params_iter()
            .map(|(name, params)| {
                (
                    name.into(),
                    VectorDataConfig {
                        size: params.size.get() as usize,
                        distance: params.distance,

Review comment (refactor):
Nitpick: I vote to move this `common::flags::feature_flags()` and `then()` to the place where we call `quantization_fn` below. That'll make it a bit cleaner, imo.

Code after:
        for (vector_name, update_params) in update_vectors.0.iter() {
            let sparse_vector_params = self.get_sparse_vector_params_mut(vector_name)?;
            let SparseVectorParams { index, modifier } = update_params.clone();

            if let Some(modifier) = modifier {
                sparse_vector_params.modifier = Some(modifier);
            }

            if let Some(index) = index {
                if let Some(existing_index) = &mut sparse_vector_params.index {
                    existing_index.update_from_other(index);
                } else {
                    sparse_vector_params.index.replace(index);
                }
            }
        }
        Ok(())
    }

    /// Convert into unoptimized named vector data configs
    ///
    /// It is the job of the segment optimizer to change this configuration with optimized settings
    /// based on threshold configurations.
    pub fn to_base_vector_data(
        &self,
        collection_quantization: Option<&QuantizationConfig>,
    ) -> CollectionResult<HashMap<VectorNameBuf, VectorDataConfig>> {
        let quantization_fn = |quantization_config: Option<&QuantizationConfig>| {
            quantization_config
                // Only if there is no `quantization_config` we may start using `collection_quantization` (to avoid mixing quantizations between segments)
                .or(collection_quantization)
                .filter(|c| c.supports_appendable())
                .cloned()
        };

        Ok(self
            .vectors
            .params_iter()
            .map(|(name, params)| {
                (
                    name.into(),
                    VectorDataConfig {
                        size: params.size.get() as usize,
                        distance: params.distance,
                        // Plain (disabled) index
                        index: Indexes::Plain {},
                        // Quantizaton config in appendable segment if runtime feature flag is set
                        quantization_config: common::flags::feature_flags()
                            .appendable_quantization
                            .then(|| quantization_fn(params.quantization_config.as_ref()))
                            .flatten(),