def hvicollection(request, connect, dim): collection_name = fake.collection_name() collection_param = { "fields": [ { "name": Field_Integer, "type": DataType.INT64 }, { "name": Field_Vector, "type": DataType.FLOAT_VECTOR, "params": { "dim": dim } }, ], "segment_row_limit": 100000, "auto_id": False } connect.create_collection(collection_name, collection_param) def teardown(): table_names = connect.list_collections() for name in table_names: connect.drop_collection(name) request.addfinalizer(teardown) return collection_name
def test_false_insert(self, gcon): param = { 'collection_name': fake.collection_name(), 'records': records_factory(dim, nq) } res, ids = gcon.insert(**param) assert not res.OK()
def test_insert_scalar_with_id(self, scalar, vec, connect, dim): collection_name = fake.collection_name() collection_param = { "fields": [ {"name": "scalar", "type": scalar}, {"name": "Vec", "type": vec, "params": {"dim": 128}} ], "auto_id": False } try: connect.create_collection(collection_name, collection_param) except Exception as e: pytest.fail(f"Create collection {collection_name} fail: {e}") if scalar in (DataType.INT32, DataType.INT64): scalars = [random.randint(0, 10000) for _ in range(10000)] else: scalars = [random.random() for _ in range(10000)] if vec in (DataType.FLOAT_VECTOR,): vectors = records_factory(dim, 10000) else: vectors = binary_records_factory(dim, 10000) entities = [{"Vec": vector, "scalar": s} for vector, s in zip(vectors, scalars)] for i, e in enumerate(entities): e["_id"] = i try: connect.insert(collection_name, entities) except Exception as e: pytest.fail(f"Unexpected Insert Error: {e}") finally: connect.drop_collection(collection_name)
def test_false_vector(self, gcon): search_param = {"nprobe": 10} param = { 'collection_name': fake.collection_name(), 'query_records': records_factory(dim, nq), 'top_k': 'string', 'params': search_param } with pytest.raises(ParamError): gcon.search(**param) param = { 'collection_name': fake.collection_name(), 'query_records': records_factory(dim, nq), 'top_k': 'string', 'params': search_param } with pytest.raises(ParamError): gcon.search(**param)
def test_has_collection(self, gcon, gcollection): collection_name = fake.collection_name() status, result = gcon.has_collection(collection_name) assert status.OK(), status.message assert not result result = gcon.has_collection(gcollection) assert result with pytest.raises(Exception): gcon.has_collection(1111)
def gcollection(request, gcon): table_name = fake.collection_name() dim = getattr(request.module, "dim", 128) param = {'collection_name': table_name, 'dimension': dim, 'index_file_size': 1024, 'metric_type': MetricType.L2 } gcon.create_collection(param) gcon.flush([table_name]) def teardown(): status, table_names = gcon.list_collections() for name in table_names: gcon.drop_collection(name) request.addfinalizer(teardown) return table_name
def test_insert_async_with_collection_non_exist(self, connect): collection_name = fake.collection_name() with pytest.raises(BaseError): connect.insert(collection_name, {"A": 1, "V": [1]}, _async=True)
def test_insert_with_collection_non_exist(self, connect): collection_name = fake.collection_name() with pytest.raises(CollectionNotExistException): connect.insert(collection_name, [{"A": 1, "V": [1]}])
def test_collection_schema(self): res = Prepare.table_schema(fake.collection_name(), random.randint(0, 999), 1024, MetricType.L2, {}) assert isinstance(res, milvus_pb2.TableSchema)
def test_false_decribe_collection(self, gcon): collection_name = fake.collection_name() res, collection_schema = gcon.describe_collection(collection_name) assert not res.OK() assert not collection_schema