# 檢索文件內容

{% openapi src="/files/WF90zszaISusKGEBimez" path="/documents/{document\_id}/contents/" method="get" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

## 範例請求

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET \
  "https://api.rememberizer.ai/api/v1/documents/12345/contents/?start_chunk=0&end_chunk=20" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

{% hint style="info" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並將 `12345` 替換為實際的文件 ID。
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const getDocumentContents = async (documentId, startChunk = 0, endChunk = 20) => {
  const url = new URL(`https://api.rememberizer.ai/api/v1/documents/${documentId}/contents/`);
  url.searchParams.append('start_chunk', startChunk);
  url.searchParams.append('end_chunk', endChunk);
  
  const response = await fetch(url.toString(), {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_JWT_TOKEN'
    }
  });
  
  const data = await response.json();
  console.log(data);
  
  // 如果還有更多的區塊，您可以獲取它們
  if (data.end_chunk < totalChunks) {
    // 獲取下一組區塊
    await getDocumentContents(documentId, data.end_chunk, data.end_chunk + 20);
  }
};

getDocumentContents(12345);
```

{% hint style="info" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並將 `12345` 替換為實際的文件 ID。
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests

def get_document_contents(document_id, start_chunk=0, end_chunk=20):
    headers = {
        "Authorization": "Bearer YOUR_JWT_TOKEN"
    }
    
    params = {
        "start_chunk": start_chunk,
        "end_chunk": end_chunk
    }
    
    response = requests.get(
        f"https://api.rememberizer.ai/api/v1/documents/{document_id}/contents/",
        headers=headers,
        params=params
    )
    
    data = response.json()
    print(data)
    
    # 如果還有更多的區塊，您可以獲取它們
    # 這是一個簡單的範例 - 您可能想要實現一個適當的遞迴檢查
    if 'end_chunk' in data and data['end_chunk'] < total_chunks:
        get_document_contents(document_id, data['end_chunk'], data['end_chunk'] + 20)

get_document_contents(12345)
```

{% hint style="info" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並將 `12345` 替換為實際的文件 ID。
{% endhint %}
{% endtab %}
{% endtabs %}

## 路徑參數

| 參數           | 類型 | 描述                   |
| ------------ | -- | -------------------- |
| document\_id | 整數 | **必填。** 要檢索內容的文件 ID。 |

## 查詢參數

| 參數           | 類型 | 描述                            |
| ------------ | -- | ----------------------------- |
| start\_chunk | 整數 | 起始區塊索引。預設為 0。                 |
| end\_chunk   | 整數 | 結束區塊索引。預設為 start\_chunk + 20。 |

## 回應格式

```json
{
  "content": "文件片段的完整文本內容...",
  "end_chunk": 20
}
```

## 錯誤回應

| 狀態碼 | 描述      |
| --- | ------- |
| 404 | 文件未找到   |
| 500 | 內部伺服器錯誤 |

## 大型文件的分頁

對於大型文件，內容被拆分成多個區塊。您可以通過多次請求來檢索完整文件：

1. 先發送一個請求，設置 `start_chunk=0`
2. 使用返回的 `end_chunk` 值作為下一個請求的 `start_chunk`
3. 繼續進行，直到檢索到所有區塊

此端點返回文件的原始文本內容，允許您訪問完整信息以進行詳細處理或分析。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rememberizer.ai/zh-hk/kai-fa-zhe-zi-yuan/api-docs/retrieve-document-contents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
