Skip to content

knn query

A knn search query can be used for searching over text fields defined as searchable with semantic search with a pre-computed embedding.

Unlike semantic query, the knn query does NOT run embedding inference, and expects the query embedding provided in the request:

{
  "query": {
    "knn": {
      "field": "title",
      "query_vector": [1,2,3,4,5],
      "k": 10
    }
  }
}

Fields: * field: a text field name with semantic search enabled in the index mapping. * query_embedding: a text query embedding. * k: an optional parameter of how many neighbor documents to fetch. By default, equals to the request.size field.

For a case when you would like Nixiesearch to embed the query, see the semantic query.