Open Sheth-G opened 10 months ago
torvalds.dev is analyzing the ticket
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, preventing the program from crashing unexpectedly.
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,
)
As you can see, there are currently no try-catch blocks in this method. If an error occurs during the deletion process (for example, if the ref_doc_id
does not exist in the index), the program will crash.
To address this issue, we can add a try-catch block around the deletion operation. If an error occurs, we can log the error message and optionally re-raise the error to be handled by the calling code.
Here is a proposed modification to 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.
"""
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 document with id {ref_doc_id}: {str(e)}")
raise
In this modification, if the deletion operation fails, the error message is logged and the error is re-raised. This allows the calling code to handle the error in a way that is appropriate for the specific context in which the delete
method is being used.
Add try catch blocks to pinecone index deletion