Make Cosine Similarity Matrix
make_cosine_similarity_matrix.Rd
make_cosine_similarity_matrix
lets you calculate the cosine similarity of a given matrix.
Examples
conn <- get_ollama_connection()
document <- "Standing proudly on the Île de la Cité in the heart of Paris,
France's capital city, lies one of the world's most beloved and historic
landmarks: the magnificent Notre Dame Cathedral. This Gothic masterpiece
has been welcoming pilgrims and tourists alike for over 850 years, since its
construction began in 1163 under King Louis VII. With its towering spires,
stunning stained glass windows, and intricate stone carvings, this beautiful
church is a testament to medieval architecture and engineering skill.
Unfortunately, a devastating fire ravaged the cathedral on April 15, 2019,
but thanks to swift action from firefighters and restoration efforts
underway, Notre Dame continues to inspire awe in those who visit her."
writeLines(document, con = "doc1.txt")
context_df <- convert_batch_documents_to_embeddings(ollama_connection = conn,
document_path_list = list("doc1.txt"))
prompt <- "When was Notre Dame in Paris built?"
prompt_vector <- get_ollama_embeddings(ollama_connection = conn, input = prompt)
whole_list <- c(list(prompt_vector), context_df$embeddings)
mat <- do.call(rbind,whole_list)
cos_sim_mat <- make_cosine_similarity_matrix(mat)