---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features: "mapper.vectors.int4_quantization"
    reason: "kNN float to half-byte quantization is required"
- do:
    indices.create:
      index: "hnsw_byte_quantized"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            name:
              type: "keyword"
            vector:
              type: "dense_vector"
              dims: 4
              index: true
              similarity: "l2_norm"
              index_options:
                type: "int4_hnsw"
            another_vector:
              type: "dense_vector"
              dims: 4
              index: true
              similarity: "l2_norm"
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized"
      id: "1"
      body:
        name: "cow.jpg"
        vector:
        - 230.0
        - 300.33
        - -34.8988
        - 15.555
        another_vector:
        - 130.0
        - 115.0
        - -1.02
        - 15.555
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized"
      id: "2"
      body:
        name: "moose.jpg"
        vector:
        - -0.5
        - 100.0
        - -13
        - 14.8
        another_vector:
        - -0.5
        - 50.0
        - -1
        - 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized"
      id: "3"
      body:
        name: "rabbit.jpg"
        vector:
        - 0.5
        - 111.3
        - -13.0
        - 14.8
        another_vector:
        - -0.5
        - 11.0
        - 0
        - 12
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.forcemerge:
      index: "hnsw_byte_quantized"
      max_num_segments: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.refresh: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
kNN search only:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.fields.name.0: "rabbit.jpg"
---
kNN multi-field search only:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
        - field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
        - field: "another_vector"
          query_vector:
          - -0.5
          - 11.0
          - 0
          - 12
          k: 2
          num_candidates: 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "moose.jpg"
---
kNN search plus query:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
        query:
          term:
            name:
              value: "cow.jpg"
              boost: 1.5
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.fields.name.0: "cow.jpg"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.1.fields.name.0: "moose.jpg"
- match:
    hits.hits.2._id: "3"
- match:
    hits.hits.2.fields.name.0: "rabbit.jpg"
---
kNN multi-field search with query:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
        - field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
        - field: "another_vector"
          query_vector:
          - -0.5
          - 11.0
          - 0
          - 12
          k: 2
          num_candidates: 3
          boost: 2.0
        query:
          term:
            name:
              value: "cow.jpg"
              boost: 2.0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.fields.name.0: "cow.jpg"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.fields.name.0: "moose.jpg"
---
kNN search with filter:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
          filter:
            term:
              name: "rabbit.jpg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total.value: 1
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.fields.name.0: "rabbit.jpg"
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 2
          num_candidates: 3
          filter:
          - term:
              name: "rabbit.jpg"
          - term:
              _id: 2
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total.value: 0
---
KNN Vector similarity search only:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 17
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
---
Vector similarity with filter only:
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 17
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          filter:
            term:
              name: "moose.jpg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.fields.name.0: "moose.jpg"
- do:
    search:
      index: "hnsw_byte_quantized"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          similarity: 110
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          filter:
            term:
              name: "cow.jpg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 0
---
Knn search with mip:
- do:
    indices.create:
      index: "mip"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            name:
              type: "keyword"
            vector:
              type: "dense_vector"
              dims: 6
              index: true
              similarity: "max_inner_product"
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "mip"
      id: "1"
      body:
        name: "cow.jpg"
        vector:
        - 1
        - 2
        - 3
        - 4
        - 5
        - 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "mip"
      id: "2"
      body:
        name: "moose.jpg"
        vector:
        - 1
        - 1
        - 1
        - 1
        - 1
        - 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "mip"
      id: "3"
      body:
        name: "rabbit.jpg"
        vector:
        - 1
        - 2
        - 2
        - 2
        - 2
        - 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.forcemerge:
      index: "mip"
      max_num_segments: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.refresh: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    search:
      index: "mip"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          query_vector:
          - 1
          - 2
          - 3
          - 4
          - 5
          - 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.2._id: "2"
- do:
    search:
      index: "mip"
      body:
        fields:
        - "name"
        knn:
          num_candidates: 3
          k: 3
          field: "vector"
          query_vector:
          - 1
          - 2
          - 3
          - 4
          - 5
          - 0
          filter:
            term:
              name: "moose.jpg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "2"
---
Cosine similarity with indexed vector:
- skip:
    features: "headers"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "cosineSimilarity(params.query_vector, 'vector')"
              params:
                query_vector:
                - 0.5
                - 111.3
                - -13.0
                - 14.8
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- match:
    hits.hits.0._id: "3"
- gte:
    hits.hits.0._score: 0.999
- lte:
    hits.hits.0._score: 1.001
- match:
    hits.hits.1._id: "2"
- gte:
    hits.hits.1._score: 0.998
- lte:
    hits.hits.1._score: 1.0
- match:
    hits.hits.2._id: "1"
- gte:
    hits.hits.2._score: 0.78
- lte:
    hits.hits.2._score: 0.8
---
Test bad quantization parameters:
- do:
    catch: "bad_request"
    indices.create:
      index: "bad_hnsw_quantized"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
              dims: 6
              element_type: "byte"
              index: true
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "bad_request"
    indices.create:
      index: "bad_hnsw_quantized"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
              dims: 6
              index: false
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Test create, merge, and search cosine:
- do:
    indices.create:
      index: "hnsw_byte_quantized_merge_cosine"
      body:
        settings:
          index:
            number_of_shards: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.put_mapping:
      index: "hnsw_byte_quantized_merge_cosine"
      body:
        properties:
          embedding:
            type: "dense_vector"
            element_type: "float"
            similarity: "cosine"
            index_options:
              type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_cosine"
      id: "1"
      body:
        embedding:
        - 0.5
        - 0.5
        - 0.5
        - 0.5
        - 0.5
        - 1.0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_cosine"
      id: "2"
      body:
        embedding:
        - 0.0
        - 0.0
        - 0.0
        - 1.0
        - 1.0
        - 0.5
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_cosine"
      id: "3"
      body:
        embedding:
        - 0.0
        - 0.0
        - 0.0
        - 0.0
        - 0.0
        - 10.5
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.forcemerge:
      index: "hnsw_byte_quantized_merge_cosine"
      max_num_segments: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.refresh: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    search:
      index: "hnsw_byte_quantized_merge_cosine"
      body:
        size: 3
        query:
          knn:
            field: "embedding"
            query_vector:
            - 1.0
            - 1.0
            - 1.0
            - 1.0
            - 1.0
            - 1.0
            num_candidates: 10
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.2._id: "3"
---
Test create, merge, and search dot_product:
- do:
    indices.create:
      index: "hnsw_byte_quantized_merge_dot_product"
      body:
        settings:
          index:
            number_of_shards: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.put_mapping:
      index: "hnsw_byte_quantized_merge_dot_product"
      body:
        properties:
          embedding:
            type: "dense_vector"
            element_type: "float"
            similarity: "dot_product"
            index_options:
              type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_dot_product"
      id: "1"
      body:
        embedding:
        - 0.6
        - 0.8
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_dot_product"
      id: "2"
      body:
        embedding:
        - 0.8
        - 0.6
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.flush: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "hnsw_byte_quantized_merge_dot_product"
      id: "3"
      body:
        embedding:
        - -0.6
        - -0.8
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.forcemerge:
      index: "hnsw_byte_quantized_merge_dot_product"
      max_num_segments: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.refresh: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    search:
      index: "hnsw_byte_quantized_merge_dot_product"
      body:
        size: 3
        query:
          knn:
            field: "embedding"
            query_vector:
            - 0.6
            - 0.8
            num_candidates: 10
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.1._id: "2"
- match:
    hits.hits.2._id: "3"
---
Vector rescoring has the same scoring as exact search for kNN section:
- requires:
    reason: "Quantized vector rescoring is required"
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "GET"
      path: "/_search"
      capabilities:
      - "knn_quantized_vector_rescore_oversample"
- skip:
    features: "headers"
    awaits_fix: "scores have changed slightly with native implementations"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      index: "hnsw_byte_quantized"
      rest_total_hits_as_int: true
      body:
        fields:
        - "name"
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 3
          num_candidates: 3
          rescore_vector:
            oversample: 1.5
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- set:
    hits.hits.0._score: "rescore_score0"
- set:
    hits.hits.1._score: "rescore_score1"
- set:
    hits.hits.2._score: "rescore_score2"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "1.0 / (1.0 + Math.pow(l2norm(params.query_vector, 'vector'),\
                \ 2.0))"
              params:
                query_vector:
                - -0.5
                - 90.0
                - -10
                - 14.8
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- match:
    hits.hits.0._score: "$rescore_score0"
- match:
    hits.hits.1._score: "$rescore_score1"
- match:
    hits.hits.2._score: "$rescore_score2"
---
Test odd dimensions fail indexing:
- do:
    catch: "bad_request"
    indices.create:
      index: "bad_hnsw_quantized"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
              dims: 5
              index: true
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.create:
      index: "dynamic_dim_hnsw_quantized"
      body:
        mappings:
          properties:
            vector:
              type: "dense_vector"
              index: true
              similarity: "l2_norm"
              index_options:
                type: "int4_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    catch: "bad_request"
    index:
      index: "dynamic_dim_hnsw_quantized"
      body:
        vector:
        - 1.0
        - 2.0
        - 3.0
        - 4.0
        - 5.0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "dynamic_dim_hnsw_quantized"
      body:
        vector:
        - 1.0
        - 2.0
        - 3.0
        - 4.0
        - 5.0
        - 6.0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Test index configured rescore vector:
- requires:
    cluster_features:
    - "mapper.dense_vector.rescore_vector"
    reason: "Needs rescore_vector feature"
- skip:
    features: "headers"
- do:
    indices.create:
      index: "int4_rescore_hnsw"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            vector:
              type: "dense_vector"
              dims: 4
              similarity: "max_inner_product"
              index_options:
                type: "int4_hnsw"
                rescore_vector:
                  oversample: 1.5
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      index: "int4_rescore_hnsw"
      refresh: true
      body: "{ \"index\": {\"_id\": \"1\"}}\n{ \"vector\":  [230.0, 300.33, -34.8988,\
        \ 15.555] }\n{ \"index\": {\"_id\": \"2\"}}\n{ \"vector\":  [-0.5, 100.0,\
        \ -13, 14.8] }\n{ \"index\": {\"_id\": \"3\"}}\n{ \"vector\":  [0.5, 111.3,\
        \ -13.0, 14.8] }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_hnsw"
      body:
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 3
          num_candidates: 3
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- set:
    hits.hits.0._score: "rescore_score0"
- set:
    hits.hits.1._score: "rescore_score1"
- set:
    hits.hits.2._score: "rescore_score2"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_hnsw"
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "double similarity = dotProduct(params.query_vector, 'vector');\
                \ return similarity < 0 ? 1 / (1 + -1 * similarity) : similarity +\
                \ 1"
              params:
                query_vector:
                - -0.5
                - 90.0
                - -10
                - 14.8
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- match:
    hits.hits.0._score: "$rescore_score0"
- match:
    hits.hits.1._score: "$rescore_score1"
- match:
    hits.hits.2._score: "$rescore_score2"
---
Test index configured rescore vector updateable and settable to 0:
- requires:
    cluster_features:
    - "mapper.dense_vector.rescore_zero_vector"
    reason: "Needs rescore_zero_vector feature"
- do:
    indices.create:
      index: "int4_rescore_0_hnsw"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            vector:
              type: "dense_vector"
              index_options:
                type: "int4_hnsw"
                rescore_vector:
                  oversample: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.create:
      index: "int4_rescore_update_hnsw"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            vector:
              type: "dense_vector"
              index_options:
                type: "int4_hnsw"
                rescore_vector:
                  oversample: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.put_mapping:
      index: "int4_rescore_update_hnsw"
      body:
        properties:
          vector:
            type: "dense_vector"
            index_options:
              type: "int4_hnsw"
              rescore_vector:
                oversample: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.get_mapping:
      index: "int4_rescore_update_hnsw"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    ".int4_rescore_update_hnsw.mappings.properties.vector.index_options.rescore_vector.oversample": 0
---
Test index configured rescore vector score consistency:
- requires:
    cluster_features:
    - "mapper.dense_vector.rescore_zero_vector"
    reason: "Needs rescore_zero_vector feature"
- skip:
    features: "headers"
- do:
    indices.create:
      index: "int4_rescore_zero_hnsw"
      body:
        settings:
          index:
            number_of_shards: 1
        mappings:
          properties:
            vector:
              type: "dense_vector"
              similarity: "max_inner_product"
              dims: 4
              index_options:
                type: "int4_hnsw"
                rescore_vector:
                  oversample: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      index: "int4_rescore_zero_hnsw"
      refresh: true
      body: "{ \"index\": {\"_id\": \"1\"}}\n{ \"vector\":  [230.0, 300.33, -34.8988,\
        \ 15.555] }\n{ \"index\": {\"_id\": \"2\"}}\n{ \"vector\":  [-0.5, 100.0,\
        \ -13, 14.8] }\n{ \"index\": {\"_id\": \"3\"}}\n{ \"vector\":  [0.5, 111.3,\
        \ -13.0, 14.8] }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_zero_hnsw"
      body:
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 3
          num_candidates: 3
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- set:
    hits.hits.0._score: "raw_score0"
- set:
    hits.hits.1._score: "raw_score1"
- set:
    hits.hits.2._score: "raw_score2"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_zero_hnsw"
      body:
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 3
          num_candidates: 3
          rescore_vector:
            oversample: 2
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- set:
    hits.hits.0._score: "override_score0"
- set:
    hits.hits.1._score: "override_score1"
- set:
    hits.hits.2._score: "override_score2"
- do:
    indices.put_mapping:
      index: "int4_rescore_zero_hnsw"
      body:
        properties:
          vector:
            type: "dense_vector"
            similarity: "max_inner_product"
            dims: 4
            index_options:
              type: "int4_hnsw"
              rescore_vector:
                oversample: 2
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_zero_hnsw"
      body:
        knn:
          field: "vector"
          query_vector:
          - -0.5
          - 90.0
          - -10
          - 14.8
          k: 3
          num_candidates: 3
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- set:
    hits.hits.0._score: "default_rescore0"
- set:
    hits.hits.1._score: "default_rescore1"
- set:
    hits.hits.2._score: "default_rescore2"
- do:
    indices.put_mapping:
      index: "int4_rescore_zero_hnsw"
      body:
        properties:
          vector:
            type: "dense_vector"
            similarity: "max_inner_product"
            dims: 4
            index_options:
              type: "int4_hnsw"
              rescore_vector:
                oversample: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    search:
      rest_total_hits_as_int: true
      index: "int4_rescore_zero_hnsw"
      body:
        query:
          script_score:
            query:
              match_all: {}
            script:
              source: "double similarity = dotProduct(params.query_vector, 'vector');\
                \ return similarity < 0 ? 1 / (1 + -1 * similarity) : similarity +\
                \ 1"
              params:
                query_vector:
                - -0.5
                - 90.0
                - -10
                - 14.8
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total: 3
- match:
    hits.hits.0._score: "$override_score0"
- match:
    hits.hits.0._score: "$default_rescore0"
- match:
    hits.hits.1._score: "$override_score1"
- match:
    hits.hits.1._score: "$default_rescore1"
- match:
    hits.hits.2._score: "$override_score2"
- match:
    hits.hits.2._score: "$default_rescore2"
