Giter Site home page Giter Site logo

Comments (7)

yanliang567 avatar yanliang567 commented on August 14, 2024

/assign @liliu-z
please take a look
/unassign

from milvus.

xiaofan-luan avatar xiaofan-luan commented on August 14, 2024

don't quite understand it.
What is the current problem?
The distance result seems to be correct

from milvus.

yanliang567 avatar yanliang567 commented on August 14, 2024

I think searching an exact vector for himself should return 0 as distance, but it returns -1 if cosine.

from milvus.

xiaofan-luan avatar xiaofan-luan commented on August 14, 2024

I think searching an exact vector for himself should return 0 as distance, but it returns -1 if cosine.

exact vector should be 1. 0 means not related at all

from milvus.

xiaofan-luan avatar xiaofan-luan commented on August 14, 2024

it's opposite direction, then the distance is -1.

from milvus.

jpowie01 avatar jpowie01 commented on August 14, 2024

Yes, that's exactly the problem. The values I get back from the search query are incorrect.

If you look closer to the example I provided above, I've added three vectors to the database ([1, 1, 1, 1], [1, 1, -1, -1], [-1, -1, -1, -1]) and then searched for a vector [-1, -1, -1, -1]. As a result, I got distance values as following:

  • [1, 1, 1, 1] -> 1.0
  • [1, 1, -1, -1] -> 0.0
  • [-1, -1, -1, -1] -> -1.0 (exact search)

Those are incorrect values, neither for cosine similarity nor cosine distance. From the behaviour I'm seeing, those values are representing cosine similarity multiplied by -1. But... why?

Here is a snippet of code using scipy & scikit-learn computing those metrics on the same vectors:

>>> from scipy.spatial import distance
>>> distance.cosine([-1, -1, -1, -1], [1, 1, 1, 1])
2.0
>>> distance.cosine([-1, -1, -1, -1], [1, 1, -1, -1])
1.0
>>> distance.cosine([-1, -1, -1, -1], [-1, -1, -1, -1])
0.0

>>> from sklearn.metrics.pairwise import cosine_similarity
>>> cosine_similarity([[-1, -1, -1, -1]], [[1, 1, 1, 1]])
array([[-1.]])
>>> cosine_similarity([[-1, -1, -1, -1]], [[1, 1, -1, -1]])
array([[0.]])
>>> cosine_similarity([[-1, -1, -1, -1]], [[-1, -1, -1, -1]])
array([[1.]])

from milvus.

xiaofan-luan avatar xiaofan-luan commented on August 14, 2024

/assign @liliu-z

from milvus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.