async def adelete_ref_doc(self, ref_doc_id: str, raise_error: bool = True) -> None:
        """Delete a ref_doc and all it's associated nodes."""
        ref_doc_info = await self.aget_ref_doc_info(ref_doc_id)
        if ref_doc_info is None:
            if raise_error:
                raise ValueError(f"ref_doc_id {ref_doc_id} not found.")
            else:
                return

        original_node_ids = (
            ref_doc_info.node_ids.copy()
        )  # copy to avoid mutation during iteration
        for doc_id in original_node_ids:
            await self.adelete_document(doc_id, raise_error=False)

        # Deleting all the nodes should already delete the ref_doc, but just to be sure
        await asyncio.gather(
            self._kvstore.adelete(ref_doc_id, collection=self._ref_doc_collection),
            self._kvstore.adelete(ref_doc_id, collection=self._metadata_collection),
            self._kvstore.adelete(ref_doc_id, collection=self._node_collection),
        )
Delete a ref_doc and all it's associated nodes.
llama-index-core/llama_index/core/storage/docstore/keyval_docstore.py