Skip to content

Commit

Permalink
fix: shard may be empty (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Jan 15, 2021
1 parent c275cc8 commit fa47adb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions jina/drivers/search.py
Expand Up @@ -120,6 +120,10 @@ def _apply_all(self, docs: 'DocumentSet', *args, **kwargs) -> None:
if bad_docs:
self.logger.warning(f'these bad docs can not be added: {bad_docs}')
idx, dist = self.exec_fn(embed_vecs, top_k=int(self.top_k))

if idx is None and dist is None:
return

op_name = self.exec.__class__.__name__
for doc, topks, scores in zip(doc_pts, idx, dist):

Expand Down
Empty file.
4 changes: 4 additions & 0 deletions tests/integration/issues/github_1684/flow.yml
@@ -0,0 +1,4 @@
!Flow
pods:
indexer:
uses: index.yml
6 changes: 6 additions & 0 deletions tests/integration/issues/github_1684/index.yml
@@ -0,0 +1,6 @@
!NumpyIndexer
with:
index_filename: vec.gz
metas:
workspace: $JINA_TEST_1684_WORKSPACE

39 changes: 39 additions & 0 deletions tests/integration/issues/github_1684/test_empty_shard.py
@@ -0,0 +1,39 @@
import os

import pytest
import numpy as np

from jina.flow import Flow
from jina import Document

cur_dir = os.path.dirname(os.path.abspath(__file__))


@pytest.fixture
def workdir(tmpdir):
os.environ['JINA_TEST_1684_WORKSPACE'] = str(tmpdir)
yield
del os.environ['JINA_TEST_1684_WORKSPACE']


def test_empty_shard(mocker, workdir):
doc = Document()
doc.text = 'text'
doc.embedding = np.array([1, 1, 1])
mock = mocker.Mock()

def validate_response(resp):
mock()
assert len(resp.docs) == 1
assert len(resp.docs[0].matches) == 0

error_mock = mocker.Mock()

def on_error_call():
error_mock()

with Flow.load_config(os.path.join(cur_dir, 'flow.yml')) as f:
f.search([doc], on_done=validate_response, on_error=on_error_call)

mock.assert_called_once()
error_mock.assert_not_called()
2 changes: 0 additions & 2 deletions tests/integration/level_depth/test_search_different_depths.py
@@ -1,5 +1,3 @@
import os

import pytest

from jina.flow import Flow
Expand Down

0 comments on commit fa47adb

Please sign in to comment.