Knn for recommendations

Let us say I am building an ecommerce app and there are 2 users:
user A : always searches for electronics (laptop, headphones, etc)
user B: searches for snacks, beverages

Is it possible to show a page with banner that has electronics for user A and snacks for user B as soon as they log in? and also show similar recommendations when they search for it?

Can this be accomplished using knn?

I don’t know if knn is the best approach here, because you’ll need to somehow map products to vectors. If you have that, then knn is probably the way to go.

Here’s a simpler solution: if you have documents stored somewhere about what people are searching for or buying (e.g. categories showing up in their search results or cart), then you can run queries on these documents and see what people prefer. Either a terms aggregation on userA’s data to get the most frequent categories they look for or maybe a significant terms aggregation on userA’s data compared to all the others, because maybe your site is very popular with snacks and everyone buys them for some reason.

Once you know what the user prefers, you can show them a banner with popular products of those categories (that they didn’t already buy?). Another common approach is to look at carts and see what other people buy along with the products userA bought (another terms aggregation). This way maybe you can suggest travel-size toothpaste along with their suitcase, instead of suggesting another suitcase :slight_smile: