API version: 0.3.0

---

# Vector search

This example finds articles by the meaning of a text instead of its words. The articles have the property
`descriptionEmbedding`, a [vector](/reference/schemas/types/vector.md) whose
[embedding](/reference/schemas/types/vector.md#embeddings) is calculated by the embedding provider `test` from the title
and the description of each article:

```json
{
  "type": "vector",
  "embedding": {
    "provider": "test",
    "source": "document.title != nil && document.description != nil ? document.title + \": \" + document.description : nil"
  },
  "index": "vector"
}
```

The search has three steps:

1. The [`text-embedding`](/reference/search/text-embedding.md) step turns the text of the search into a vector, with the
   same provider which calculated the vectors of the articles. Vectors of different models can not be compared.
2. The Elasticsearch step runs a
   [kNN query](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-knn-query) on
   `descriptionEmbedding`. The vector of the first step is inserted with the expression
   `{{ stepResults[0].vector }}`. `num_candidates` is the number of nearest articles which Elasticsearch considers.
3. The [element hydration](/reference/search/element-hydration.md) step returns the articles.

```json
{
  "debug": true,
  "steps": [
    {
      "type": "text-embedding",
      "query": "a hot drink made from roasted beans",
      "parameters": {
        "provider": "test"
      }
    },
    {
      "type": "elasticsearch-query-dsl-mixin",
      "query": {
        "knn": {
          "field": "descriptionEmbedding",
          "query_vector": "{{ stepResults[0].vector }}",
          "num_candidates": 10
        }
      },
      "parameters": {
        "nodeTypes": [
          "KnowledgeArticle"
        ]
      }
    },
    {
      "type": "element-hydration"
    }
  ]
}
```

##### Response Body

```json
{
  "type": "_SearchResultResponse",
  "results": [
    {
      "type": "KnowledgeArticle",
      "id": "02IiNr0GPRh9FOgqcIYpqkrpwVgmyBJi0Utt7",
      "data": {
        "scenario": "endpoint.search.embedding",
        "description": "Strong coffee, brewed by forcing hot water through finely ground coffee beans.",
        "title": "Espresso",
        "createdAt": "2026-12-05T12:15:19+00:00",
        "createdBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh",
        "updatedAt": "2026-12-05T12:15:19+00:00",
        "updatedBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
      },
      "metadata": {
        "score": 0.82979465,
        "matchedQueries": {
          "descriptionEmbedding": 0.82979465
        }
      }
    },
    {
      "type": "KnowledgeArticle",
      "id": "02IiNr0GPRh8yeu4k5NbyGhla4mDL5NbcbpsV",
      "data": {
        "scenario": "endpoint.search.embedding",
        "description": "Bread made from a fermented starter of flour and water, with a tangy taste.",
        "title": "Sourdough bread",
        "createdAt": "2026-12-05T12:15:19+00:00",
        "createdBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh",
        "updatedAt": "2026-12-05T12:15:19+00:00",
        "updatedBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
      },
      "metadata": {
        "score": 0.66170645,
        "matchedQueries": {
          "descriptionEmbedding": 0.66170645
        }
      }
    },
    {
      "type": "KnowledgeArticle",
      "id": "02IiNr0GPRh8qI11qqd5gmiDJDW1RDIJ6shU3",
      "data": {
        "scenario": "endpoint.search.embedding",
        "description": "A tropical plant with large, split leaves, which grows well in bright indirect light.",
        "title": "Monstera deliciosa",
        "createdAt": "2026-12-05T12:15:19+00:00",
        "createdBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh",
        "updatedAt": "2026-12-05T12:15:19+00:00",
        "updatedBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
      },
      "metadata": {
        "score": 0.60950875,
        "matchedQueries": {
          "descriptionEmbedding": 0.60950875
        }
      }
    },
    {
      "type": "KnowledgeArticle",
      "id": "02IiNr0GPRh971naZquHFfpuOO89XxD01he2z",
      "data": {
        "scenario": "endpoint.search.embedding",
        "description": "A bicycle with suspension and wide tires for riding on rough trails.",
        "title": "Mountain bike",
        "createdAt": "2026-12-05T12:15:19+00:00",
        "createdBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh",
        "updatedAt": "2026-12-05T12:15:19+00:00",
        "updatedBy": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
      },
      "metadata": {
        "score": 0.53638935,
        "matchedQueries": {
          "descriptionEmbedding": 0.53638935
        }
      }
    }
  ],
  "debug": [
    {
      "input": {
        "type": "text-embedding",
        "query": "a hot drink made from roasted beans",
        "parameters": {
          "provider": "test",
          "stepResults": []
        }
      },
      "step-handler": "text-embedding (App\\EventSystem\\SearchStep\\EventListener\\TextEmbeddingSearchStepEventListener)",
      "start": 1796473118.173704,
      "end": 1796473118.195801,
      "duration": 0.022097110748291016
    },
    {
      "input": {
        "type": "elasticsearch-query-dsl-mixin",
        "query": {
          "knn": {
            "field": "descriptionEmbedding",
            "query_vector": "{{ stepResults[0].vector }}",
            "num_candidates": 10
          }
        },
        "parameters": {
          "nodeTypes": [
            "KnowledgeArticle"
          ],
          "stepResults": [
            {
              "vector": [
                -0.054718122,
                -0.02551928,
                -0.13014504,
                "..."
              ],
              "provider": "test",
              "dimensions": 384
            }
          ]
        }
      },
      "step-handler": "elasticsearch-query-dsl-mixin (App\\EventSystem\\SearchStep\\EventListener\\ElasticsearchQueryDslMixinSe...",
      "start": 1796473118.196239,
      "indices": "node_knowledgearticle",
      "combinedQuery": {
        "_source": [
          "_id"
        ],
        "from": 0,
        "size": 25,
        "query": {
          "bool": {
            "must": [
              {
                "knn": {
                  "field": "descriptionEmbedding",
                  "query_vector": [
                    -0.054718122,
                    -0.02551928,
                    -0.13014504,
                    "..."
                  ],
                  "num_candidates": 10,
                  "filter": [
                    {
                      "bool": {
                        "should": [
                          {
                            "terms": {
                              "_groupsWithSearchAccess.keyword": []
                            }
                          },
                          {
                            "term": {
                              "_usersWithSearchAccess.keyword": {
                                "value": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
                              }
                            }
                          }
                        ],
                        "minimum_should_match": 1
                      }
                    }
                  ],
                  "_name": "descriptionEmbedding"
                }
              }
            ],
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "terms": {
                        "_groupsWithSearchAccess.keyword": []
                      }
                    },
                    {
                      "term": {
                        "_usersWithSearchAccess.keyword": {
                          "value": "02IiNr0GPRh8IoTyJhhpoI3h2bpn2GRg75sBh"
                        }
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
      },
      "end": 1796473118.315804,
      "duration": 0.119565
    },
    {
      "input": {
        "type": "element-hydration",
        "query": null,
        "parameters": {
          "stepResults": [
            {
              "vector": [
                -0.054718122,
                -0.02551928,
                -0.13014504,
                "..."
              ],
              "provider": "test",
              "dimensions": 384
            },
            {
              "elements": [
                {
                  "id": "02IiNr0GPRh9FOgqcIYpqkrpwVgmyBJi0Utt7",
                  "type": "KnowledgeArticle",
                  "metadata": {
                    "score": 0.82979465,
                    "matchedQueries": {
                      "descriptionEmbedding": 0.82979465
                    }
                  }
                },
                {
                  "id": "02IiNr0GPRh8yeu4k5NbyGhla4mDL5NbcbpsV",
                  "type": "KnowledgeArticle",
                  "metadata": {
                    "score": 0.66170645,
                    "matchedQueries": {
                      "descriptionEmbedding": 0.66170645
                    }
                  }
                },
                {
                  "id": "02IiNr0GPRh8qI11qqd5gmiDJDW1RDIJ6shU3",
                  "type": "KnowledgeArticle",
                  "metadata": {
                    "score": 0.60950875,
                    "matchedQueries": {
                      "descriptionEmbedding": 0.60950875
                    }
                  }
                },
                {
                  "id": "02IiNr0GPRh971naZquHFfpuOO89XxD01he2z",
                  "type": "KnowledgeArticle",
                  "metadata": {
                    "score": 0.53638935,
                    "matchedQueries": {
                      "descriptionEmbedding": 0.53638935
                    }
                  }
                }
              ],
              "totalHits": 4,
              "maxScore": 0.82979465
            }
          ]
        }
      },
      "step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
      "start": 1796473118.316017,
      "accessibleElementIds": [
        "02IiNr0GPRh9FOgqcIYpqkrpwVgmyBJi0Utt7",
        "02IiNr0GPRh8yeu4k5NbyGhla4mDL5NbcbpsV",
        "02IiNr0GPRh8qI11qqd5gmiDJDW1RDIJ6shU3",
        "02IiNr0GPRh971naZquHFfpuOO89XxD01he2z"
      ],
      "end": 1796473118.383879,
      "duration": 0.067862
    }
  ]
}
```

##### Response Headers

```http
Access-Control-Allow-Headers: Authorization, Content-Type, Prefer
Access-Control-Allow-Methods: OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Preference-Applied
Allow: OPTIONS, POST
Cache-Control: no-cache, private
Content-Type: application/json; charset=utf-8
Date: Sat, 05 Dec 2026 02:00:55 GMT
Transfer-Encoding: chunked
Vary: Prefer, Accept-Encoding
X-Powered-By: Ember Nexus API
```

The articles are ordered by their similarity to the text: none of them contains the words "hot drink" or "roasted
beans", but the espresso is closest to them. The similarity of each article is returned in
`metadata.matchedQueries.descriptionEmbedding`: the kNN query is named after its field, as it has no `_name` of its
own. `metadata.score` is the score of the whole query, which can combine several queries.

Only articles which the user has access to are found. The API adds the access filter to the kNN query itself, so that
Elasticsearch searches the nearest accessible articles, instead of filtering the nearest articles afterwards. An
article of another user is not part of the result, even if it is the closest one.

**Note**: The `text-embedding` step needs a token with the capability `embedding.create`, as every search sends a
request to the embedding provider.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Exact keyword matching](/reference/search/elasticsearch-query-dsl-mixin/exact-keyword-matching.md)

Next: [Geospatial search](/reference/search/elasticsearch-query-dsl-mixin/geospatial-search.md)
