Skip to content

Commit 5828dc9

Browse files
committed
Add sparse_vector query to client specification
1 parent ce9d54c commit 5828dc9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Field, Id } from '@_types/common'
21+
import { QueryBase } from './abstractions'
22+
import { float } from '@_types/Numeric'
23+
import { Dictionary } from '@spec_utils/Dictionary'
24+
import { TokenPruningConfig } from './TokenPruningConfig'
25+
26+
export class SparseVectorQuery extends QueryBase {
27+
/**
28+
* The name of the field that contains the token-weight pairs to be searched against.
29+
* This field must be a mapped sparse_vector field.
30+
*/
31+
field: Field
32+
33+
/**
34+
* Dictionary of precomputed sparse vectors and their associated weights.
35+
* Only one of inference_id or query_vector may be supplied in a request.
36+
*/
37+
query_vector?: Dictionary<string, float>
38+
39+
/**
40+
* The inference ID to use to convert the query text into token-weight pairs.
41+
* It must be the same inference ID that was used to create the tokens from the input text.
42+
* Only one of inference_id and query_vector is allowed.
43+
* If inference_id is specified, query must also be specified.
44+
* Only one of inference_id or query_vector may be supplied in a request.
45+
*/
46+
inference_id?: Id
47+
48+
/**
49+
* The query text you want to use for search.
50+
* If inference_id is specified, query must also be specified.
51+
*/
52+
query?: String
53+
54+
/**
55+
* Whether to perform pruning, omitting the non-significant tokens from the query to improve query performance.
56+
* If prune is true but the pruning_config is not specified, pruning will occur but default values will be used.
57+
* @default false
58+
* @availability stack since=8.15.0 stability=experimental
59+
* @availability serverless stability=experimental
60+
*/
61+
prune?: Boolean
62+
63+
/**
64+
* Optional pruning configuration.
65+
* If enabled, this will omit non-significant tokens from the query in order to improve query performance.
66+
* This is only used if prune is set to true.
67+
* If prune is set to true but pruning_config is not specified, default values will be used.
68+
* @availability stack since=8.15.0 stability=experimental
69+
* @availability serverless stability=experimental
70+
*/
71+
pruning_config?: TokenPruningConfig
72+
}

specification/_types/query_dsl/abstractions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import { TextExpansionQuery } from './TextExpansionQuery'
9797
import { WeightedTokensQuery } from './WeightedTokensQuery'
9898
import { KnnQuery } from '@_types/Knn'
9999
import { SemanticQuery } from './SemanticQuery'
100+
import { SparseVectorQuery } from './SparseVectorQuery'
100101

101102
/**
102103
* @variants container
@@ -364,6 +365,13 @@ export class QueryContainer {
364365
* @doc_id query-dsl-span-within-query
365366
*/
366367
span_within?: SpanWithinQuery
368+
/**
369+
* Using input query vectors or a natural language processing model to convert a query into a list of token-weight pairs, queries against a sparse vector field.
370+
* @availability stack since=8.15.0
371+
* @availability serverless
372+
* @doc_id query-dsl-sparse-vector-query
373+
*/
374+
sparse_vector?: SparseVectorQuery
367375
/**
368376
* Returns documents that contain an exact term in a provided field.
369377
* To return a document, the query term must exactly match the queried field's value, including whitespace and capitalization.
@@ -387,13 +395,15 @@ export class QueryContainer {
387395
* @availability stack since=8.8.0
388396
* @availability serverless
389397
* @doc_id query-dsl-text-expansion-query
398+
* @deprecated 8.15.0
390399
*/
391400
text_expansion?: SingleKeyDictionary<Field, TextExpansionQuery>
392401
/**
393402
* Supports returning text_expansion query results by sending in precomputed tokens with the query.
394403
* @availability stack since=8.13.0
395404
* @availability serverless
396405
* @doc_id query-dsl-weighted-tokens-query
406+
* @deprecated 8.15.0
397407
*/
398408
weighted_tokens?: SingleKeyDictionary<Field, WeightedTokensQuery>
399409
/**

0 commit comments

Comments
 (0)