Search Products using useProductSearch in Supabase

Hi,

In my shop-mini app I am collecting some user profile data (like favourite brands, etc) that I want to share with OpenAI’s model as a prompt and ask it to suggest me products using the useProductSearch.

Right now I am using the useProductSearch directly inside my shop-mini to get the top 10 results, but is it possible to use Supabase to connect to OpenAI and send the user’s data as a prompt to suggest more relevant products?

If you want to connect to OpenAI API you need to use a custom backend (like Supabase) to proxy the requests from the mini.

You can send the array of products to your backend and add them to a prompt for OpenAI. Then send the response back to the mini.

Hey @Quique-Shopify actually the idea is to just provide a basic prompt to OpenAI like “My wife loves pink sneakers, and her favourite brand is Nike, I’m looking to buy something in the range of $50-$100“, and then have the AI model search through Shopify’s catalog and give the relevant results back to the shop-mini where we can display it. How can I achieve this?

I tried using the useProductSearch hook directly inside my shop-mini (no backend required) but that alone does not give me most relevant results, plus I think it would not work with "natural language” queries.

@Quique-Shopify I researched about Shopify MCP but it only lets us access products for a selected store. I wonder how for example “pair with” is able to search the whole catalogue in Shopify as MCP is per store? Do you have any idea? We are now thinking off using AI to get specific keywords out of the input fields and then using the native useProductSearch hook in mini search the keywords. Would that be a robust way you think?

1 Like

the approach would be to ask OpenAI for keywords for the search query, and then use the minis search hook.

In this way, OpenAI will translate from natural language to search query keywords for your search. There’s no other way at the moment

Hi @Quique-Shopify I have had similar experience, do you suggest we only use the useProductSearch hook without any filters and then use our backend AI to organize/filter the results based on the search query? because when i do use the filters i do not get the correct results. Also, i am getting some product currency in pounds and rest in dollars.

1 Like

Hi @Quique-Shopify can you suggest to us how we should handle the category for useProductSearch param?
Should we just put all prompts to query, or can we still add categories to filters with this format [“gid://shopify/TaxonomyCategory/el”]. I am concern about the accuracy of the result.

No, I think the more filters you add, the more accurate the response will be. Also, take into account that search results may vary per user, and especially per user’s country.

What I suggested was to use OpenAI (or any other LLM) to convert from a natural language query to what our hook expects, that it’s a set of keywords.

You can add the keywords you’re interested in your search query and also add category filters to narrow the search.