﻿---
title: Dense vector query
description: Performs exact, brute-force scoring of a query vector against every document that has a value for a dense_vector field. Unlike the approximate knn query,...
url: https://www.elastic.co/elastic/docs-builder/docs/3650/reference/query-languages/query-dsl/query-dsl-dense-vector-query
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
---

# Dense vector query
Performs exact, brute-force scoring of a query vector against every document that has a value for a
[`dense_vector`](https://www.elastic.co/elastic/docs-builder/docs/3650/reference/elasticsearch/mapping-reference/dense-vector) field. Unlike the approximate
[`knn` query](https://www.elastic.co/elastic/docs-builder/docs/3650/reference/query-languages/query-dsl/query-dsl-knn-query), it does not use an index
structure or a `k`/`num_candidates` cutoff: every matching document is scored. This is useful when you need
exact scores, want to combine exact vector scoring with other queries, or want to score a `dense_vector`
field that is not indexed for approximate search (`index: false`).
By default, scoring uses the original, full-precision vectors, so a [quantized](/elastic/docs-builder/docs/3650/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization)
index still produces full-precision scores. See [`quantized`](#dense-vector-query-params) to score against
the quantized representation instead.

## Example request

```json

{
  "mappings": {
    "properties": {
      "image-vector": {
        "type": "dense_vector",
        "dims": 3,
        "index": true,
        "similarity": "l2_norm"
      }
    }
  }
}
```

1. Index your data.
   ```json

   { "index": { "_id": "1" } }
   { "image-vector": [1, 5, -20] }
   { "index": { "_id": "2" } }
   { "image-vector": [42, 8, -15] }
   { "index": { "_id": "3" } }
   { "image-vector": [15, 11, 23] }
   ```
   
2. Run the `dense_vector` query. Every document with the field is scored.
   ```json

   {
     "query": {
       "dense_vector": {
         "field": "image-vector",
         "query_vector": [-5, 9, -12]
       }
     }
   }
   ```
   


## Top-level parameters for `dense_vector`

<definitions>
  <definition term="field">
    (Required, string) The name of the `dense_vector` field to search against.
  </definition>
  <definition term="query_vector">
    (Optional, array of floats or string) The query vector. Must have the same number of dimensions as the
    target field. You must provide either `query_vector` or `query_vector_builder`, but not both. Accepts a
    float array, or a hex-encoded or base64-encoded string.
  </definition>
  <definition term="query_vector_builder">
    (Optional, object) A configuration object used to convert a query into a `query_vector`, for example by
    running a text embedding model. You must provide either `query_vector` or `query_vector_builder`, but not
    both. See [`query_vector_builder`](https://www.elastic.co/elastic/docs-builder/docs/3650/reference/query-languages/query-dsl/query-dsl-knn-query) for details.
  </definition>
  <definition term="similarity_function">
    (Optional, string) The similarity metric used for scoring, overriding the field's mapped similarity for
    this query. One of `l2_norm`, `dot_product`, `cosine`, or `max_inner_product`. Defaults to the field's
    configured similarity, or to `cosine` for a non-indexed (`index: false`) field, which has no configured
    similarity. For `bit` fields, only `l2_norm` is supported. Cannot be combined with `quantized: true`.
  </definition>
  <definition term="quantized [dense-vector-query-quantized]">
    (Optional, Boolean) Defaults to `false`.
    When `false` (the default), scoring iterates the preserved full-precision vectors, producing raw scores
    regardless of the field's `index_options`.
    When `true`, scoring uses the codec's scorer, which on a [quantized](/elastic/docs-builder/docs/3650/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization)
    index scores against the lossy quantized representation (faster, lower fidelity). It cannot be combined
    with `similarity_function`.
    <note>
      `quantized: true` only makes sense for [quantized](/elastic/docs-builder/docs/3650/reference/elasticsearch/mapping-reference/dense-vector#dense-vector-quantization)
      fields. For non-quantized `dense_vector` fields, the setting is ignored and the original vectors are used
      for scoring.
    </note>
  </definition>
  <definition term="boost">
    (Optional, float) Floating point number used to multiply the scores of the query. Defaults to `1.0`.
  </definition>
  <definition term="_name">
    (Optional, string) Name to identify the query for [named queries](https://www.elastic.co/elastic/docs-builder/docs/3650/reference/query-languages/query-dsl/query-dsl-bool-query).
  </definition>
</definitions>


## Scoring non-indexed fields

The `dense_vector` query can score a field mapped with `index: false`, whose vectors are stored as doc
values rather than in an approximate-search index. A non-indexed field has no configured `similarity`, so
scoring uses `cosine` unless you specify a different metric with
[`similarity_function`](#dense-vector-query-params):
```json

{
  "query": {
    "dense_vector": {
      "field": "image-vector",
      "query_vector": [-5, 9, -12],
      "similarity_function": "cosine"
    }
  }
}
```