Skip to content

Commit

Permalink
Add 'knn' property to Search request body
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson authored Aug 4, 2022
1 parent eb79528 commit 255393c
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 114 deletions.
267 changes: 171 additions & 96 deletions output/schema/schema.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions output/typescript/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions specification/_global/msearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { SourceConfig } from '@global/search/_types/SourceFilter'
import { RuntimeFields } from '@_types/mapping/RuntimeFields'
import { ScriptField } from '@_types/Scripting'
import { SlicedScroll } from '@_types/SlicedScroll'
import { KnnQuery } from '@_types/Knn'

/**
* @codegen_names header, body
Expand Down Expand Up @@ -91,6 +92,11 @@ export class MultisearchBody {
* names matching these patterns in the hits.fields property of the response.
*/
docvalue_fields?: FieldAndFormat[]
/**
* Defines the approximate kNN search to run.
* @since 8.4.0
*/
knn?: KnnQuery
/**
* Starting document offset. By default, you cannot page through more than 10,000
* hits using the from and size parameters. To page through more hits, use the
Expand Down
6 changes: 6 additions & 0 deletions specification/_global/search/SearchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Suggester } from './_types/suggester'
import { TrackHits } from '@global/search/_types/hits'
import { Operator } from '@_types/query_dsl/Operator'
import { Sort, SortResults } from '@_types/sort'
import { KnnQuery } from '@_types/Knn'

/**
* @rest_spec_name search
Expand Down Expand Up @@ -141,6 +142,11 @@ export interface Request extends RequestBase {
* names matching these patterns in the hits.fields property of the response.
*/
docvalue_fields?: FieldAndFormat[]
/**
* Defines the approximate kNN search to run.
* @since 8.4.0
*/
knn?: KnnQuery
/**
* Minimum _score for matching documents. Documents with a lower _score are
* not included in the search results.
Expand Down
37 changes: 37 additions & 0 deletions specification/_types/Knn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Field } from '@_types/common'
import { long, double, float } from '@_types/Numeric'
import { QueryContainer } from './query_dsl/abstractions'

export interface KnnQuery {
/** The name of the vector field to search against */
field: Field
/** The query vector */
query_vector: double[]
/** The final number of nearest neighbors to return as top hits */
k: long
/** The number of nearest neighbor candidates to consider per shard */
num_candidates: long
/** Boost value to apply to kNN scores */
boost?: float
/** Filters for the kNN search query */
filter?: QueryContainer | QueryContainer[]
}
2 changes: 0 additions & 2 deletions specification/_types/query_dsl/abstractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import {
ExistsQuery,
FuzzyQuery,
IdsQuery,
KnnQuery,
PrefixQuery,
RangeQuery,
RegexpQuery,
Expand Down Expand Up @@ -120,7 +119,6 @@ export class QueryContainer {
has_parent?: HasParentQuery
ids?: IdsQuery
intervals?: SingleKeyDictionary<Field, IntervalsQuery>
knn?: KnnQuery
match?: SingleKeyDictionary<Field, MatchQuery>
match_all?: MatchAllQuery
match_bool_prefix?: SingleKeyDictionary<Field, MatchBoolPrefixQuery>
Expand Down
9 changes: 0 additions & 9 deletions specification/_types/query_dsl/term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ export class ExistsQuery extends QueryBase {
field: Field
}

/**
* A k-nearest neighbor (kNN) search finds the k nearest vectors to a query vector, as measured by a similarity metric.
*/
export class KnnQuery extends QueryBase {
field: Field
num_candidates: integer
query_vector: double[]
}

/** @shortcut_property value */
export class FuzzyQuery extends QueryBase {
max_expansions?: integer
Expand Down
6 changes: 6 additions & 0 deletions specification/async_search/submit/AsyncSearchSubmitRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
import { Suggester } from '@global/search/_types/suggester'
import { TrackHits } from '@global/search/_types/hits'
import { Operator } from '@_types/query_dsl/Operator'
import { KnnQuery } from '@_types/Knn'

/**
* @rest_spec_name async_search.submit
Expand Down Expand Up @@ -151,6 +152,11 @@ export interface Request extends RequestBase {
* names matching these patterns in the hits.fields property of the response.
*/
docvalue_fields?: FieldAndFormat[]
/**
* Defines the approximate kNN search to run.
* @since 8.4.0
*/
knn?: KnnQuery
/**
* Minimum _score for matching documents. Documents with a lower _score are
* not included in the search results.
Expand Down

0 comments on commit 255393c

Please sign in to comment.