Skip to content

Instantly share code, notes, and snippets.

extern crate blas_src;
use hnsw::{Hnsw, Params, Searcher};
use ndarray_npy::{ViewNpyExt, WriteNpyExt};
use memmap2::{Mmap, MmapMut};
use rand_pcg::Pcg64;
use space::Metric;
use std::{fs::OpenOptions, io::BufWriter, time::Instant};
[package]
name = "mem"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rayon = "1.5"
indicatif = {version = "0.16", features = ["rayon"]}
[package]
name = "mem"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rayon = "1.5"
indicatif = {version = "0.16", features = ["rayon"]}
# https://github.com/matsui528/faiss_tips
import faiss
import numpy as np
D = 256
N = 10000
X = np.random.random((N, D)).astype(np.float32)
# Setup
index = faiss.index_factory(D, "IVF25,Flat", faiss.METRIC_INNER_PRODUCT)
use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
time::Instant,
};
use faiss::{error::Error, index_factory, read_index, write_index, Index, MetricType};
use itertools_num::linspace;
use structopt::StructOpt;
use std::{path::PathBuf, time::Instant};
use faiss::{error::Error, index_factory, read_index, write_index, Index, MetricType};
use itertools_num::linspace;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "dann", about = "Demo ANN")]
struct DannOpt {
/// FAISS Index factory string
use std::time::Instant;
use faiss::{error::Error, index_factory, Index, MetricType};
use itertools_num::linspace;
fn main() -> Result<(), Error> {
let d: u32 = 64;
// let my_data: Vec<f32> = (1u16..(d * 10) as u16).map(f32::from).collect();
// above way of generating f32 ranges is limited in d size wrt default traits
// https://users.rust-lang.org/t/collect-f32-range-into-a-vector/15936/3
use faiss::{error::Error, index_factory, Index, MetricType};
fn main() -> Result<(), Error> {
let my_data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
let mut index = index_factory(8, "Flat", MetricType::L2)?;
index.add(&my_data)?;
let result = index.search(&my_data, 5)?;
for (i, (l, d)) in result
.labels
.iter()
.zip(result.distances.iter())
#![deny(warnings)]
use std::{collections::HashMap, convert::Infallible, sync::Arc};
use tokio::sync::RwLock;
use warp::{Filter, Rejection};
fn with_store(
store: Arc<RwLock<HashMap<String, u64>>>,
) -> impl Filter<Extract = (Arc<RwLock<HashMap<String, u64>>>,), Error = Infallible> + Clone {
warp::any().map(move || store.clone())
}
#![deny(warnings)]
use std::{collections::HashMap, convert::Infallible, str::FromStr, sync::Arc};
use tokio::sync::RwLock;
use warp::{Filter, Rejection};
fn with_store(
store: Arc<RwLock<HashMap<String, u64>>>,
) -> impl Filter<Extract = (Arc<RwLock<HashMap<String, u64>>>,), Error = Infallible> + Clone {
warp::any().map(move || store.clone())
}