Function get_ranked_function_names

Source
pub async fn get_ranked_function_names(
    prompt_embedding: Vec<f32>,
    embed_path: &Path,
) -> Result<Vec<String>, Box<dyn Error + Sync + Send>>
Expand description

Asynchronously retrieves and ranks function names based on their similarity to a given prompt embedding.

This function searches a specified file for function embeddings, compares them to the provided prompt embedding, and returns a ranked list of function names based on their similarity to the prompt.

§Parameters

  • prompt_embedding: A Vec<f32> representing the embedding of the prompt. This embedding is used to compare against the function embeddings stored in the file located at embed_path.
  • embed_path: A reference to a Path where the function embeddings are stored. This file should contain a serialized Vec<FuncEmbedding> where FuncEmbedding is a structure representing the function name and its embedding.

§Returns

  • Ok(Vec<String>): A vector of function names ranked by their similarity to the prompt_embedding. The most similar function’s name is first.
  • Err(Box<dyn std::error::Error + Send + Sync>): An error if the file at embed_path cannot be opened, read, or if the embeddings cannot be deserialized and compared successfully.

§Errors

  • File opening failure due to embed_path not existing or being inaccessible.
  • File reading failure if the file cannot be read to the end.
  • Archive processing failure if deserialization of the stored embeddings encounters errors.

§Examples

async fn run() -> Result<(), Box<dyn std::error::Error>> {
    let prompt_embedding = vec![0.1, 0.2, 0.3];
    let embed_path = Path::new("function_embeddings.bin");
    let ranked_function_names = get_ranked_function_names(prompt_embedding, embed_path).await?;
    println!("Ranked functions: {:?}", ranked_function_names);
    Ok(())
}