> For the complete documentation index, see [llms.txt](https://docs.cherryai.com.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cherryai.com.cn/docs/zhong-wen-fan-ti/knowledge-base/data.md).

# 知識庫數據

本頁面係俾想了解知識庫底層運作機制嘅用戶睇嘅。若果只係需要使用知識庫，可直接參考 [知識庫教程](/docs/zhong-wen-fan-ti/knowledge-base/knowledge-base.md)。

## 核心原理

加入知識庫嘅文件會被**切分成細片段 → 由嵌入模型轉做數字向量 → 存入本地資料庫**。提問嗰陣，知識庫會將問題轉換做同類向量，檢索最相似嘅片段，並將呢啲片段提供俾對話模型作為上下文。

<figure><img src="/files/9abecae474099aac5371e04bd1ea1d0d4bd1fa04" alt=""><figcaption><p>知識庫處理流程圖</p></figcaption></figure>

## 再詳細啲

1. **入庫前嘅準備**
   * 文件（PDF、Word、網頁等）先經過 [文件預處理](/docs/zhong-wen-fan-ti/knowledge-base/document-preprocessing.md)（OCR 等），變成純文字
   * 純文字會被切成 200-500 字左右嘅細片段（chunk），方便檢索
2. **嵌入與儲存**
   * 每個片段交俾 [嵌入模型](/docs/zhong-wen-fan-ti/knowledge-base/emb-models-info.md) 處理，得到一組數字（向量）
   * 呢啲數字 + 原文片段都存喺 Cherry Studio 本地嘅資料庫入面（基於開源嘅 libSQL）
3. **查詢**
   * 你提問嘅時候，問題文字同樣會被嵌入模型轉成數字
   * 系統搵出「同問題數字最似」嘅若干片段
   * 呢啲片段連同問題一齊送俾對話模型，由佢生成最終答案

## 數據儲存位置

**所有數據都保存在本地**，唔會上傳到雲端（如果所用嘅嵌入模型本身係雲服務，文字片段會喺嵌入處理過程中短暫經過該服務）。

* **macOS**：`~/Library/Application Support/CherryStudio`
* **Windows**：`%APPDATA%\CherryStudio`
* **Linux**：`~/.config/CherryStudio`

## 數據私隱建議

如果資料涉及敏感資訊（合約、醫療、內部代碼等）：

* 使用**本地嵌入模型**（例如透過 [Ollama](/docs/zhong-wen-fan-ti/pre-basic/providers/ollama.md) 或者 [LM Studio](/docs/zhong-wen-fan-ti/pre-basic/providers/lm-studio.md) 運行 `bge-m3`），全流程離線
* 對話模型同樣建議揀本地部署
* 可以配合 [修改儲存位置](/docs/zhong-wen-fan-ti/pre-basic/personalization-settings/storage.md) 將數據存放喺加密磁碟

## 延伸閱讀

* 向量資料庫（libSQL / Turso）：<https://turso.tech/libsql>
* 嵌入與檢索增強生成：可查閱「vector embedding」、「RAG」相關資料

***

### 💡 獲取幫助同提交反饋

如果您喺配置或使用過程中遇到任何疑問、Bug 或有功能改進建議，請參考 [反饋同建議](/docs/zhong-wen-fan-ti/question-contact/suggestions.md) 入面提供嘅官方渠道。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.cherryai.com.cn/docs/zhong-wen-fan-ti/knowledge-base/data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
