跳至主要内容

Documents API

上傳文件

POST /v1/documents

使用 multipart/form-data 上傳文件。

POST /v1/documents
Authorization: Bearer sk-your-api-key
Content-Type: multipart/form-data

Form Fields:

欄位類型必填說明
filefile文件二進位內容
filenamestring文件名稱(含副檔名)
chunk_strategystring切分策略,預設 recursive
chunk_sizenumber每個段落最大字元數
chunk_overlapnumber相鄰段落重疊字元數
metadatastring (JSON)自訂 metadata(JSON 字串)

回應:

{
"success": true,
"data": {
"id": "doc-uuid",
"filename": "manual.pdf",
"status": "processing",
"chunk_strategy": "recursive",
"created_at": "2026-05-08T12:00:00Z"
}
}

列出文件

GET /v1/documents

查詢參數:

參數類型說明
searchstring按文件名稱搜尋
statusstring篩選狀態:processing / ready / failed / inactive
pagenumber頁碼,預設 1
page_sizenumber每頁筆數,預設 20

取得文件詳情

GET /v1/documents/{id}


刪除文件

DELETE /v1/documents/{id}

刪除後無法復原,向量資料與原始檔案都會一起移除。


停用文件

PATCH /v1/documents/{id}/deactivate

文件從 RAG 索引中移除,但檔案保留。


啟用文件

PATCH /v1/documents/{id}/activate

重新將文件加入 RAG 索引(會重新排入 Embedding 佇列)。


更新切分設定

PATCH /v1/documents/{id}/chunking

{
"chunk_strategy": "semantic",
"chunk_size": 1000,
"chunk_overlap": 100,
"chunk_semantic_threshold": 0.75
}

可更新的欄位:

欄位類型說明
chunk_strategystringrecursive / fixed / semantic / sentence / parent_child / llm
chunk_sizenumber段落最大字元數
chunk_overlapnumber重疊字元數
chunk_semantic_thresholdnumberSemantic 策略的切分門檻(0.0 – 1.0)

重新索引

POST /v1/documents/{id}/reindex

觸發重新切分和向量化,通常在更新切分設定後使用。


查看段落

GET /v1/documents/{id}/chunks

查詢參數:

參數類型說明
pagenumber頁碼
page_sizenumber每頁筆數

回應:

{
"success": true,
"data": {
"chunks": [
{
"id": "chunk-uuid",
"index": 0,
"content": "第一章:產品概述...",
"token_count": 128
}
],
"total": 42
}
}

下載原始檔案

GET /v1/documents/{id}/download

回傳原始二進位檔案,Content-Type 為原始文件格式。


下載 Markdown 版本

GET /v1/documents/{id}/download/markdown

回傳文件解析後的 Markdown 文字,方便檢查文字擷取的結果。


所需權限

操作所需權限
讀取文件列表和詳情source.read
上傳、管理、刪除文件source.write