Delete Document

Updated at:

Delete a document and all of its chunks from a Knowledge Base.

Prerequisites

Configure the endpoint and authentication first. See API overview and Authentication.

Endpoint

POST /api/v1/indices/rag/index/delete_file

Delete a document and all of its chunks from a specified knowledge base.

WarningThis operation is irreversible. This endpoint uses snake_case parameters — index_id and doc_ids — unlike the camelCase (indexId) used by other endpoints. Sending IndexId or indexId returns Index.InvalidParameter.

When a parameter is missing, the server returns Required parameter(IndexId) missing or invalid. The IndexId in that message is the server's internal field name, not the request parameter name — still send index_id.

Request body

FieldRequiredTypeDescription
index_idYesstringKnowledge base ID.
doc_idsYesarray<string>List of document IDs to delete.

Request example

curl -X POST "$BASE_URL/api/v1/indices/rag/index/delete_file" \
  -H "Authorization: Bearer $BAILIAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "index_id": "your_index_id",
    "doc_ids": ["file_xxx"]
  }'

BASE_URL is https://{workspace_id}.cn-beijing.maas.aliyuncs.com ({workspace_id} is the workspace ID), and BAILIAN_API_KEY is your Alibaba Cloud Model Studio API key.

Response example

Returns 200 on success.

{
  "code": "Success",
  "status_code": 200,
  "data": {
    "deleted": []
  },
  "success": true,
  "message": "success",
  "request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "SUCCESS"
}

Response fields

FieldTypeDescription
codestringResponse code. Success on success.
status_codeintegerHTTP status code.
request_idstringUnique request identifier. Provide this ID when troubleshooting.
dataobjectBusiness data. Sub-field: deleted (array<string>, list of deleted document IDs).
successbooleanWhether the operation succeeded.
messagestringResponse message. success on success.
statusstringRequest status: SUCCESS or FAILED.

Error codes

HTTP status codeError codeMessageDescription
400Index.InvalidParameterRequired parameter missing or invalid.Invalid request parameters.
401InvalidApiKeyInvalid API-key provided.Authentication failed. The API key is invalid or missing.