How do I use a vector search to find a matching combination of vectors?

330 Views Asked by At

**I want to match a user's query to a combination of items from the database. If there's no exact match, I want to return the closest possible combination. Each combination must have 1 item and 0 or more options. **

Example: The user query is "large pepperoni pizza with olives".

There's a row in the database with a vector for the item name "pizza". There are also rows for options "pepperoni", "olives", "sausage", "size: large", etc.

The returned combination should be "Item: pizza. Options: pepperoni, olives, size: large"

What I've tried

After embedding the user query, I do a vector search in the database. I get a list of items and options, sorted by cosine distance. It currently returns 3 items and 3 options.

All good so far. But now that I have the results, how do I create a combination that matches the user's query? I could try re-embedding different combinations and comparing them against the original query, but I assume that will get exponentially expensive and slow.

Notes

  • I'm using SBERT all-MiniLM-L6-v2 and pgvector
  • Open to using full-text search, but would like to preserve ability to provide recommendations if there's no exact match
0

There are 0 best solutions below