查询 vespa.ai 中的张量

Query tensor in vespa.ai

模仿:https://blog.vespa.ai/billion-scale-knn/

命令行: curl -s -d '{"yql":"select * from user where {\"targetHits\":10}nearestNeighbor(approximate, q_binary_code);","ranking.features.query(q_binary_code)":[1,2,3,4,5,6,7,8,9,10],"hits":10}' -H "Content-Type: application/json" -X POST http://localhost:8080/search/ | jq .

错误信息:

{
  "root": {
    "id": "toplevel",
    "relevance": 1,
    "fields": {
      "totalCount": 0
    },
    "errors": [
      {
        "code": 4,
        "summary": "Invalid query parameter",
        "source": "content",
        "message": "Expected a tensor value of 'query(q_binary_code)' but has [1,2,3,4,5,6,7,8,9,10]"
      }
    ]
  }
}

问题:如何通过q_binary_code

使用最近的 Vespa 版本,您可以在模式中定义查询张量。必须定义

schema code {
  document code {
    field id type int {..} 
    field binary_code type tensor<int8>(b[16]) {..}
 }
 rank-profile coarse-ranking {
    inputs {
      query(q_binary_code) tensor<int8>(b[16])
    }
    num-threads-per-search:12
    first-phase { expression { closeness(field,binary_code) } } 
 }

您还必须在查询请求中定义排名配置文件:

curl -s -d '{"yql":"select * from user where {\"targetHits\":10}nearestNeighbor(binary_code, q_binary_code);","ranking.features.query(q_binary_code)":[1,2,3,4,5,6,7,8,9,10],"hits":10, "ranking": "coarse-ranking"}' -H "Content-Type: application/json" -X POST http://localhost:8080/search/ | jq .