Can I display ordered results in Workshop from a Semantic Search function?

I’m having a workflow where I perform a semantic search across my objects. My user inputs a query, this query is converted to an embedding, which then serves as basis for the “closest matches” of Object instances.

In workshop, I display the list of “N best matches” but … the list is not ordered.

Can I display ordered result ? Can I show how much each result is matching (the distance value) ?
I would like my users to focus on the best matches first.

See https://www.palantir.com/docs/foundry/functions/using-palantir-provided-models-to-create-a-semantic-search-workflow/
See https://www.palantir.com/docs/foundry/functions/using-custom-models-to-create-a-semantic-search-workflow/

Hey!,

You can display ordered results in workshop by calculating a “similarity” score using functions similar to the one created for the semantic search workflow and then using that to sort the results

Here’s an example

@Function()
    public async queryRelevance(
        yourObjects: ObjectSet<YOUR OBJECT TYPE>, 
        query: string
        ): Promise<FunctionsMap<YOUR OBJECT TYPE, Double>> {
            const map = new FunctionsMap<YOUR OBJECT TYPE, Double>();
            // Return empty map if no query
            if (query.length < 1 || yourObjects === null) {
                return map;
            }
            // Embed the current query
            const embedding = await TextEmbeddingAda_002.createEmbeddings({inputs: [query]}).then(q => q.embeddings[0]);;
            
            yourObjects.all().forEach(o => {
                const relevanceScore = MyFunctions.dotProduct(embedding, o.objectEmbeddings! as number[])
                map.set(o, relevanceScore)
            }

            );
        return map;
    }```