dotnet-smartcomponents / smartcomponents

Experimental, end-to-end AI features for .NET apps
693 stars 61 forks source link

Smart ComboBox always posts 5 as the value of similarityThreshold #64

Open Mimisss opened 4 months ago

Mimisss commented 4 months ago

Smart ComboBox always posts 5 as the value of similarityThreshold. As a result, the MVC/Razor Pages example does not work out of the box.

Sample https://github.com/dotnet-smartcomponents/smartcomponents/tree/main/samples/ExampleMvcRazorPagesApp

Page https://localhost:7227/smartcombobox

Expected behavior:

If you run the application, you'll see it now does suggest semantic matches. For example, if you type "cat" it will suggest "Pet Care", whereas if you type "plane" it will suggest "Travel".

Actual behavior: Nothing happens. No error(s).

Mimisss commented 3 months ago

Must be foul play with the similarity-threshold parameter of the component. The value posted is always 5. For example, both:

<smart-combobox id="accounting-category" url="~/api/suggestions/accounting-categories" />

and

<smart-combobox id="accounting-category" url="~/api/suggestions/accounting-categories" similarity-threshold="0.5f" />

always post 5 as the value of similarity threshold instead of 0.5.

As a result, FindClosest returns no matches.

I've tested it by implementing the API endpoint manually:

public IActionResult ExpenseCategories([FromForm] SuggestionsParams request)
{
    var expenseCategories = _embedder.EmbedRange(new[]
        { "Groceries", "Utilities", "Rent", "Mortgage", "Car Payment", "Car Insurance", "Health Insurance", "Life Insurance", "Home Insurance", "Gas", "Public Transportation", "Dining Out", "Entertainment", "Travel", "Clothing", "Electronics", "Home Improvement", "Gifts", "Charity", "Education", "Childcare", "Pet Care", "Other" });

    var similarityQuery = new SmartComponents.Inference.SimilarityQuery()
    {
        SearchText = request.inputValue,
        MaxResults = request.maxResults,
        MinSimilarity = request.similarityThreshold     //  <--- always 5
    };

    var result = _embedder.FindClosest(similarityQuery, expenseCategories);

    return Ok(result);
}