Skip to content

Commit 46bcf5a

Browse files
author
Joan Fontanals Martinez
committed
fix: fix the hnswlib tests
Signed-off-by: Joan Fontanals Martinez <[email protected]>
1 parent 3f4e86f commit 46bcf5a

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

docarray/index/backends/elasticv7.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,6 @@ def execute_query(self, query: Dict[str, Any], *args, **kwargs) -> Any:
130130
# Helpers #
131131
###############################################
132132

133-
# ElasticSearch helpers
134-
def _create_index_mapping(self, col: '_ColumnInfo') -> Dict[str, Any]:
135-
"""Create a new HNSW index for a column, and initialize it."""
136-
137-
index = col.config.copy()
138-
if 'type' not in index:
139-
index['type'] = col.db_type
140-
141-
if col.db_type == 'dense_vector' and col.n_dim:
142-
index['dims'] = col.n_dim
143-
144-
return index
145-
146133
def _form_search_body(self, query: np.ndarray, limit: int, search_field: str = '') -> Dict[str, Any]: # type: ignore
147134
body = {
148135
'size': limit,

docarray/index/backends/hnswlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, db_config=None, **kwargs):
115115
sub_docs_exist = True
116116
if safe_issubclass(col.docarray_type, AnyDocArray):
117117
continue
118-
if not col.config:
118+
if not col.config or 'dim' not in col.config:
119119
# non-tensor type; don't create an index
120120
continue
121121
if not load_existing and (

tests/index/base_classes/test_base_doc_store.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_create_columns():
157157
assert index._column_infos['id'].docarray_type == ID
158158
assert index._column_infos['id'].db_type == str
159159
assert index._column_infos['id'].n_dim is None
160-
assert index._column_infos['id'].config == {'hi': 'there'}
160+
assert index._column_infos['id'].config['hi'] == 'there'
161161

162162
assert issubclass(index._column_infos['tens'].docarray_type, AbstractTensor)
163163
assert index._column_infos['tens'].db_type == str
@@ -171,7 +171,7 @@ def test_create_columns():
171171
assert index._column_infos['id'].docarray_type == ID
172172
assert index._column_infos['id'].db_type == str
173173
assert index._column_infos['id'].n_dim is None
174-
assert index._column_infos['id'].config == {'hi': 'there'}
174+
assert index._column_infos['id'].config['hi'] == 'there'
175175

176176
assert issubclass(index._column_infos['tens_one'].docarray_type, AbstractTensor)
177177
assert index._column_infos['tens_one'].db_type == str
@@ -190,7 +190,7 @@ def test_create_columns():
190190
assert index._column_infos['id'].docarray_type == ID
191191
assert index._column_infos['id'].db_type == str
192192
assert index._column_infos['id'].n_dim is None
193-
assert index._column_infos['id'].config == {'hi': 'there'}
193+
assert index._column_infos['id'].config['hi'] == 'there'
194194

195195
assert issubclass(index._column_infos['d__tens'].docarray_type, AbstractTensor)
196196
assert index._column_infos['d__tens'].db_type == str
@@ -214,7 +214,7 @@ def test_create_columns():
214214
assert index._subindices['d']._column_infos['id'].docarray_type == ID
215215
assert index._subindices['d']._column_infos['id'].db_type == str
216216
assert index._subindices['d']._column_infos['id'].n_dim is None
217-
assert index._subindices['d']._column_infos['id'].config == {'hi': 'there'}
217+
assert index._subindices['d']._column_infos['id'].config['hi'] == 'there'
218218

219219
assert issubclass(
220220
index._subindices['d']._column_infos['tens'].docarray_type, AbstractTensor
@@ -262,10 +262,10 @@ def test_create_columns():
262262
assert (
263263
index._subindices['d_root']._subindices['d']._column_infos['id'].n_dim is None
264264
)
265-
assert index._subindices['d_root']._subindices['d']._column_infos['id'].config == {
266-
'hi': 'there'
267-
}
268-
265+
assert (
266+
index._subindices['d_root']._subindices['d']._column_infos['id'].config['hi']
267+
== 'there'
268+
)
269269
assert issubclass(
270270
index._subindices['d_root']
271271
._subindices['d']

0 commit comments

Comments
 (0)