test-app-organization / test-repo-app

MIT License
0 stars 0 forks source link

Add try catch blocks to pinecone index deletion #46

Open Sheth-G opened 7 months ago

Sheth-G commented 7 months ago

Add try catch blocks to pinecone index deletion

torvalds-dev commented 7 months ago

torvalds.dev is analyzing the ticket

torvalds-dev commented 7 months ago

The issue is about adding try-catch blocks to the Pinecone index deletion process. This is to ensure that any errors that occur during the deletion process are properly caught and handled, rather than causing the entire program to crash.

The relevant file for this issue is llama_index/vector_stores/pinecone.py. This file contains the PineconeVectorStore class, which has a delete method. This method is responsible for deleting nodes from the Pinecone index.

Here is the current implementation of the delete method:

def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
    """
    Delete nodes using with ref_doc_id.

    Args:
        ref_doc_id (str): The doc_id of the document to delete.

    """
    # delete by filtering on the doc_id metadata
    self._pinecone_index.delete(
        filter={"doc_id": {"$eq": ref_doc_id}},
        namespace=self.namespace,
        **delete_kwargs,
    )

The delete method currently does not have any error handling. If an error occurs during the deletion process (for example, if the ref_doc_id does not exist in the index), the method will raise an exception and potentially cause the entire program to crash.

To address this issue, we can add a try-catch block around the deletion process. If an error occurs, we can log the error and optionally re-raise the exception or handle it in some other way.

Here is a potential implementation:

def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
    """
    Delete nodes using with ref_doc_id.

    Args:
        ref_doc_id (str): The doc_id of the document to delete.

    """
    try:
        # delete by filtering on the doc_id metadata
        self._pinecone_index.delete(
            filter={"doc_id": {"$eq": ref_doc_id}},
            namespace=self.namespace,
            **delete_kwargs,
        )
    except Exception as e:
        _logger.error(f"Failed to delete node with ref_doc_id {ref_doc_id}: {e}")
        # Optionally, re-raise the exception
        # raise

In this implementation, if an error occurs during the deletion process, the error message will be logged and the program will continue running. If you want the program to stop running when an error occurs, you can uncomment the raise statement to re-raise the exception.