Step 5: Cleanup (optional)
In this section we will learn about some of Ragie's utility APIs to remove our tutorial documents
In our tutorial we created several documents, but we should remove them so they don't clutter your index.
Here is an example script that we can use to delete all of the created in this tutorial.
import { Ragie } from "ragie";
const apiKey = "<YOUR API KEY>";
const ragie = new Ragie({
auth: apiKey
});
(async () => {
while (true) {
try {
const response = await ragie.documents.list({
filter: `{"scope": "tutorial"}`
});
const documents = response.result.documents;
for (const document of documents) {
try {
await ragie.documents.delete({
documentId: document.id
});
console.log(`Deleted document ${document.id}`);
} catch (error) {
console.error(`Failed to delete document ${document.id}:`, error);
throw error;
}
}
if (!response.result.pagination.nextCursor) {
console.warn("No more documents\n");
break;
}
} catch (error) {
console.error("Failed to retrieve or process documents:", error);
throw error;
}
}
})();
This script cleans up the documents that we created in this tutorial. It uses the list document API to iterate through a filtered list of the documents in your Ragie instance using the next_cursor
parameter for pagination. For each document that is listed, the document is deleted.
There are more utility APIs that help you manage your documents in Ragie. Be sure to check out the API Reference for a complete list of all of the rest APIs that Ragie supports.
Updated 13 days ago