Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created February 7, 2022 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/81a5f2f23fdc8f0e199f7bb11c354b92 to your computer and use it in GitHub Desktop.
Save mooreniemi/81a5f2f23fdc8f0e199f7bb11c354b92 to your computer and use it in GitHub Desktop.
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())
.enumerate()
{
println!("#{}: {} (D={})", i + 1, *l, *d);
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment