-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(elastic): update offset2ids management #416
Changes from 7 commits
1f19451
b96cb97
23a98d8
31a01fa
1c317af
9a5112c
f6d8454
4df7034
8d005c3
a22aa54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from docarray import Document, DocumentArray | ||
|
||
|
||
def test_add_ignore_existing_doc_id(start_storage): | ||
elastic_doc = DocumentArray( | ||
storage='elasticsearch', | ||
config={ | ||
'n_dim': 3, | ||
'columns': [('price', 'int')], | ||
'distance': 'l2_norm', | ||
'index_name': 'test_add', | ||
}, | ||
) | ||
|
||
with elastic_doc: | ||
elastic_doc.extend( | ||
[ | ||
Document(id='r0', embedding=[0, 0, 0]), | ||
Document(id='r1', embedding=[1, 1, 1]), | ||
Document(id='r2', embedding=[2, 2, 2]), | ||
Document(id='r3', embedding=[3, 3, 3]), | ||
Document(id='r4', embedding=[4, 4, 4]), | ||
] | ||
) | ||
|
||
with elastic_doc: | ||
elastic_doc.extend( | ||
[ | ||
Document(id='r0', embedding=[0, 0, 0]), | ||
Document(id='r2', embedding=[2, 2, 2]), | ||
Document(id='r4', embedding=[4, 4, 4]), | ||
Document(id='r5', embedding=[2, 2, 2]), | ||
Document(id='r6', embedding=[4, 4, 4]), | ||
] | ||
) | ||
|
||
indexed_offset_count = elastic_doc._client.count( | ||
index=elastic_doc._index_name_offset2id | ||
)['count'] | ||
|
||
assert len(elastic_doc) == len(elastic_doc[:, 'embedding']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assert that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay noted |
||
assert len(elastic_doc) == indexed_offset_count |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from docarray import Document, DocumentArray | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize('deleted_elmnts', [[0, 1], ['r0', 'r1']]) | ||
def test_delete_offset_success_sync_es_offset_index(deleted_elmnts, start_storage): | ||
elastic_doc = DocumentArray( | ||
storage='elasticsearch', | ||
config={ | ||
'n_dim': 3, | ||
'columns': [('price', 'int')], | ||
'distance': 'l2_norm', | ||
'index_name': 'test_delete', | ||
}, | ||
) | ||
|
||
with elastic_doc: | ||
elastic_doc.extend( | ||
[ | ||
Document(id='r0', embedding=[0, 0, 0]), | ||
Document(id='r1', embedding=[1, 1, 1]), | ||
Document(id='r2', embedding=[2, 2, 2]), | ||
Document(id='r3', embedding=[3, 3, 3]), | ||
Document(id='r4', embedding=[4, 4, 4]), | ||
Document(id='r5', embedding=[5, 5, 5]), | ||
Document(id='r6', embedding=[6, 6, 6]), | ||
Document(id='r7', embedding=[7, 7, 7]), | ||
] | ||
) | ||
|
||
expected_offset_after_del = ['r2', 'r3', 'r4', 'r5', 'r6', 'r7'] | ||
|
||
with elastic_doc: | ||
del elastic_doc[deleted_elmnts] | ||
|
||
indexed_offset_count = elastic_doc._client.count( | ||
index=elastic_doc._index_name_offset2id | ||
)['count'] | ||
|
||
assert len(elastic_doc._offset2ids.ids) == indexed_offset_count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, what should be the length here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep will be updated |
||
|
||
for id in expected_offset_after_del: | ||
expected_offset = str(expected_offset_after_del.index(id)) | ||
actual_offset_index = elastic_doc._client.search( | ||
index=elastic_doc._index_name_offset2id, query={'match': {'blob': id}} | ||
)['hits']['hits'][0]['_id'] | ||
assert actual_offset_index == expected_offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you perhaps randomize the index name or give the index name the exact same name as the test function name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure will do