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:
Parameters | Description | Required |
---|---|---|
vectors_left | Vector dataset in the database | Yes |
database_name (vectors _left) | Database name | No, defaults to "default" database |
table_name (vectors _left) | Table name | Yes |
field (vectors _left) | Vector field name | Yes |
primary_keys (vectors _left) | Primary key list | Yes |
vectors_right | Vector dataset to be calculated | Yes |
float_vectors (vectors _right) | Floating point vector dataset | Yes |
params | Parameter | Yes |
metric_type (params) | Metric type | Yes, L2 / IP / Cosine |
Table 51 Calculate Vector Distance (Restful API)