Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: fix elastic v7 test
Signed-off-by: Joan Fontanals Martinez <[email protected]>
  • Loading branch information
Joan Fontanals Martinez committed Aug 1, 2023
commit c1b4aa5963719be2b433d2fbeef1369a238794ac
23 changes: 13 additions & 10 deletions docarray/index/backends/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@


class ElasticDocIndex(BaseDocIndex, Generic[TSchema]):
_index_vector_params: Optional[Tuple[str]] = ('dims', 'similarity', 'index')
_index_vector_options: Optional[Tuple[str]] = ('m', 'ef_construction')

def __init__(self, db_config=None, **kwargs):
"""Initialize ElasticDocIndex"""
super().__init__(db_config=db_config, **kwargs)
Expand All @@ -82,9 +85,6 @@ def __init__(self, db_config=None, **kwargs):
self._logger.debug('ElasticSearch client has been created')

# ElasticSearh index setup
self._index_vector_params = ('dims', 'similarity', 'index')
self._index_vector_options = ('m', 'ef_construction')

mappings: Dict[str, Any] = {
'dynamic': True,
'_source': {'enabled': 'true'},
Expand Down Expand Up @@ -572,20 +572,23 @@ def _filter_by_parent_id(self, id: str) -> List[str]:
# Helpers #
###############################################

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

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

if col.db_type == 'dense_vector':
for k in self._index_vector_params:
index[k] = col.config[k]
if cls._index_vector_params is not None:
for k in cls._index_vector_params:
index[k] = col.config[k]
if col.n_dim:
index['dims'] = col.n_dim
index['index_options'] = dict(
(k, col.config[k]) for k in self._index_vector_options
)
index['index_options']['type'] = 'hnsw'
if cls._index_vector_options is not None:
index['index_options'] = dict(
(k, col.config[k]) for k in cls._index_vector_options
)
index['index_options']['type'] = 'hnsw'
return index

def _send_requests(
Expand Down
7 changes: 5 additions & 2 deletions docarray/index/backends/elasticv7.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import warnings
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Sequence, TypeVar, Union
from typing import Any, Dict, List, Optional, Sequence, TypeVar, Union, Tuple

import numpy as np
from pydantic import parse_obj_as

from docarray import BaseDoc
from docarray.index import ElasticDocIndex
from docarray.index.abstract import BaseDocIndex, _ColumnInfo
from docarray.index.abstract import BaseDocIndex
from docarray.typing import AnyTensor
from docarray.typing.tensor.ndarray import NdArray
from docarray.utils.find import _FindResult
Expand All @@ -17,6 +17,9 @@


class ElasticV7DocIndex(ElasticDocIndex):
_index_vector_params: Optional[Tuple[str]] = ('dims',)
_index_vector_options: Optional[Tuple[str]] = None

def __init__(self, db_config=None, **kwargs):
"""Initialize ElasticV7DocIndex"""
from elasticsearch import __version__ as __es__version__
Expand Down