From 8fb436a71f78de3d4b7ef1d209554bc3905ff7fb Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 9 Apr 2024 14:27:04 +0400 Subject: [PATCH] Address review --- .../elasticsearch-serverless-openapi.json | 86 +++++++++---------- output/schema/schema.json | 40 +++------ output/schema/validation-errors.json | 1 + output/typescript/types.ts | 6 +- specification/_types/Knn.ts | 4 +- 5 files changed, 57 insertions(+), 80 deletions(-) diff --git a/output/openapi/elasticsearch-serverless-openapi.json b/output/openapi/elasticsearch-serverless-openapi.json index 30f1e1610d..5874df7b37 100644 --- a/output/openapi/elasticsearch-serverless-openapi.json +++ b/output/openapi/elasticsearch-serverless-openapi.json @@ -34914,55 +34914,53 @@ ] }, "_types:KnnQuery": { - "type": "object", - "properties": { - "field": { - "$ref": "#/components/schemas/_types:Field" - }, - "query_vector": { - "$ref": "#/components/schemas/_types:QueryVector" - }, - "query_vector_builder": { - "$ref": "#/components/schemas/_types:QueryVectorBuilder" - }, - "k": { - "description": "The final number of nearest neighbors to return as top hits", - "type": "number" - }, - "num_candidates": { - "description": "The number of nearest neighbor candidates to consider per shard", - "type": "number" - }, - "boost": { - "description": "Boost value to apply to kNN scores", - "type": "number" + "allOf": [ + { + "$ref": "#/components/schemas/_types.query_dsl:QueryBase" }, - "filter": { - "description": "Filters for the kNN search query", - "oneOf": [ - { - "$ref": "#/components/schemas/_types.query_dsl:QueryContainer" + { + "type": "object", + "properties": { + "field": { + "$ref": "#/components/schemas/_types:Field" }, - { - "type": "array", - "items": { - "$ref": "#/components/schemas/_types.query_dsl:QueryContainer" - } + "query_vector": { + "$ref": "#/components/schemas/_types:QueryVector" + }, + "query_vector_builder": { + "$ref": "#/components/schemas/_types:QueryVectorBuilder" + }, + "num_candidates": { + "description": "The number of nearest neighbor candidates to consider per shard", + "type": "number" + }, + "boost": { + "description": "Boost value to apply to kNN scores", + "type": "number" + }, + "filter": { + "description": "Filters for the kNN search query", + "oneOf": [ + { + "$ref": "#/components/schemas/_types.query_dsl:QueryContainer" + }, + { + "type": "array", + "items": { + "$ref": "#/components/schemas/_types.query_dsl:QueryContainer" + } + } + ] + }, + "similarity": { + "description": "The minimum similarity for a vector to be considered a match", + "type": "number" } + }, + "required": [ + "field" ] - }, - "similarity": { - "description": "The minimum similarity for a vector to be considered a match", - "type": "number" - }, - "inner_hits": { - "$ref": "#/components/schemas/_global.search._types:InnerHits" } - }, - "required": [ - "field", - "k", - "num_candidates" ] }, "_types:QueryVector": { diff --git a/output/schema/schema.json b/output/schema/schema.json index 667402aa5c..f604ed007f 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -43736,6 +43736,12 @@ } }, { + "inherits": { + "type": { + "name": "QueryBase", + "namespace": "_types.query_dsl" + } + }, "kind": "interface", "name": { "name": "KnnQuery", @@ -43778,22 +43784,10 @@ } } }, - { - "description": "The final number of nearest neighbors to return as top hits", - "name": "k", - "required": true, - "type": { - "kind": "instance_of", - "type": { - "name": "long", - "namespace": "_types" - } - } - }, { "description": "The number of nearest neighbor candidates to consider per shard", "name": "num_candidates", - "required": true, + "required": false, "type": { "kind": "instance_of", "type": { @@ -43852,23 +43846,9 @@ "namespace": "_types" } } - }, - { - "description": "If defined, each search hit will contain inner hits.", - "docId": "knn-inner-hits", - "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/knn-search.html#nested-knn-search-inner-hits", - "name": "inner_hits", - "required": false, - "type": { - "kind": "instance_of", - "type": { - "name": "InnerHits", - "namespace": "_global.search._types" - } - } } ], - "specLocation": "_types/Knn.ts#L54-L76" + "specLocation": "_types/Knn.ts#L54-L69" }, { "kind": "interface", @@ -45346,7 +45326,7 @@ } } ], - "specLocation": "_types/Knn.ts#L78-L81", + "specLocation": "_types/Knn.ts#L71-L74", "variants": { "kind": "container" } @@ -47593,7 +47573,7 @@ } } ], - "specLocation": "_types/Knn.ts#L83-L86" + "specLocation": "_types/Knn.ts#L76-L79" }, { "kind": "enum", diff --git a/output/schema/validation-errors.json b/output/schema/validation-errors.json index 1b8b94e75b..d7a8cf06d1 100644 --- a/output/schema/validation-errors.json +++ b/output/schema/validation-errors.json @@ -66,6 +66,7 @@ "Request: query parameter 'scroll' does not exist in the json spec", "Request: query parameter 'rest_total_hits_as_int' does not exist in the json spec", "interface definition _types:QueryVectorBuilder - Property text_embedding is a single-variant and must be required", + "interface definition _types:KnnQuery - Property 'boost' is already defined in an ancestor class", "type_alias definition _spec_utils:PipeSeparatedFlags / union_of / instance_of - No type definition for '_spec_utils:T'" ], "response": [] diff --git a/output/typescript/types.ts b/output/typescript/types.ts index bdae491870..ba62ea34c7 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -2353,16 +2353,14 @@ export interface InlineScript extends ScriptBase { export type Ip = string -export interface KnnQuery { +export interface KnnQuery extends QueryDslQueryBase { field: Field query_vector?: QueryVector query_vector_builder?: QueryVectorBuilder - k: long - num_candidates: long + num_candidates?: long boost?: float filter?: QueryDslQueryContainer | QueryDslQueryContainer[] similarity?: float - inner_hits?: SearchInnerHits } export interface KnnSearch { diff --git a/specification/_types/Knn.ts b/specification/_types/Knn.ts index f97c9e3bb6..60562df555 100644 --- a/specification/_types/Knn.ts +++ b/specification/_types/Knn.ts @@ -19,7 +19,7 @@ import { Field } from '@_types/common' import { long, float } from '@_types/Numeric' -import { QueryContainer } from './query_dsl/abstractions' +import { QueryBase, QueryContainer } from './query_dsl/abstractions' import { InnerHits } from '@global/search/_types/hits' export type QueryVector = float[] @@ -51,7 +51,7 @@ export interface KnnSearch { inner_hits?: InnerHits } -export class KnnQuery extends QueryBase { +export interface KnnQuery extends QueryBase { /** The name of the vector field to search against */ field: Field /** The query vector */