Hi Typesense team, I’m trying to implement a user-...
# community-help
a
Hi Typesense team, I’m trying to implement a user-based personalized search, similar to Algolia’s personalization, but in Typesense. The personalization is primarily tag-based. For example: • If a user has a preference for the cuisine tag “Italian” and a dietary preference for “chicken”, • When the user searches for “pasta”, the results should prioritize dishes like chicken alfredo. This works reasonably well, but there are inconsistencies: • For instance, when searching for “cake”, the system sometimes surfaces unrelated items like pancakes with chicken. The issue seems related to query intent classification. To address this, I’m experimenting with: • Using Qdrant (vector DB) to classify the intent of the query. • Dynamically parsing a sorting string in Typesense that adjusts the weightage of certain tags. I know you recommend using the StarSpace model for personalization, but I’m not aiming for a heavy ML approach. Could you recommend a stable strategy for achieving consistent, tag-based personalization in Typesense without going full ML? Please give a response
k
Pure tag based approach is going to be tricky and you will likely always run into edge cases like this. One idea that you can try is to see if you can embed the tag and record data into vectors (using a small embedding model) and then to re-rank the search results using the vector similarity between the user's preference tag vector and a given document's data vector. See this section on sorting hybrid matches on vector distance: https://typesense.org/docs/29.0/api/vector-search.html#sorting-hybrid-matches-on-vector-distance
a
userPreferences := []string{"Chicken","Indian"} test, _ := intents.VectorSearch(userPreferences) vectorBytes, _ := json.Marshal(test) vectorQuery := fmt.Sprintf("embedding:(%s, k:100)", string(vectorBytes)) result := &api.MultiSearchSearchesParameter{ Searches: []api.MultiSearchCollectionParameters{ { Collection: pointer.Any("SKU_collection"), Q: pointer.Any(query), QueryBy: pointer.Any("sku_name,category_name,tag_names"), Prefix: pointer.Any("false"), VectorQuery: pointer.String(vectorQuery),// <=== Be sure to replace
embedding
with the name of the field that stores your embeddings. ExcludeFields: pointer.Any("embedding"), // <=== Don't return the raw floating point numbers in the vector field in the search API response, to save on network bandwidth. }, }, } return result is it something like this
k
I don't follow you.
a
sorry this a query i implemented in golang
is the structure u recommend to follow
k
You have to sort on vector distance. Check the doc link I shared earlier. It will look like this:
Copy code
"sort_by": "popularity_score:desc,_vector_distance:asc"