Skip to content

Commit 7de3854

Browse files
use internal aggregation range class for date aggregation ranges
1 parent eac539d commit 7de3854

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

elasticsearch/dsl/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class Knn(Query):
10841084
:arg similarity: The minimum similarity for a vector to be considered
10851085
a match
10861086
:arg rescore_vector: Apply oversampling and rescoring to quantized
1087-
vectors *
1087+
vectors
10881088
:arg boost: Floating point number used to decrease or increase the
10891089
relevance scores of the query. Boost values are relative to the
10901090
default value of 1.0. A boost value between 0 and 1.0 decreases

elasticsearch/dsl/types.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,31 +324,58 @@ class DenseVectorIndexOptions(AttrDict[Any]):
324324
`int4_flat` index types.
325325
:arg ef_construction: The number of candidates to track while
326326
assembling the list of nearest neighbors for each new node. Only
327-
applicable to `hnsw`, `int8_hnsw`, and `int4_hnsw` index types.
328-
Defaults to `100` if omitted.
327+
applicable to `hnsw`, `int8_hnsw`, `bbq_hnsw`, and `int4_hnsw`
328+
index types. Defaults to `100` if omitted.
329329
:arg m: The number of neighbors each node will be connected to in the
330-
HNSW graph. Only applicable to `hnsw`, `int8_hnsw`, and
331-
`int4_hnsw` index types. Defaults to `16` if omitted.
330+
HNSW graph. Only applicable to `hnsw`, `int8_hnsw`, `bbq_hnsw`,
331+
and `int4_hnsw` index types. Defaults to `16` if omitted.
332+
:arg rescore_vector: The rescore vector options. This is only
333+
applicable to `bbq_hnsw`, `int4_hnsw`, `int8_hnsw`, `bbq_flat`,
334+
`int4_flat`, and `int8_flat` index types.
332335
"""
333336

334337
type: Union[
335-
Literal["flat", "hnsw", "int4_flat", "int4_hnsw", "int8_flat", "int8_hnsw"],
338+
Literal[
339+
"bbq_flat",
340+
"bbq_hnsw",
341+
"flat",
342+
"hnsw",
343+
"int4_flat",
344+
"int4_hnsw",
345+
"int8_flat",
346+
"int8_hnsw",
347+
],
336348
DefaultType,
337349
]
338350
confidence_interval: Union[float, DefaultType]
339351
ef_construction: Union[int, DefaultType]
340352
m: Union[int, DefaultType]
353+
rescore_vector: Union[
354+
"DenseVectorIndexOptionsRescoreVector", Dict[str, Any], DefaultType
355+
]
341356

342357
def __init__(
343358
self,
344359
*,
345360
type: Union[
346-
Literal["flat", "hnsw", "int4_flat", "int4_hnsw", "int8_flat", "int8_hnsw"],
361+
Literal[
362+
"bbq_flat",
363+
"bbq_hnsw",
364+
"flat",
365+
"hnsw",
366+
"int4_flat",
367+
"int4_hnsw",
368+
"int8_flat",
369+
"int8_hnsw",
370+
],
347371
DefaultType,
348372
] = DEFAULT,
349373
confidence_interval: Union[float, DefaultType] = DEFAULT,
350374
ef_construction: Union[int, DefaultType] = DEFAULT,
351375
m: Union[int, DefaultType] = DEFAULT,
376+
rescore_vector: Union[
377+
"DenseVectorIndexOptionsRescoreVector", Dict[str, Any], DefaultType
378+
] = DEFAULT,
352379
**kwargs: Any,
353380
):
354381
if type is not DEFAULT:
@@ -359,6 +386,29 @@ def __init__(
359386
kwargs["ef_construction"] = ef_construction
360387
if m is not DEFAULT:
361388
kwargs["m"] = m
389+
if rescore_vector is not DEFAULT:
390+
kwargs["rescore_vector"] = rescore_vector
391+
super().__init__(kwargs)
392+
393+
394+
class DenseVectorIndexOptionsRescoreVector(AttrDict[Any]):
395+
"""
396+
:arg oversample: (required) The oversampling factor to use when
397+
searching for the nearest neighbor. This is only applicable to the
398+
quantized formats: `bbq_*`, `int4_*`, and `int8_*`. When provided,
399+
`oversample * k` vectors will be gathered and then their scores
400+
will be re-computed with the original vectors. valid values are
401+
between `1.0` and `10.0` (inclusive), or `0` exactly to disable
402+
oversampling.
403+
"""
404+
405+
oversample: Union[float, DefaultType]
406+
407+
def __init__(
408+
self, *, oversample: Union[float, DefaultType] = DEFAULT, **kwargs: Any
409+
):
410+
if oversample is not DEFAULT:
411+
kwargs["oversample"] = oversample
362412
super().__init__(kwargs)
363413

364414

utils/dsl-generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ def get_python_type(self, schema_type, for_response=False):
345345
]["name"].endswith("Analyzer"):
346346
# not expanding analyzers at this time, maybe in the future
347347
return "str, Dict[str, Any]", None
348-
elif (
349-
schema_type["name"]["namespace"] == "_types.aggregations"
350-
and schema_type["name"]["name"].endswith("AggregationRange")
351-
and schema_type["name"]["name"] != "IpRangeAggregationRange"
352-
):
353-
return '"wrappers.AggregationRange"', None
348+
elif schema_type["name"]["namespace"] == "_types.aggregations":
349+
if (
350+
schema_type["name"]["name"].endswith("AggregationRange")
351+
or schema_type["name"]["name"] == "DateRangeExpression"
352+
) and schema_type["name"]["name"] != "IpRangeAggregationRange":
353+
return '"wrappers.AggregationRange"', None
354354

355355
# to handle other interfaces we generate a type of the same name
356356
# and add the interface to the interfaces.py module

0 commit comments

Comments
 (0)