简体   繁体   English

如何更改 Vespa 中最近邻搜索的排名顺序?

[英]How to change ranking order for nearest neighbor search in Vespa?

Let's say I have such schema:假设我有这样的模式:

schema embeddings {
  document embeddings {
    field id type int {}
    field text_embedding type tensor<double>(d0[960]) {
      indexing: attribute
      attribute {
        distance-metric: euclidean
      }
    }
  }

  rank-profile distance {
    num-threads-per-search:1
    inputs {
      query(query_embedding) tensor<double>(d0[960])
    }
    first-phase {
      expression: distance(field, text_embedding)
    }
  }
}

After performing a query with such a body在使用这样的主体执行查询后

body = {
    'yql': 'select * from embeddings where ([{\"targetHits\":10}] nearestNeighbor(text_embedding, query_embedding));',
    "hits":10,
    'ranking': {
        'profile': 'distance',
        'features': {
            'query(query_embedding)': [...]
        }
    },
}

I received a number of results sorted by the distance in descending order.我收到了一些按距离降序排列的结果。

How can I change the query or schema to receive results sorted by the distance in ascending order?如何更改查询或模式以接收按距离升序排序的结果?

I am aware of closeness operator but I need exactly what I described我知道closeness operator 但我需要的正是我所描述的

Use for example -distance(field, embedding) then - you can write any math expression here.例如使用-distance(field, embedding)然后 - 你可以在这里写任何数学表达式。

You can also have distance returned while ranking by something else by declaring it a summary-feature, for example:您还可以通过将其他内容声明为摘要功能来在按其他内容排名时返回距离,例如:

  rank-profile distance {
    num-threads-per-search:1
    inputs {
      query(query_embedding) tensor<double>(d0[960])
    }
    first-phase {
      expression: closeness(field, text_embedding)
    }
    summary-features {
      distance(field, text_embedding)
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM