torvalds-dev / llama_index

LlamaIndex (formerly GPT Index) is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
0 stars 0 forks source link

[Question]: Add error statement when pinecone index deletion fails #18

Open torvalds-dev opened 7 months ago

torvalds-dev commented 7 months ago

Question Validation

Question

Add error statement when pinecone index deletion fails

torvalds-dev commented 7 months ago

torvalds.dev is analyzing the ticket

torvalds-dev commented 7 months ago

The task is to add an error statement when the deletion of a Pinecone index fails. The relevant files for this task are:

  1. llama_index/readers/json.py
  2. llama_index/vector_stores/pinecone.py
  3. llama_index/readers/pinecone.py

The deletion of a Pinecone index is handled in the delete method of the PineconeVectorStore class in the llama_index/vector_stores/pinecone.py file. Currently, there is no error handling in this method.

Here is a plan to add the error statement:

  1. In the delete method of the PineconeVectorStore class, add a try-except block around the self._pinecone_index.delete call.
  2. In the except block, log an error message with the details of the exception.
  3. Test the deletion of a non-existent index to ensure the error message is logged correctly.

Here is the code snippet to add the error statement:

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
    try:
        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 index with ref_doc_id {ref_doc_id}. Error: {str(e)}")

This code will log an error message when the deletion of a Pinecone index fails. The error message will include the ref_doc_id of the index that failed to be deleted and the details of the exception.