# Buggy code
def query(
    self, keys: "np.ndarray", top_k: int, *args, **kwargs
) -> Tuple["np.ndarray", "np.ndarray"]:
    """Find the top-k vectors with smallest ``metric`` and return their ids in ascending order.

    :return: a tuple of two ndarray.
        The first is ids in shape B x K (`dtype=int`), the second is metric in shape B x K (`dtype=float`)

    .. warning::
        This operation is memory-consuming.

        Distance (the smaller the better) is returned, not the score.

    """
    if self.metric not in {"cosine", "euclidean"} or self.backend == "scipy":
        dist = self._cdist(keys, self.query_handler)
    elif self.metric == "euclidean":
        _keys = _ext_A(keys)
        dist = self._euclidean(_keys, self.query_handler)
    elif self.metric == "cosine":
        _keys = _ext_A(_norm(keys))
        dist = self._cosine(_keys, self.query_handler)
    else:
        raise NotImplementedError(f"{self.metric} is not implemented")

    idx, dist = self._get_sorted_top_k(dist, top_k)
    return self.int2ext_id[idx], dist


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/peapods/pea.py", line 292, in msg_callback
self.zmqlet.send_message(self._callback(msg))
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/peapods/pea.py", line 266, in _callback
self.pre_hook(msg).handle(msg).post_hook(msg)
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/peapods/pea.py", line 160, in handle
self.executor(self.request_type)
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/executors/__init__.py", line 570, in __call__
d()
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/drivers/__init__.py", line 251, in __call__
self._traverse_apply(self.req.docs, *args, **kwargs)
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/drivers/__init__.py", line 268, in _traverse_apply
**kwargs,
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/drivers/__init__.py", line 281, in _traverse_rec
doc.chunks, doc, 'chunks', path[1:], *args, **kwargs
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/drivers/__init__.py", line 284, in _traverse_rec
self._apply_all(docs, parent_doc, parent_edge_type, *args, **kwargs)
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/drivers/search.py", line 124, in _apply_all
idx, dist = self.exec_fn(embed_vecs, top_k=int(self.top_k))
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/executors/indexers/vector.py", line 279, in query
dist = self._euclidean(_keys, self.query_handler)
File "/home/cristian/envs/lyrics/lib/python3.7/site-packages/jina/executors/decorators.py", line 241, in arg_wrapper
for b in batch_iterator(data[:total_size], b_size, split_over_axis, yield_slice=yield_slice):
TypeError: 'NoneType' object is not subscriptable

# Fixed code
def query(
    self, keys: "np.ndarray", top_k: int, *args, **kwargs
) -> Tuple[Optional["np.ndarray"], Optional["np.ndarray"]]:
    """Find the top-k vectors with smallest ``metric`` and return their ids in ascending order.

    :return: a tuple of two ndarray.
        The first is ids in shape B x K (`dtype=int`), the second is metric in shape B x K (`dtype=float`)

    .. warning::
        This operation is memory-consuming.

        Distance (the smaller the better) is returned, not the score.

    """
    if self.size == 0:
        return None, None
    if self.metric not in {"cosine", "euclidean"} or self.backend == "scipy":
        dist = self._cdist(keys, self.query_handler)
    elif self.metric == "euclidean":
        _keys = _ext_A(keys)
        dist = self._euclidean(_keys, self.query_handler)
    elif self.metric == "cosine":
        _keys = _ext_A(_norm(keys))
        dist = self._cosine(_keys, self.query_handler)
    else:
        raise NotImplementedError(f"{self.metric} is not implemented")

    idx, dist = self._get_sorted_top_k(dist, top_k)
    return self.int2ext_id[idx], dist