(self)
| 547 | assert py_doc.vector("text")[i] == text_vector[i] |
| 548 | |
| 549 | def test_with_sparse_vector_fields(self): |
| 550 | schema = CollectionSchema( |
| 551 | name="test_collection", |
| 552 | vectors=[ |
| 553 | VectorSchema( |
| 554 | name="author", |
| 555 | data_type=DataType.SPARSE_VECTOR_FP32, |
| 556 | ), |
| 557 | VectorSchema( |
| 558 | name="content", |
| 559 | data_type=DataType.SPARSE_VECTOR_FP16, |
| 560 | ), |
| 561 | ], |
| 562 | ) |
| 563 | |
| 564 | doc = _Doc() |
| 565 | doc.set_pk("1") |
| 566 | doc.set_any( |
| 567 | "author", schema.vector("author")._get_object(), {1: 1.1, 2: 2.2, 3: 3.3} |
| 568 | ) |
| 569 | doc.set_any( |
| 570 | "content", schema.vector("content")._get_object(), {4: 4.4, 5: 5.5, 6: 6.6} |
| 571 | ) |
| 572 | |
| 573 | py_doc = convert_to_py_doc(doc, schema) |
| 574 | assert py_doc.id == "1" |
| 575 | |
| 576 | author_vector = py_doc.vector("author") |
| 577 | assert isinstance(author_vector, dict) |
| 578 | for key, value in doc.get_any("author", DataType.SPARSE_VECTOR_FP32).items(): |
| 579 | assert math.isclose(author_vector[key], value, rel_tol=1e-1) |
| 580 | |
| 581 | content_vector = py_doc.vector("content") |
| 582 | assert isinstance(content_vector, dict) |
| 583 | for key, value in doc.get_any("content", DataType.SPARSE_VECTOR_FP16).items(): |
| 584 | assert math.isclose(content_vector[key], value, rel_tol=1e-1) |
nothing calls this directly
no test coverage detected