You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: dual_encoder.rs
    path of file: ./repos/stract/crates/core/src/models
    
    the code of the file until where you have to start completion: // Stract is an open source web search engine.
// Copyright (C) 2024 Stract ApS
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use anyhow::anyhow;
use candle_core::{Device, Tensor};
use candle_nn::VarBuilder;
use std::path::Path;

use crate::{
    models::bert::{self, BertModel},
    Result,
};
use tokenizers::{PaddingParams, TruncationParams};

pub struct DualEncoder {
    model: BertModel,
    tokenizer: tokenizers::Tokenizer,
    device: Device,
    dtype: candle_core::DType,
    config: bert::Config,
}

impl DualEncoder {
    pub fn open<P: AsRef<Path>>(folder: P) -> Result<Self> {
   
    
    pub fn open<P: AsRef<Path>>(folder: P) -> Result<Self> {
        let device = Device::Cpu;
        let dtype = candle_core::DType::F16;

        let truncation = TruncationParams {
            max_length: 256,
            ..Default::default()
        };

        let padding = PaddingParams {
            ..Default::default()
        };

        let mut tokenizer =
            tokenizers::Tokenizer::from_file(folder.as_ref().join("tokenizer.json")).unwrap();

        tokenizer.with_truncation(Some(truncation)).unwrap();
        tokenizer.with_padding(Some(padding));

        let vb = unsafe {
            VarBuilder::from_mmaped_safetensors(
                &[folder.as_ref().join("model.safetensors")],
                dtype,
                &device,
            )?
        };
        let config = std::fs::read_to_string(folder.as_ref().join("config.json"))?;
        let mut config: bert::Config = serde_json::from_str(&config)?;
        config.hidden_act = bert::HiddenAct::GeluApproximate;

        // all tensors can be loaded with (useful for debugging):
        // candle_core::safetensors::load(folder.as_ref().join("model.safetensors"), &device)

        let mut model = BertModel::load(vb, &config)?;
        model.set_pooler(None); // model should use mean pooling

        Ok(Self {
            model,
            tokenizer,
            device,
            dtype,
            config,
        })
    }