Skip to content

Commit 7631744

Browse files
numpy deserialization
1 parent c788f46 commit 7631744

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

elasticsearch/dsl/field.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,7 @@ class DenseVector(Field):
15551555
:arg dynamic:
15561556
:arg fields:
15571557
:arg synthetic_source_keep:
1558+
:arg use_numpy: if set to ``True``, deserialize as a numpy array.
15581559
"""
15591560

15601561
name = "dense_vector"
@@ -1587,6 +1588,7 @@ def __init__(
15871588
synthetic_source_keep: Union[
15881589
Literal["none", "arrays", "all"], "DefaultType"
15891590
] = DEFAULT,
1591+
use_numpy: bool = False,
15901592
**kwargs: Any,
15911593
):
15921594
if dims is not DEFAULT:
@@ -1614,6 +1616,7 @@ def __init__(
16141616
self._element_type = kwargs.get("element_type", "float")
16151617
if self._element_type in ["float", "byte"]:
16161618
kwargs["multi"] = True
1619+
self._use_numpy = use_numpy
16171620
super().__init__(*args, **kwargs)
16181621

16191622

utils/templates/field.py.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class {{ k.name }}({{ k.parent }}):
217217
{% endfor %}
218218
{% endfor %}
219219
{% endif %}
220+
{% if k.field == "dense_vector" %}
221+
:arg use_numpy: if set to ``True``, deserialize as a numpy array.
222+
{% endif %}
220223
"""
221224
name = "{{ k.field }}"
222225
{% if k.coerced %}
@@ -246,6 +249,9 @@ class {{ k.name }}({{ k.parent }}):
246249
{{ arg.name }}: {{ arg.type }} = DEFAULT,
247250
{% endif %}
248251
{% endfor %}
252+
{% if k.field == "dense_vector" %}
253+
use_numpy: bool = False,
254+
{% endif %}
249255
**kwargs: Any
250256
):
251257
{% for arg in k.args %}
@@ -416,6 +422,7 @@ class {{ k.name }}({{ k.parent }}):
416422
self._element_type = kwargs.get("element_type", "float")
417423
if self._element_type in ["float", "byte"]:
418424
kwargs["multi"] = True
425+
self._use_numpy = use_numpy
419426
super().__init__(*args, **kwargs)
420427

421428
class NumpyDenseVector(DenseVector):

0 commit comments

Comments
 (0)