> ## Documentation Index
> Fetch the complete documentation index at: https://www.sapientpriors.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Remove a document

> Delete an uploaded file, its extracted pictures, and every memory learned from it

## Example use case

You retire an older product line on the inbound support line and must remove its manual, or a prospect asks you to delete a confidential proposal uploaded to their sales agent.

## Setup

Call [DELETE`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file) as the agent's owner:

* **Immediate removal:** before returning `202`, Priors deletes the file bytes, any extracted pictures cut from it, and its upload ledger rows.
* **Background memory cleanup:** Priors starts a job that erases the file's pieces and forgets every memory from turns citing the file.
* **Verify completion:** poll the returned `Location` header ([GET`/v2/agents/{agent_id}/memories?file_id={file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories)) until every listed turn reaches `forgotten`.

## Benefit with Priors

* **One-call cleanup:** removes original file bytes, extracted figures, upload metadata, and learned memories together.
* **Safe across large documents:** avoids looping through thousands of individual file pieces (and [DELETE`.../memories/{turn_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/forget-a-memory) deliberately directs file pieces here).

## What goes wrong

> [!WARNING]
>
> [DELETE`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file) returns `409 conflict` if the file is still learning or waiting in the upload queue, or if you pass the `file_id` of an extracted picture instead of the parent document. Memories made from ordinary chat turns that did not cite the file also remain if someone pasted excerpts into conversation.

## Recommendation

Wait until ingestion finishes before deleting a file, always delete using the parent document's `file_id`, and poll the `Location` URL until every citing turn reads `forgotten`. Forget any manual chat excerpts separately if needed.

## Calls used

* Guides: [Files](https://www.sapientpriors.com/docs/concepts/files.md), [Memories](https://www.sapientpriors.com/docs/concepts/memories.md), [Your data](https://www.sapientpriors.com/docs/data.md)
* API reference: [List files](https://www.sapientpriors.com/docs/api-reference/v2/files/list-files.md), [Delete file](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file.md), [List memories](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.