> ## 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.

# Search Knowledge Base

> User knowledge base search, supporting all types of user uploaded files and allows searching within specified directories

## 搜索知识库

**URL**: `/v1/tools/kb/search`\
**方法**: `POST`\
**描述**: 搜索用户的私有知识库，包括上传的文档和文件夹。

### 请求参数

| 参数名         | 类型        | 必填 | 描述                |
| ----------- | --------- | -- | ----------------- |
| query       | string    | 是  | 搜索关键词             |
| folder\_ids | string\[] | 否  | 文件夹 ID 列表，筛选特定文件夹 |
| doc\_ids    | string\[] | 否  | 文档 ID 列表，筛选特定文档   |
| start\_date | string    | 否  | 开始日期（YYYY-MM-DD）  |
| end\_date   | string    | 否  | 结束日期（YYYY-MM-DD）  |
| num         | integer   | 否  | 返回结果数量，默认 10      |

### 响应参数

| 参数名            | 类型     | 描述      |
| -------------- | ------ | ------- |
| chunks         | array  | 搜索结果块列表 |
|   chunk\_id    | string | 内容块 ID  |
|   content      | string | 匹配的内容   |
|   score        | number | 相关性得分   |
|   doc\_id      | string | 所属文档 ID |
|   doc\_title   | string | 文档标题    |
|   folder\_id   | string | 文件夹 ID  |
|   folder\_name | string | 文件夹名称   |

### 请求示例

**cURL**

```bash theme={null}
curl -X POST "https://api.reportify.cn/v1/tools/kb/search" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "投资策略",
    "num": 10
  }'
```

**Python**

```python theme={null}
import requests

url = "https://api.reportify.cn/v1/tools/kb/search"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "query": "投资策略",
    "folder_ids": ["folder_abc123"],
    "num": 10
}

response = requests.post(url, headers=headers, json=data)
results = response.json()

for chunk in results["chunks"]:
    print(f"[{chunk['doc_title']}] {chunk['content'][:100]}...")
```

**TypeScript**

```typescript theme={null}
const response = await fetch('https://api.reportify.cn/v1/tools/kb/search', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    query: '投资策略',
    num: 10
  })
});

const data = await response.json();
console.log(`Found ${data.chunks.length} results`);
```

### 响应示例

```json theme={null}
{
  "chunks": [
    {
      "chunk_id": "chunk_abc123",
      "content": "本报告提出的投资策略主要关注价值投资和成长投资的结合...",
      "score": 0.95,
      "doc_id": "doc_xyz789",
      "doc_title": "2024年投资策略报告.pdf",
      "folder_id": "folder_abc123",
      "folder_name": "投资研究"
    }
  ]
}
```

### 错误响应

| 状态码 | 描述       |
| --- | -------- |
| 422 | 请求参数验证失败 |

### 使用场景

1. **搜索私有文档**
   * 在上传的研究报告中搜索特定内容
   * 快速定位相关分析和数据

2. **按时间范围筛选**
   * 搜索特定时间段内的文档内容
   * 追踪历史分析记录

3. **分文件夹搜索**
   * 在特定项目文件夹中搜索
   * 隔离不同研究领域的内容


## OpenAPI

````yaml POST /v1/tools/kb/search
openapi: 3.1.0
info:
  title: Reportify API
  version: 1.0.0
  description: API documentation for Reportify's document management and search services.
servers:
  - url: https://api.reportify.cn
    description: Production server
security:
  - BearerAuth: []
paths:
  /v1/tools/kb/search:
    post:
      tags:
        - openapi-tools-kb
      summary: Search Knowledge Base
      description: >-
        User knowledge base search, supporting all types of user uploaded files
        and allows searching within specified directories
      operationId: search_kb_reportify_api_v1_tools_kb_search_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAIKBSearchRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KBSearchOutput'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    OAIKBSearchRequest:
      properties:
        query:
          type: string
          title: Query
          description: Search query
        folder_ids:
          type: array
          items:
            type: string
          title: Folder Ids
          description: Folder IDs to filter by
        doc_ids:
          type: array
          items:
            type: string
          title: Doc Ids
          description: Document IDs to filter by
        start_date:
          type: string
          title: Start Date
          description: Start date filter (YYYY-MM-DD)
        end_date:
          type: string
          title: End Date
          description: End date filter (YYYY-MM-DD)
        num:
          type: integer
          title: Num
          description: Number of results to return
          default: 10
      type: object
      required:
        - query
      title: OAIKBSearchRequest
      description: Request model for knowledge base search
    KBSearchOutput:
      properties:
        chunks:
          type: array
          items:
            $ref: '#/components/schemas/OAIChunkWithDoc'
          title: Chunks
          description: Search result chunks with document information
          default: []
      type: object
      title: KBSearchOutput
      description: Output model for knowledge base search
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    OAIChunkWithDoc:
      properties:
        id:
          type: string
          title: Id
        type:
          $ref: '#/components/schemas/OAIChunkType'
        media_url:
          type: string
          title: Media Url
        content:
          type: string
          title: Content
        summary:
          type: string
          title: Summary
        metadata:
          type: object
          title: Metadata
        doc:
          anyOf:
            - $ref: '#/components/schemas/OAIDoc'
            - $ref: '#/components/schemas/OAIDocBase'
          title: Doc
      type: object
      title: OAIChunkWithDoc
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    OAIChunkType:
      type: string
      enum:
        - text
        - table
        - image
        - formula
      title: OAIChunkType
      description: An enumeration.
    OAIDoc:
      properties:
        doc_id:
          type: string
          title: Doc Id
        title:
          type: string
          title: Title
        url:
          type: string
          title: Url
        institution:
          type: string
          title: Institution
        author:
          type: string
          title: Author
        published_at:
          type: integer
          title: Published At
        category:
          $ref: '#/components/schemas/OAIDocCategory'
        market:
          $ref: '#/components/schemas/OAIMarket'
        ticker:
          type: string
          title: Ticker
        symbol:
          type: string
          title: Symbol
        company_name:
          type: string
          title: Company Name
        logo:
          type: string
          title: Logo
        companies:
          items:
            $ref: '#/components/schemas/CompanyLabel'
          type: array
          title: Companies
        tags:
          additionalProperties:
            items: {}
            type: array
          type: object
          title: Tags
        metadatas:
          additionalProperties:
            items: {}
            type: array
          type: object
          title: Metadatas
        report_type:
          type: integer
          title: Report Type
        channel_id:
          type: string
          title: Channel Id
        channel_name:
          type: string
          title: Channel Name
        summary:
          type: string
          title: Summary
          description: Two-line document summary
          nullable: true
      type: object
      required:
        - doc_id
        - title
        - url
      title: OAIDoc
    OAIDocBase:
      properties:
        doc_id:
          type: string
          title: Doc Id
        title:
          type: string
          title: Title
        url:
          type: string
          title: Url
      type: object
      required:
        - doc_id
        - title
        - url
      title: OAIDocBase
    OAIDocCategory:
      type: string
      enum:
        - financials
        - transcripts
        - reports
        - news
        - files
        - filings
        - socials
        - global_research
      title: OAIDocCategory
      description: An enumeration.
    OAIMarket:
      type: string
      enum:
        - cn
        - hk
        - us
      title: OAIMarket
      description: An enumeration.
    CompanyLabel:
      properties:
        name:
          type: string
          title: Name
        logo:
          type: string
          title: Logo
        stocks:
          items:
            $ref: '#/components/schemas/CompanyStock'
          type: array
          title: Stocks
      type: object
      required:
        - name
      title: CompanyLabel
    CompanyStock:
      properties:
        symbol:
          type: string
          title: Symbol
        market:
          type: string
          title: Market
        code:
          type: string
          title: Code
      type: object
      required:
        - symbol
        - market
        - code
      title: CompanyStock
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your Bearer token

````