```python:inference/core/workflows/execution_engine/entities/base.py
from __future__ import annotations

from typing import Generic, List, Optional, Set, Tuple, TypeVar

B = TypeVar("B")


class Batch(Generic[B]):

    def __init__(self, content: List[B], indices: Optional[List[Tuple[int, ...]]]):
        self._content = content
        self._indices = indices

    def remove_by_indices(self, indices_to_remove: Set[tuple]) -> "Batch":
        filtered_content: List[B] = []
        filtered_indices: List[Tuple[int, ...]] = []

        for index, element in zip(self._indices, self._content):
            if index in indices_to_remove:
                continue
            if isinstance(element, Batch):
                filtered_content.append(
                    element.remove_by_indices(indices_to_remove=indices_to_remove)
                )
            else:
                filtered_content.append(element)
            filtered_indices.append(index)

        return Batch(content=filtered_content, indices=filtered_indices)
```