Skip to content

Instantly share code, notes, and snippets.

@sachaarbonel
Created November 5, 2022 21:30
Show Gist options
  • Save sachaarbonel/2c0261f9e4687fc9a96e8ec4b9d37666 to your computer and use it in GitHub Desktop.
Save sachaarbonel/2c0261f9e4687fc9a96e8ec4b9d37666 to your computer and use it in GitHub Desktop.
fn main() -> anyhow::Result<()> {
+ let model = SentenceEmbeddingsBuilder::remote(SentenceEmbeddingsModelType::AllMiniLmL12V2).create_model()?;
let json = fs::read_to_string("data/books.json")?;
let library: Library = serde_json::from_str(&json)?;
+ let mut embeddedbooks = Vec::new();
for book in library.books.clone() {
- println!("Embedding book: {}", book.title);
+ let embeddings = model.encode(&[book.clone().summary])?;
+ let embedding = to_array(embeddings[0].as_slice());
+ embeddedbooks.push(book.to_embedded(embedding));
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment