I find it useful and have implemented in my daily life. How to delete the prevailing data?
Do anyone have any idea on the subject? DOCUMENTATION This Contains some insight but seems to get an error.
def list_documents(store_name):
print("\\n Listing documents in store...")
try:
pager = client.file_search_stores.documents.list(
parent=store_name
)
except Exception as e:
print(f"Error listing documents: {e}")
return \[\]
docs = \[\]
for doc in pager:
print(" -", doc.name)
docs.append(doc.name)
if not docs:
print(" No documents found.")
return docs
**
this seems to return the files as a list.**
def list_and_delete_documents(store_name):
print("\\n This will DELETE ALL documents in the store.")
print("This cannot be undone.")
confirm = input("Type 'YES' to continue: ")
if confirm.strip().upper() != "YES":
print(" Delete cancelled.")
return
print("\\n Fetching documents...")
try:
pager = client.file_search_stores.documents.list(
parent=store_name
)
except Exception as e:
print(f" Error listing documents: {e}")
return
docs = \[\]
for doc in pager:
docs.append(doc.name)
if not docs:
print(" No documents found.")
return
print("\\n Deleting documents:\\n")
for doc_name in docs:
try:
client.file_search_stores.documents.delete(
name=doc_name,
force=True
)
print(f" Deleted: {doc_name}")
except Exception as e:
print(f" Failed to delete {doc_name}: {e}")
print("\\n Deleted successfully!")
Can you define more clearly what your intentions behind the phrase āprevailing contentsā are?
Do you mean: keep the ID, but remove all contents?
It would seem easier just to delete the fileSearchStore entirely, and use the āforceā query parameter to remove any document artifacts if not empty.
The API itself has no DELETE method specifically for multiple documents in a store. This would have to be an SDK helper that iterates through a list (like your loop).
The asterisks in the query is a confusion layer for what actually goes in āname=ā - fileSearchStores/{filesearchstore}/documents/{document}
However, you will note that any call to clear a single listed document needs both the store ID and the document. The SDK method you show I can already tell will fail without even looking, because you arenāt passing both of these, and that is not a path which takes a āforceā.
The file_search_stores Python āmethodsā you show, which might be inferred as existing from the camelcase āmethodā in API docs, would need a recent update of the Google API SDKs that would have such support, instead of the ease of just directly making https API calls. āerror occursā - you can read the error, and see if there is even such a delete method.
This seems to do the trick. What Iām concerned about is what happens if I ever need to delete a specific file by name, or remove a group of files based on a particular upload time range.
The same place you discovered client.file_search_stores.documents.list() - see if there is API reference for a .documents.delete() that surfaces.
You will have to guess the correct fields for the store name and document name if you are also guessing at the method and like me canāt find documentation (or you can go into the latest messy API SDK code and see what they have provided but not documented).
Otherwise, DELETE is an API method that doesnāt take an encoded body, just send the URL with path and your Bearer authentication header. I documented it above.