-
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.
feat: ref indexer avoid getting abspath
- Loading branch information
Showing
8 changed files
with
149 additions
and
2 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
Empty file.
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,4 @@ | ||
!Flow | ||
pods: | ||
indexer: | ||
uses: pods/indexer.yml |
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,6 @@ | ||
!NumpyIndexer | ||
with: | ||
index_filename: 'index.gz' | ||
metas: | ||
workspace: $JINA_TEST_INDEXER_WITH_REF_INDEXER | ||
name: wrapidx |
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 @@ | ||
!NumpyIndexer | ||
with: | ||
ref_indexer: | ||
!NumpyIndexer | ||
with: | ||
index_filename: 'index.gz' | ||
metas: | ||
workspace: $JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY | ||
name: wrapidx | ||
metas: | ||
name: indexer | ||
workspace: $JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY |
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,4 @@ | ||
!Flow | ||
pods: | ||
indexer: | ||
uses: pods/indexer_with_ref.yml |
85 changes: 85 additions & 0 deletions
85
tests/integration/ref_indexer/test_numpy_indexer_with_ref_indexer.py
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,85 @@ | ||
import os | ||
import shutil | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from jina.flow import Flow | ||
from jina import Document | ||
|
||
|
||
@pytest.fixture | ||
def index_docs(): | ||
docs = [] | ||
for idx in range(0, 100): | ||
doc = Document() | ||
doc.id = f'{idx:0>16}' | ||
doc.embedding = doc.embedding = np.array([idx, idx]) | ||
docs.append(doc) | ||
return docs | ||
|
||
|
||
@pytest.fixture | ||
def random_workspace(tmpdir): | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] = str(tmpdir) | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] = str(tmpdir) | ||
yield | ||
del os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] | ||
del os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] | ||
|
||
|
||
def test_indexer_with_ref_indexer(random_workspace, index_docs, mocker): | ||
top_k = 10 | ||
with Flow.load_config('index.yml') as index_flow: | ||
index_flow.index(input_fn=index_docs, batch_size=10) | ||
|
||
mock = mocker.Mock() | ||
|
||
def validate_response(resp): | ||
mock() | ||
assert len(resp.search.docs) == 1 | ||
assert len(resp.search.docs[0].matches) == top_k | ||
|
||
query_document = Document() | ||
query_document.embedding = np.array([1, 1]) | ||
with Flow.load_config('query.yml') as query_flow: | ||
query_flow.search(input_fn=[query_document], on_done=validate_response, top_k=top_k) | ||
|
||
mock.assert_called_once() | ||
|
||
|
||
@pytest.fixture | ||
def random_workspace_move(tmpdir): | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] = str(tmpdir) | ||
os.mkdir(str(tmpdir) + '/query') | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] = str(tmpdir) + '/query' | ||
yield | ||
del os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] | ||
del os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] | ||
|
||
|
||
def test_indexer_with_ref_indexer_move(random_workspace_move, index_docs, mocker): | ||
top_k = 10 | ||
with Flow.load_config('index.yml') as index_flow: | ||
index_flow.index(input_fn=index_docs, batch_size=10) | ||
|
||
mock = mocker.Mock() | ||
|
||
shutil.move(os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] + '/wrapidx.bin', | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] + '/wrapidx.bin') | ||
shutil.move(os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER'] + '/index.gz', | ||
os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY'] + '/index.gz',) | ||
|
||
print(f' JOAN ', os.environ['JINA_TEST_INDEXER_WITH_REF_INDEXER_QUERY']) | ||
|
||
def validate_response(resp): | ||
mock() | ||
assert len(resp.search.docs) == 1 | ||
assert len(resp.search.docs[0].matches) == top_k | ||
|
||
query_document = Document() | ||
query_document.embedding = np.array([1, 1]) | ||
with Flow.load_config('query.yml') as query_flow: | ||
query_flow.search(input_fn=[query_document], on_done=validate_response, top_k=top_k) | ||
|
||
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