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

> Perform semantic search on document chunks based on specified criteria.

## 文档块搜索

**URL**: `/v1/search/chunks`\
**方法**: `POST`\
**描述**: 根据指定条件进行语义搜索文档内容块，通常用于 RAG 场景，支持按文档内容或相关字段搜索。

### 请求参数

| 参数名                         | 类型          | 描述                                                                                                                               |
| --------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------- |
| query                       | str         | 搜索关键词。                                                                                                                           |
| doc\_ids                    | array\[str] | 指定的文档 ID 列表，如 `["1046915273103380480", "1046522679340961792"]`。                                                                  |
| folder\_ids                 | array\[str] | 指定的文件夹 ID 列表，如 `["2046915273103380480", "2046522679340961792"]`。                                                                 |
| categories                  | array       | 文档类别（默认不包含 `files`），可选值有 `financials`，`transcripts`，`reports`（国内研报），`global_research`（外资研报），`filings`，`news`, `socials`，`files`。 |
| institutions                | array       | 指定机构筛选，如 `Morgan Stanley`，`Seeking Alpha`。*暂未支持*                                                                                 |
| markets                     | array       | 市场区域，默认包括所有市场。可选值有 `sz`, `sh`, `hk`, `us`。                                                                                       |
| symbols                     | array       | 股票代码列表，格式为 market:ticker（如 `US:AAPL`、`HK:00700`、`SH:600519`、`SZ:000001`）。                                                        |
| tags                        | dict        | 标签数组。                                                                                                                            |
|   key                       | str         | 标签类型（如 `industry`, `company`, `person`, `event`）。                                                                                |
|   value                     | array       | 标签内容数组。                                                                                                                          |
| start\_date                 | str         | 开始日期，格式为 `YYYY-MM-DD`。                                                                                                           |
| end\_date                   | str         | 结束日期，格式为 `YYYY-MM-DD`。                                                                                                           |
| num                         | int         | 返回的结果数量，默认值为 `10`。                                                                                                               |
| include\_doc\_extra\_detail | boolean     | 是否包含文档详细信息，默认值为 `false`（只返回文档 `id`，`title`，`url` 字段）。                                                                            |

**说明：**

* 当 categories 为 `files` 时，可以通过指定 `tags` 参数来筛选上传的文件（上传时制定了相应的 `tags`）。

### 响应参数

| 参数名             | 类型    | 描述                                                                                                      |
| --------------- | ----- | ------------------------------------------------------------------------------------------------------- |
| chunks          | array | 内容块数组，每个块包含以下字段：                                                                                        |
| id              | str   | 内容块唯一 ID。                                                                                               |
| type            | str   | 内容类型，可能的值为 `text`，`table`，`image`，`formula`。                                                            |
| media\_url      | str   | 内容块的媒体文件链接（如果类型为 `table`，`image`，`formula` 时提供图片链接）。                                                    |
| content         | str   | 内容原始文本（适用于 `text` 或 `table` 类型）。                                                                        |
| summary         | str   | 解析内容，适用于 `table`，`image`，`formula` 类型。                                                                  |
| doc             | dict  | 文档信息（当 `include_doc_extra_detail` 为 `true` 时包含以下字段）：                                                    |
|   id            | str   | 文档唯一 ID。                                                                                                |
|   title         | str   | 文档标题。                                                                                                   |
|   url           | str   | 文档网页链接。                                                                                                 |
|   institution   | str   | 发布机构。                                                                                                   |
|   author        | str   | 作者。                                                                                                     |
|   published\_at | str   | 发布时间，格式为 `YYYY-MM-DDTHH:MM:SS.000Z`。                                                                    |
|   category      | str   | 文档类别（`financials`, `transcripts`, `reports`, `global_research`, `filings`, `news`, `socials`, `files`）。 |
|   market        | str   | 市场区域（`cn`, `hk`, `us`）。                                                                                 |
|   symbol        | str   | 股票代码。                                                                                                   |
|   company\_name | str   | 公司名称。                                                                                                   |
|   logo          | str   | 公司 Logo 链接。                                                                                             |
|   summary       | str   | 文档摘要。                                                                                                   |
|   tags          | dict  | 标签字典，包含以下字段：                                                                                            |
|     key         | str   | 标签类型（如 `industry`，`company`，`person`，`event`）。                                                          |
|     value       | array | 标签内容数组。                                                                                                 |
|   metadatas     | dict  | 元数据字典，包含以下字段：                                                                                           |
|     key         | str   | 元数据类型（如 `periods`，`entities`）。                                                                          |
|     value       | array | 元数据内容数组。                                                                                                |

### 请求示例

**cURL**

```bash theme={null}
curl -X POST https://api.reportify.cn/v1/search/chunks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "query": "AI in finance",
    "doc_ids": ["1046915273103380480", "1046522679340961792"],
    "categories": ["financials", "reports"],
    "markets": ["us"],
    "symbols": ["AAPL"],
    "start_date": "2023-01-01",
    "end_date": "2023-12-31",
    "num": 5,
    "include_doc_extra_detail": true
}'
```

**Python 示例**

```python theme={null}
import requests

url = "https://api.reportify.cn/v1/search/chunks"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
payload = {
    "query": "AI in finance",
    "doc_ids": ["1046915273103380480", "1046522679340961792"],
    "categories": ["financials", "reports"],
    "markets": ["us"],
    "symbols": ["AAPL"],
    "start_date": "2023-01-01",
    "end_date": "2023-12-31",
    "num": 5,
    "include_doc_extra_detail": True
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

### 响应示例

```json theme={null}
{
  "chunks": [
    {
      "id": "448902339012",
      "type": "text",
      "media_url": "",
      "content": "AI in finance is transforming the industry...",
      "summary": "",
      "doc": {
        "id": "1046915273103380480",
        "title": "AI in Finance Report",
        "url": "https://reportify.cn/financials/1046895208953942016",
        "file_url": "https://files.reportify.cn/media/production/TSLA5a08ddfbb97bd6486fff7a3875e7fe28_20241024183012.pdf",
        "media_url": "https://files.reportify.cn/media/production/s_4728833_9e25b61b62960211e6040eb2b81b352c.mp3",
        "institution": "Morgan Stanley",
        "author": "Jane Doe",
        "published_at": "2023-12-31T00:00:00.000Z",
        "category": "reports",
        "type": "research_report_company",
        "market": "us",
        "symbol": "AAPL",
        "company_name": "Apple Inc.",
        "logo": "https://files.reportify.cn/logo/AAPL.svg",
        "summary": "This report provides an overview of AI applications in finance...",
        "tags": {
          "industry": [
            "AI",
            "EV"
          ],
          "company": [
            "Tesla"
          ]
        },
        "metadatas": {
          "periods": "Q4 2023",
          "entities": [
            "Tesla Inc.",
            "TSLA"
          ]
        }
      }
    },
    {
      "id": "448902339013",
      "type": "table",
      "media_url": "https://files.reportify.cn/media/production/447460783945158/520072899438150/605401659404358/element/4.jpg",
      "content": "",
      "summary": "Financial data for AI companies in 2023",
      "doc": {
        "id": "1046915273103380480",
        "title": "AI in Finance Report",
        "url": "https://reportify.cn/financials/1046895208953942016",
        "file_url": "https://files.reportify.cn/media/production/TSLA5a08ddfbb97bd6486fff7a3875e7fe28_20241024183012.pdf",
        "media_url": "https://files.reportify.cn/media/production/s_4728833_9e25b61b62960211e6040eb2b81b352c.mp3",
        "institution": "Morgan Stanley",
        "author": "Jane Doe",
        "published_at": "2023-12-31T00:00:00.000Z",
        "category": "reports",
        "type": "research_report_company",
        "market": "us",
        "symbol": "AAPL",
        "company_name": "Apple Inc.",
        "logo": "https://files.reportify.cn/logo/AAPL.svg",
        "summary": "This report provides an overview of AI applications in finance...",
        "tags": {
          "industry": [
            "AI",
            "EV"
          ],
          "company": [
            "Tesla"
          ]
        },
        "metadatas": {
          "periods": "Q4 2023",
          "entities": [
            "Tesla Inc.",
            "TSLA"
          ]
        }
      }
    }
  ]
}
```


## OpenAPI

````yaml POST /v1/search/chunks
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/search/chunks:
    post:
      tags:
        - openapi-search
      summary: Search Chunks
      description: Perform semantic search on document chunks based on specified criteria.
      operationId: search_chunks_reportify_api_v1_search_chunks_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAISearchChunksRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAISearchChunksResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    OAISearchChunksRequest:
      properties:
        query:
          type: string
          title: Query
        folder_ids:
          items:
            type: string
          type: array
          title: Folder Ids
          default: []
        doc_ids:
          items:
            type: string
          type: array
          title: Doc Ids
          default: []
        categories:
          items:
            $ref: '#/components/schemas/OAIDocCategory'
          type: array
          default:
            - financials
            - transcripts
            - reports
            - news
            - filings
            - socials
        markets:
          items:
            $ref: '#/components/schemas/OAIMarket'
          type: array
          default: []
        institutions:
          items:
            type: string
          type: array
          title: Institutions
          default: []
        symbols:
          items:
            type: string
          type: array
          title: Symbols
          default: []
        tags:
          additionalProperties:
            items: {}
            type: array
          type: object
          title: Tags
        start_date:
          type: string
          title: Start Date
        end_date:
          type: string
          title: End Date
        min_score:
          type: number
          title: Min Score
        extended_filters:
          items:
            type: object
          type: array
          title: Extended Filters
        num:
          type: integer
          title: Num
          default: 10
        include_doc_extra_details:
          type: boolean
          title: Include Doc Extra Details
          default: false
        refine_question:
          type: boolean
          title: Refine Question
          default: false
        date_range:
          $ref: '#/components/schemas/DateRangeEnum'
      type: object
      required:
        - query
      title: OAISearchChunksRequest
    OAISearchChunksResponse:
      properties:
        chunks:
          items:
            $ref: '#/components/schemas/OAIChunkWithDoc'
          type: array
          title: Chunks
          default: []
      type: object
      title: OAISearchChunksResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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.
    DateRangeEnum:
      type: string
      enum:
        - h
        - d
        - w
        - m
        - 'y'
      title: DateRangeEnum
      description: An enumeration.
    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
    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

````