-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: sharding non existent * test: sharding merge * fix: proof of concept on how to reduce at request level * refactor: promote apply_root * refactor: fixed circular import * fix: type error * fix: another linting error fixed * feat: cleaner interface * fix: name change due to deprecation * test: sharding move merge root Co-authored-by: Joan Fontanals Martinez <joan.martinez@jina.ai> Co-authored-by: Maximilian Werk <maximilian.werk@jina.ai>
- Loading branch information
1 parent
d800a58
commit 86853bf
Showing
9 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
!BaseExecutor | ||
with: {} | ||
metas: | ||
name: merge_root | ||
requests: | ||
on: | ||
[SearchRequest, TrainRequest, IndexRequest, DeleteRequest, UpdateRequest]: | ||
- !ReduceAllDriver | ||
with: | ||
traversal_paths: ['r'] | ||
ControlRequest: | ||
- !ControlReqDriver {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import random | ||
import string | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from jina import Document, Flow | ||
|
||
random.seed(0) | ||
np.random.seed(0) | ||
|
||
cur_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
@pytest.fixture | ||
def config(tmpdir): | ||
os.environ['JINA_SHARDING_DIR'] = str(tmpdir) | ||
yield | ||
del os.environ['JINA_SHARDING_DIR'] | ||
|
||
|
||
def random_docs(start, end, embed_dim=10): | ||
for j in range(start, end): | ||
d = Document() | ||
d.id = f'{j:0>16}' | ||
d.tags['id'] = j | ||
d.text = ''.join(random.choice(string.ascii_lowercase) for _ in range(10)).encode('utf8') | ||
d.embedding = np.random.random([embed_dim]) | ||
yield d | ||
|
||
|
||
def test_search_non_existent(config, mocker): | ||
yaml_file = 'index_kv_simple.yml' | ||
|
||
def validate_results(resp): | ||
mock() | ||
assert len(resp.docs) == 3 | ||
|
||
with Flow().add( | ||
uses=os.path.join(cur_dir, 'yaml', yaml_file), | ||
shards=2, | ||
separated_workspace=True, | ||
) as index_flow: | ||
index_flow.index(input_fn=random_docs(0, 3), request_size=1) | ||
|
||
mock = mocker.Mock() | ||
with Flow(read_only=True).add( | ||
show_exc_info=True, | ||
uses=os.path.join(cur_dir, 'yaml', yaml_file), | ||
shards=2, | ||
separated_workspace=True, | ||
uses_after='_merge_root', | ||
polling='all' | ||
) as search_flow: | ||
search_flow.search(input_fn=random_docs(0, 5), | ||
on_done=validate_results, | ||
request_size=5 | ||
) | ||
mock.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
!BinaryPbIndexer | ||
with: | ||
index_filename: doc.gzip | ||
metas: | ||
name: kvidx | ||
workspace: $JINA_SHARDING_DIR | ||
|
||
requests: | ||
on: | ||
IndexRequest: | ||
- !KVIndexDriver | ||
with: | ||
executor: kvidx | ||
traversal_paths: ['r'] | ||
SearchRequest: | ||
- !KVSearchDriver | ||
with: | ||
executor: kvidx | ||
is_merge: false | ||
traversal_paths: ['r'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters