Your question is Retrieve Top-K Documentation Snippets. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Intercom Fin can use vector embeddings to retrieve relevant Help Center documentation for a customer's query. Given one query embedding and a collection of documentation snippets with precomputed embeddings, return the IDs of the k most relevant snippets.
Use cosine similarity as the relevance score. Return IDs ordered by decreasing similarity. If multiple snippets have exactly the same score, order them by their original input position. You may assume every embedding is nonzero and all embeddings have the same dimension.
Implement retrieve_top_k(query_embedding, snippets, k).
query_embedding is a list of floats.snippets is a list of objects, each containing an id and an embedding list of floats.k is a positive integer no greater than the number of snippets.k snippet IDs.def retrieve_top_k(query_embedding, snippets, k):