# 14.1 项目需求与架构设计

在开始编码之前，清晰的需求分析和稳健的架构设计是成功的关键。

## 14.1.1 需求分析

### 核心功能需求

* **多源数据接入**：支持导入 PDF、Markdown、Word 等格式的企业文档。
* **精准问答**：基于知识库回答用户提问，回答需标注引用来源。
* **多轮对话**：支持基于上下文的追问，理解指代关系（如“它”、“这个”）。
* **拒识能力**：对于知识库中不存在的问题，应明确告知“未找到相关信息”，避免幻觉。

### 非功能需求

* **响应速度**：首字生成延迟 < 1 秒，完整回答 < 5 秒。
* **并发能力**：支持至少 50 QPS 的并发访问。
* **数据安全**：确保企业敏感数据不泄露，支持私有化部署模型。

*注：以上性能指标为示例目标，实际 SLO 需结合模型部署形态（本地/云）、检索链路、缓存策略与业务负载压测结果确定。*

## 14.1.2 技术选型

| 组件                | 选型                         | 理由             |
| ----------------- | -------------------------- | -------------- |
| **LLM**           | 具备工具调用与长上下文能力的通用模型         | 结合预算与延迟要求选型    |
| **Embedding**     | 多语言/领域嵌入模型                 | 结合语料与评测集选型     |
| **Vector DB**     | 专用向量数据库或带向量扩展的数据库          | 结合规模、运维与成本选型   |
| **Orchestration** | RAG/Agent 编排框架             | 组件化构建检索与上下文组装  |
| **Backend**       | Web 后端框架（如 Python/Node/Go） | 便于接入鉴权、审计与可观测性 |

## 14.1.3 系统架构设计

系统整体采用典型的 RAG（检索增强生成）架构，分为 **离线处理链路** 和 **在线服务链路**。

### 架构图

{% @mermaid/diagram content="graph TB
subgraph "离线处理 (Offline Pipeline)"
D\[原始文档] --> P\["文档解析 (Parser)"]
P --> C\["分块 (Chunking)"]
C --> E\["向量化 (Embedding)"]
E --> V\[(向量数据库)]
end

```
subgraph "在线服务 (Online Service)"
    U[用户提问] --> Q["查询重写 (Query Rewrite)"]
    Q --> R["混合检索 (Hybrid Search)"]
    V --> R
    R --> RK["重排序 (Rerank)"]
    RK --> G["上下文组装 (Prompt)"]
    His[对话历史] --> G
    G --> L[LLM 生成]
    L --> Ans[最终回答]
end" %}
```

图 14-1：RAG 系统架构设计

### 模块职责

1. **数据层**：负责文档的 ETL（Extract, Transform, Load）。
2. **检索层**：负责根据语义和关键词召回相关片段，并进行精排。
3. **认知层**：负责对话状态管理、Prompt 组装和 LLM 推理。
4. **接口层**：提供标准 API 供前端或第三方系统调用。


---

# 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://yeasy.gitbook.io/context_engineering_guide/di-si-bu-fen-gong-cheng-shi-zhan-yu-wei-lai-yan-jin/14_practice/14.1_requirements.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.
