facebookresearch / faiss

A library for efficient similarity search and clustering of dense vectors.

Home Page:https://faiss.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Searching most distant vector

EnricoBeltramo opened this issue · comments

Is it possible to search more distant elements instead the nearest? I looked in the documentation but I didn't find any option for a similar search.

same as #2366

There is nothing to do that currently, except with INNER_PRODUCT or cosine distance, where one can just query the opposite vector.

Just realized you can find the farthest away vector by restating it as a max inner product search problem with one additional dimension.
demo_farthest_L2.ipynb

Thank you! It's an amazing solution. It's not really clear how equivalence comes from, is it possible to see all calculation steps (or the mathematical reference) in order to understand it better ?
I tried to move values in different ranges and I found that with i.e. :
ds = SyntheticDataset(200, 0, 2000, 100)
k = 200
The ordering not match completely. Is it an exact formula or an approximation?

in my calculation I expected that:
(x-q)^2 = x^2 + q^2 - 2x*q
so I should add 2 dimension to have a correct transformation:
x' = [-2x,x^2,1] q'=[q,1,q^2]

or it's wrong?

I understood the calculation: q^2 is a constant term added to any distance calculated so doesn't matter if I'm interested only to order.
About that sometimes the order doesn't match with ground truth I found that when is different is always because two vectors with a very close distance are inverted, I suppose it's only a numerical issue due flow32 resolution.