Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Azure AI Search Index delete #17539

Open
1 task done
krupalsmart97 opened this issue Jan 17, 2025 · 7 comments
Open
1 task done

[Question]: Azure AI Search Index delete #17539

krupalsmart97 opened this issue Jan 17, 2025 · 7 comments
Labels
question Further information is requested

Comments

@krupalsmart97
Copy link

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

Hey,
I am trying to delete the Azure AI Search index that I created using the Lama index. I reviewed the documentation but could not find any reference for it.

Can you help me with it by pointing me in the right direction or documentation?

Thanks in advance

@krupalsmart97 krupalsmart97 added the question Further information is requested label Jan 17, 2025
Copy link

dosubot bot commented Jan 17, 2025

Hey, @krupalsmart97! 👋 I'm here to help you with bugs, questions, or becoming a contributor. Let's squash those bugs together!

To delete an Azure AI Search index using the LlamaIndex framework, you can use the delete or adelete methods. Here's how you can do it:

  1. Synchronous Deletion: Use the delete method to delete documents from the AI Search Index by specifying the ref_doc_id:

    def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
        if not self._index_exists(self._index_name):
            return
    
        filter = f'{self._field_mapping["doc_id"]} eq \'{ref_doc_id}\''
        batch_size = 1000
    
        while True:
            results = self._search_client.search(
                search_text="*",
                filter=filter,
                top=batch_size,
            )
    
            docs_to_delete = [
                {"id": result[self._field_mapping["id"]]} for result in results
            ]
    
            if docs_to_delete:
                self._search_client.delete_documents(docs_to_delete)
            else:
                break
  2. Asynchronous Deletion: Use the adelete method for asynchronous deletion:

    async def adelete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
        if not await self._aindex_exists(self._index_name):
            return
    
        filter = f'{self._field_mapping["doc_id"]} eq \'{ref_doc_id}\''
        batch_size = 1000
    
        while True:
            results = await self._async_search_client.search(
                search_text="*",
                filter=filter,
                top=batch_size,
            )
    
            docs_to_delete = [
                {"id": result[self._field_mapping["id"]]} async for result in results
            ]
    
            if docs_to_delete:
                await self._async_search_client.delete_documents(docs_to_delete)
            else:
                break

These methods locate documents to delete using a filter based on the ref_doc_id and delete them in batches [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@krupalsmart97
Copy link
Author

@dosu , so I know that I can delete a document indexed inside an index but my question is how to delete the entire index not just one document

Copy link

dosubot bot commented Jan 17, 2025

Could you provide more details about the tools or SDKs you're using to interact with Azure AI Search? This will help me guide you on how to delete the entire index.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@krupalsmart97
Copy link
Author

@dosu I am using the llama index for interaction

Copy link

dosubot bot commented Jan 17, 2025

The LlamaIndex framework does not explicitly provide a method to delete an entire Azure AI Search index. However, you can manage Azure AI Search indexes using the Azure SDK for Python, which provides the necessary functionality to delete an entire index.

Here's a basic example of how you can delete an Azure AI Search index using the Azure SDK:

from azure.search.documents.indexes import SearchIndexClient
from azure.core.credentials import AzureKeyCredential

# Replace with your Azure Search service details
endpoint = "https://<your-service-name>.search.windows.net"
admin_key = "<your-admin-key>"
index_name = "<your-index-name>"

# Create a client
client = SearchIndexClient(endpoint=endpoint, credential=AzureKeyCredential(admin_key))

# Delete the index
client.delete_index(index_name)

Make sure to replace <your-service-name>, <your-admin-key>, and <your-index-name> with your actual Azure Search service name, admin key, and the name of the index you want to delete. This approach uses the Azure SDK directly to manage the index lifecycle.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@krupalsmart97
Copy link
Author

@dosu, thanks for the answer, will try this approach.

Copy link

dosubot bot commented Jan 17, 2025

You're welcome! If you run into any issues or have further questions while trying this approach, feel free to reach out. Good luck!

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant