Calculate Vector Distance

Users can calculate vector distance between one target vector and data stored in specified database.

curl -u shiva:shiva -XGET 'localhost:8902/hippo/v1/_distance?pretty' -H 'Content-Type: application/json' -d'{
  "vectors_left" : {
    "database_name" : "default",
    "table_name" : "book",
    "field" : "book_intro",
    "primary_keys" : [
      {
        "field_name": "book_id",
        "field": [1,2,3,4,5]
      }
    ]
  },
  "vectors_right" : {
    "float_vectors" : [[1,2], [3,4]]
  },
  "params" : {
    "metric_type": "cosine"
  }
}';

Result:

{
  "vectors_distance" : [
    {
      "distances" : [
        0.94868326,
        0.9899495
      ]
    },
    {
      "distances" : [
        0.79999995,
        0.8944272
      ]
    },
    {
      "distances" : [
        0.70710677,
        0.8221922
      ]
    },
    {
      "distances" : [
        0.6507914,
        0.77611405
      ]
    },
    {
      "distances" : [
        0.6139406,
        0.74524134
      ]
    }
  ]
}

Parameter description:

ParametersDescriptionRequired
vectors_leftVector dataset in the databaseYes
database_name (vectors _left)Database nameNo, defaults to "default" database
table_name (vectors _left)Table nameYes
field (vectors _left)Vector field nameYes
primary_keys (vectors _left)Primary key listYes
vectors_rightVector dataset to be calculatedYes
float_vectors (vectors _right)Floating point vector datasetYes
paramsParameterYes
metric_type (params)Metric typeYes, L2 / IP / Cosine

Table 51 Calculate Vector Distance (Restful API)