async def _aremove_from_ref_doc_node(self, doc_id: str) -> None:
        """
        Helper function to remove node doc_id from ref_doc_collection.
        If ref_doc has no more doc_ids, delete it from the collection.
        """
        ref_doc_id, ref_doc_info = await asyncio.gather(
            self._aget_ref_doc_id(doc_id),
            self.aget_ref_doc_info(doc_id),
        )
        if ref_doc_id is None or ref_doc_info is None:
            return

        if doc_id in ref_doc_info.node_ids:  # sanity check
            ref_doc_info.node_ids.remove(doc_id)
        # delete ref_doc from collection if it has no more doc_ids
        if len(ref_doc_info.node_ids) > 0:
            await self._kvstore.aput(
                ref_doc_id,
                ref_doc_info.to_dict(),
                collection=self._ref_doc_collection,
            )
        else:
            await asyncio.gather(
                self._kvstore.adelete(ref_doc_id, collection=self._metadata_collection),
                self._kvstore.adelete(ref_doc_id, collection=self._node_collection),
                self._kvstore.adelete(ref_doc_id, collection=self._ref_doc_collection),
            )

        Helper function to remove node doc_id from ref_doc_collection.
        If ref_doc has no more doc_ids, delete it from the collection.
        
llama-index-core/llama_index/core/storage/docstore/keyval_docstore.py