def test_matches_sort_by_document_interface_not_in_proto(): docs = [Document(embedding=np.array([1] * (10 - i))) for i in range(10)] query = Document() query.matches = docs assert len(query.matches) == 10 assert query.matches[0].embedding.shape == (10,) query.matches.sort(key=lambda m: m.embedding.shape[0]) assert query.matches[0].embedding.shape == (1,)
def test_matches_sort_by_document_interface_in_proto(): docs = [Document(weight=(10 - i)) for i in range(10)] query = Document() query.matches = docs assert len(query.matches) == 10 assert query.matches[0].weight == 10 query.matches.sort(key=lambda m: m.weight) assert query.matches[0].weight == 1
def test_query_match_array_sort_scores(): query = Document() query.matches = [ Document(id=i, copy=True, scores={'euclid': 10 - i}) for i in range(10) ] assert query.matches[0].id == '0' assert query.matches[0].scores['euclid'].value == 10 query.matches.sort( key=lambda m: m.scores['euclid'].value) # sort matches by their values assert query.matches[0].id == '9' assert query.matches[0].scores['euclid'].value == 1
def test_doc_match_score_assign(): d = Document(id='hello') d1 = Document(d, copy=True, score=123) d.matches = [d1] assert d.matches[0].score.value == 123