Skip to content

[Backport 8.7] [KNN] Add query vector builder #2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 99 additions & 30 deletions output/schema/schema.json

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

3 changes: 2 additions & 1 deletion output/schema/validation-errors.json

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

18 changes: 14 additions & 4 deletions output/typescript/types.ts

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

1 change: 1 addition & 0 deletions specification/_global/knn_search/KnnSearchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FieldAndFormat } from '@_types/query_dsl/abstractions'
/**
* @rest_spec_name knn_search
* @since 8.0.0
* @deprecated 8.4.0
* @stability experimental
*/
export interface Request extends RequestBase {
Expand Down
5 changes: 2 additions & 3 deletions specification/_global/knn_search/_types/Knn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/

import { Field } from '@_types/common'
import { long, double } from '@_types/Numeric'

export type QueryVector = double[]
import { long, float } from '@_types/Numeric'
import { QueryVector } from '@_types/Knn'

export interface Query {
/** The name of the vector field to search against */
Expand Down
16 changes: 15 additions & 1 deletion specification/_types/Knn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import { Field } from '@_types/common'
import { long, double, float } from '@_types/Numeric'
import { QueryContainer } from './query_dsl/abstractions'

export type QueryVector = float[]

export interface KnnQuery {
/** The name of the vector field to search against */
field: Field
/** The query vector */
query_vector: double[]
query_vector?: QueryVector
/** The query vector builder. You must provide a query_vector_builder or query_vector, but not both. */
query_vector_builder?: QueryVectorBuilder
/** The final number of nearest neighbors to return as top hits */
k: long
/** The number of nearest neighbor candidates to consider per shard */
Expand All @@ -35,3 +39,13 @@ export interface KnnQuery {
/** Filters for the kNN search query */
filter?: QueryContainer | QueryContainer[]
}

/** @variants container */
export interface QueryVectorBuilder {
text_embedding?: TextEmbedding
}

export interface TextEmbedding {
model_id: string
model_text: string
}