INNER CODE UNIT · Rust

from_vec

lanterndata/lantern · lantern_cli/src/embeddings/mod.rs:29

    fn from_vec(pk: String, value: Vec<f32>) -> EmbeddingRecord {
        let mut buf = BytesMut::with_capacity(4);

        if value.len() > 0 {
            let chunk_size = 1024 * 1024; // 1 MB
            buf = BytesMut::with_capacity(chunk_size);
            buf.extend_from_slice("{".as_bytes());
            let row_str: String = value.iter().map(|&x| x.to_string() + ",").collect();
            buf.extend_from_slice(row_str[0..row_str.len() - 1].as_bytes());
            drop(row_str);
            buf.extend_from_slice("}".as_bytes());
        } else {
            buf.extend_from_slice("NULL".as_bytes());
        }

        EmbeddingRecord { pk, record: buf }
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…