I'm working on a project where I use FAISS to retrieve n neighbouring vectors based on a query vector. The data in question is textual and is being embedded by using a machine learning model to create a vector before it goes into FAISS.

These neighbors each have a category assigned to them, and also have a similarity score to the query, like the following:

Query: Berlin is the capital of Germany
Neighbours output:

5 Neighbour ids: [57, 163, 177, 124, 91]

Text | Category | Similarity

Berlin is a great city to live in | Capital cities | 0.897843
Capital letters are often used to indicate nouns in German | Grammar | 0.803834
Over 3 million people live in Berlin | Capital cities | 0.79434
Germany is a country in Central Europe | Countries | 0.763232
Germany has many big cities | Countries | 0.7304545

Now, the thing I want to achieve is getting a single category for the query based on the categories of the neighbours, a kind of vector based recommender/suggestion system. What I tried already is just doing simple and weighted (based on similarity) majority voting.

Using simple majority voting, in the above example I would just get "Capital cities" or "Country" category as they both occur 2 out of 5 times. Using weighted voting I would arrive at "Capital cities" as they have higher similarity overall.

Both the approaches seem to work, however I am looking for a slightly more sophisticated approach to combine different signals. I read about the concept of data fusion in machine learning, but I don't quite know yet how to best apply it here to arrive at one category based on the neighbours.

Any ideas are appreciated!

  • $\begingroup$ Why don't you just fine-tune your machine learning model to predict the category? $\endgroup$
    – Valentas
    Jul 1, 2022 at 8:42
  • $\begingroup$ Good question, the reason for this is because I have very limited actual data available to me to train a supervised model on this. So, by leveraging open embedding models I wanted to see how good this unsupervised approach would be, $\endgroup$
    – mabergerx
    Jul 1, 2022 at 8:46
  • $\begingroup$ I don't think it is reasonable to expect something 'more sophisticated' without having the data and using only pretrained blackbox models. $\endgroup$
    – Valentas
    Jul 1, 2022 at 14:05

1 Answer 1


You can use similarity score as your distance metric for the nearest neighbors algorithm.

You do not need to vote, the top most similar neighbor is the label you are looking for.

Often times similarity is thresholded to avoid returning low-quality search results. If none of the nearest neighbors are above a certain similarity, then the system would do something else.

  • $\begingroup$ Your suggestion makes sense, but this is what OP said he has already tried. In fact he has tried not only the 1-nn as you suggest but also a k-nn method. $\endgroup$
    – Valentas
    Jul 1, 2022 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.