Skip to content

Commit c1b4aa5

Browse files
author
Joan Fontanals Martinez
committed
fix: fix elastic v7 test
Signed-off-by: Joan Fontanals Martinez <[email protected]>
1 parent 46bcf5a commit c1b4aa5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

docarray/index/backends/elastic.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767

6868

6969
class ElasticDocIndex(BaseDocIndex, Generic[TSchema]):
70+
_index_vector_params: Optional[Tuple[str]] = ('dims', 'similarity', 'index')
71+
_index_vector_options: Optional[Tuple[str]] = ('m', 'ef_construction')
72+
7073
def __init__(self, db_config=None, **kwargs):
7174
"""Initialize ElasticDocIndex"""
7275
super().__init__(db_config=db_config, **kwargs)
@@ -82,9 +85,6 @@ def __init__(self, db_config=None, **kwargs):
8285
self._logger.debug('ElasticSearch client has been created')
8386

8487
# ElasticSearh index setup
85-
self._index_vector_params = ('dims', 'similarity', 'index')
86-
self._index_vector_options = ('m', 'ef_construction')
87-
8888
mappings: Dict[str, Any] = {
8989
'dynamic': True,
9090
'_source': {'enabled': 'true'},
@@ -572,20 +572,23 @@ def _filter_by_parent_id(self, id: str) -> List[str]:
572572
# Helpers #
573573
###############################################
574574

575-
def _create_index_mapping(self, col: '_ColumnInfo') -> Dict[str, Any]:
575+
@classmethod
576+
def _create_index_mapping(cls, col: '_ColumnInfo') -> Dict[str, Any]:
576577
"""Create a new HNSW index for a column, and initialize it."""
577578

578579
index = {'type': col.config['type'] if 'type' in col.config else col.db_type}
579580

580581
if col.db_type == 'dense_vector':
581-
for k in self._index_vector_params:
582-
index[k] = col.config[k]
582+
if cls._index_vector_params is not None:
583+
for k in cls._index_vector_params:
584+
index[k] = col.config[k]
583585
if col.n_dim:
584586
index['dims'] = col.n_dim
585-
index['index_options'] = dict(
586-
(k, col.config[k]) for k in self._index_vector_options
587-
)
588-
index['index_options']['type'] = 'hnsw'
587+
if cls._index_vector_options is not None:
588+
index['index_options'] = dict(
589+
(k, col.config[k]) for k in cls._index_vector_options
590+
)
591+
index['index_options']['type'] = 'hnsw'
589592
return index
590593

591594
def _send_requests(

docarray/index/backends/elasticv7.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import warnings
22
from dataclasses import dataclass
3-
from typing import Any, Dict, List, Optional, Sequence, TypeVar, Union
3+
from typing import Any, Dict, List, Optional, Sequence, TypeVar, Union, Tuple
44

55
import numpy as np
66
from pydantic import parse_obj_as
77

88
from docarray import BaseDoc
99
from docarray.index import ElasticDocIndex
10-
from docarray.index.abstract import BaseDocIndex, _ColumnInfo
10+
from docarray.index.abstract import BaseDocIndex
1111
from docarray.typing import AnyTensor
1212
from docarray.typing.tensor.ndarray import NdArray
1313
from docarray.utils.find import _FindResult
@@ -17,6 +17,9 @@
1717

1818

1919
class ElasticV7DocIndex(ElasticDocIndex):
20+
_index_vector_params: Optional[Tuple[str]] = ('dims',)
21+
_index_vector_options: Optional[Tuple[str]] = None
22+
2023
def __init__(self, db_config=None, **kwargs):
2124
"""Initialize ElasticV7DocIndex"""
2225
from elasticsearch import __version__ as __es__version__

0 commit comments

Comments
 (0)