valentinegb / openai

An unofficial Rust library for the OpenAI API.
https://crates.io/crates/openai/
MIT License
61 stars 18 forks source link

Add embeddings distance function #19

Closed valentinegb closed 1 year ago

valentinegb commented 1 year ago

This pull request adds the distance method to the Embedding structure and distances method to the Embeddings structure. The distance function uses cosine similarity, as suggested by the OpenAI API documentation. Example usage of each:

println!(embedding_a.distance(embedding_b)); // prints a float
println!(embeddings.distances()); // prints a vector of floats