def test_ndarray_to_proto_numpy(): X = np.array([1, 2, 3], dtype="float32") proto = serializers.ndarray_to_proto(X) assert proto.shape == [3] assert proto.dtype == tensors_pb2.NDArray.FLOAT32 assert proto.numpy_content == X.tobytes() proto = serializers.ndarray_to_proto(X, dtype="float64") assert proto.dtype == tensors_pb2.NDArray.FLOAT64
def test_proto_to_ndarray_numpy(X): proto = serializers.ndarray_to_proto(X) X_prime = serializers.proto_to_ndarray(proto) assert np.array_equal(X, X_prime)
def test_ndarray_to_proto_unsupported_input(X, dtype, shape, error): with pytest.raises(ValueError) as excinfo: serializers.ndarray_to_proto(X, dtype=dtype, shape=shape) assert error in str(excinfo.value)
def test_ndarray_to_proto_list(): X = [1, 2, 3] proto = serializers.ndarray_to_proto(X, dtype="int8", shape=(3, )) assert proto.shape == [3] assert proto.dtype == tensors_pb2.NDArray.INT8 assert proto.numpy_content is not None
def retrieve(self, id: str) -> indices_pb2.RetrievalResultItem: vector, metadata = self.get_vector_and_metadata(id) vector_proto = None if vector is None else serializers.ndarray_to_proto( vector) return indices_pb2.RetrievalResultItem(vector=vector_proto, metadata=metadata)