> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reportify.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 知识库

> TypeScript SDK 知识库模块 - 搜索用户上传的私有文档

## 概述

知识库模块用于搜索用户上传到 Reportify 的私有文档，支持按文件夹筛选。

## search()

在知识库中搜索文档。

```typescript theme={null}
const results = await client.kb.search('投资策略', {
  folderIds: ['folder_abc123'],
  num: 10
});

results.forEach(chunk => {
  console.log(chunk.content.slice(0, 100));
});
```

**参数：**

| 参数                  | 类型         | 必填 | 默认值  | 说明                   |
| ------------------- | ---------- | -- | ---- | -------------------- |
| `query`             | `string`   | 是  | -    | 搜索关键词                |
| `options.folderIds` | `string[]` | 否  | -    | 文件夹 ID 列表，不传则搜索全部文件夹 |
| `options.docIds`    | `string[]` | 否  | -    | 文档 ID 列表，限定搜索范围      |
| `options.startDate` | `string`   | 否  | -    | 开始日期过滤（YYYY-MM-DD）   |
| `options.endDate`   | `string`   | 否  | -    | 结束日期过滤（YYYY-MM-DD）   |
| `options.num`       | `number`   | 否  | `10` | 返回结果数量               |

**返回值：** `Promise<Chunk[]>` - 搜索结果列表（内容块）

***

## 类型定义

```typescript theme={null}
interface KBSearchResult {
  docId: string;
  title: string;
  content: string;
  score: number;
  folderId: string;
  folderName: string;
  createdAt: number;
}
```

## 使用场景

```typescript theme={null}
// 搜索特定文件夹的文档
const results = await client.kb.search('季度报告', {
  folderIds: ['folder_quarterly_reports']
});

// 搜索所有知识库文档
const allResults = await client.kb.search('财务分析');

// 结合文档搜索和知识库搜索
const [publicDocs, privateDocs] = await Promise.all([
  client.search.all('Tesla analysis'),
  client.kb.search('Tesla analysis')
]);

console.log(`公开文档: ${publicDocs.length} 条`);
console.log(`私有文档: ${privateDocs.length} 条`);
```
