Esempio n. 1
0
 def validate_response(resp):
     valid_resp_length = (len(resp.search.docs) == request_size) or (len(
         resp.search.docs) == num_docs_last_req_batch)
     assert valid_resp_length
     for doc in resp.search.docs:
         assert NdArray(doc.embedding).value is not None
         for chunk in doc.chunks:
             assert NdArray(chunk.embedding).value is not None
             for chunk_chunk in chunk.chunks:
                 assert NdArray(chunk_chunk.embedding).value is not None
Esempio n. 2
0
def test_random_docs_new_api():
    np.random.seed(42)
    docs1 = list(random_docs(10))
    np.random.seed(42)
    docs2 = list(random_docs_new_api(10))
    for d2, d1 in zip(docs2, docs1):
        np.testing.assert_almost_equal(d2.embedding, NdArray(d1.embedding).value)
        assert d2.text == d1.text
        assert d2.tags['id'] == d1.tags['id']
        for c2, c1 in zip(d2.chunks, d1.chunks):
            np.testing.assert_almost_equal(c2.embedding, NdArray(c1.embedding).value)
            assert c2.text == c1.text
            assert c2.tags['id'] == c1.tags['id']
Esempio n. 3
0
def test_random_docs():
    np.random.seed(42)
    nr_docs = 10
    docs1 = list(random_docs(nr_docs))
    np.random.seed(42)
    docs2 = list(random_docs(nr_docs))
    doc_ids = []
    chunk_ids = []
    for d2, d1 in zip(docs2, docs1):
        np.testing.assert_almost_equal(d2.embedding, NdArray(d1.embedding).value)
        doc_ids.append((d1.id))
        assert d2.text == d1.text
        assert d2.tags['id'] == d1.tags['id']
        for c2, c1 in zip(d2.chunks, d1.chunks):
            np.testing.assert_almost_equal(c2.embedding, NdArray(c1.embedding).value)
            chunk_ids.append((c1.id))
            assert c2.text == c1.text
            assert c2.tags['id'] == c1.tags['id']
            assert c2.tags['parent_id'] == c1.tags['parent_id']
    assert len(set(doc_ids)) == len(doc_ids)
    assert len(set(chunk_ids)) == len(chunk_ids)
    assert len(set(doc_ids).intersection(set(chunk_ids))) == 0
Esempio n. 4
0
def test_ndarray_get_set(field):
    a = Document()
    b = np.random.random([10, 10])
    setattr(a, field, b)
    np.testing.assert_equal(getattr(a, field), b)

    b = np.random.random([10, 10])
    c = NdArray()
    c.value = b
    setattr(a, field, c)
    np.testing.assert_equal(getattr(a, field), b)

    b = np.random.random([10, 10])
    c = NdArray()
    c.value = b
    setattr(a, field, c._pb_body)
    np.testing.assert_equal(getattr(a, field), b)
Esempio n. 5
0
import pytest

from jina import Document, Request, QueryLang, NdArray
from jina.types.score import NamedScore
from jina.types.arrays import ChunkArray
from jina.types.arrays.match import MatchArray


@pytest.mark.parametrize(
    'obj',
    [
        Document(),
        Request(),
        QueryLang(),
        NamedScore(),
        NdArray(),
        MatchArray([Document()], Document()),
        ChunkArray([Document()], Document()),
    ],
)
def test_builtin_str_repr_no_content(obj):
    print(obj)
    print(f'{obj!r}')


@pytest.mark.parametrize(
    'obj',
    [
        Document(content='123', chunks=[Document(content='abc')]),
        QueryLang({
            'name': 'FilterQL',