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

# 全模态知识库检索

> 用于检索全模态知识库，支持文本、图片、视频等多模态输入检索，支持向量检索、关键词检索、混合检索，支持查询重写、重排、QA干预等高级功能。点击 **Try it** 按钮可快速试用。



## OpenAPI

````yaml /openapi/openapi.json post /zrag/retrieval/retrieve
openapi: 3.0.1
info:
  title: ZHIPU AI API
  description: ZHIPU AI 接口提供强大的 AI 能力，包括聊天对话、工具调用和视频生成。
  license:
    name: ZHIPU AI 开发者协议和政策
    url: https://chat.z.ai/legal-agreement/terms-of-service
  version: 1.0.0
  contact:
    name: Z.AI 开发者
    url: https://chat.z.ai/legal-agreement/privacy-policy
    email: user_feedback@z.ai
servers:
  - url: https://open.bigmodel.cn/api/
    description: 开放平台服务
security:
  - bearerAuth: []
tags:
  - name: 模型 API
    description: Chat API
  - name: 工具 API
    description: Web Search API
  - name: Agent API
    description: Agent API
  - name: 文件 API
    description: File API
  - name: 知识库 API
    description: Knowledge API
  - name: 实时 API
    description: Realtime API
  - name: 批处理 API
    description: Batch API
  - name: 助理 API
    description: Assistant API
  - name: 智能体 API（旧）
    description: QingLiu Agent API
paths:
  /zrag/retrieval/retrieve:
    post:
      tags:
        - 知识库 API
      summary: 全模态知识库检索
      description: >-
        用于检索全模态知识库，支持文本、图片、视频等多模态输入检索，支持向量检索、关键词检索、混合检索，支持查询重写、重排、QA干预等高级功能。点击
        **Try it** 按钮可快速试用。
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ZragRetrieveRequest'
            example:
              multimodal: true
              knows:
                - id: '1234567890'
              query: 介绍一下小智
              multimodal_parts:
                - type: image_url
                  url: https://example.com/image.png
              top_k: 8
              top_n: 10
              recall_method: mixed
              recall_ratio: 0.8
              messages:
                - role: user
                  content: 你是谁
                - role: assistant
                  content: 我是小智，一个智能助手
        required: true
      responses:
        '200':
          description: 业务处理成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ZragRetrieveResponse'
        default:
          description: 请求失败。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LlmApplicationError'
components:
  schemas:
    ZragRetrieveRequest:
      type: object
      properties:
        multimodal:
          type: boolean
          default: true
          description: 是否走多模态路径检索，默认值为true
        knows:
          type: array
          description: 查询的知识库列表
          items:
            type: object
            properties:
              id:
                type: string
                description: 知识库ID
              doc_ids:
                type: array
                description: 知识库下的文档ID列表
                items:
                  type: string
            required:
              - id
        query:
          type: string
          description: 文本查询内容，与多模态查询内容必须传入其中之一
        multimodal_parts:
          type: array
          description: 多模态查询内容，与文本查询内容必须传入其中之一
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - image_url
                description: 仅支持图片类型：image_url
              url:
                type: string
                description: 图片URL链接
            required:
              - type
              - url
        top_k:
          type: integer
          default: 8
          description: 最终召回数量，默认为8
        top_n:
          type: integer
          default: 10
          description: 初始召回数量，默认为10
        recall_method:
          type: string
          enum:
            - embedding
            - keyword
            - mixed
          default: mixed
          description: 文本检索方式：embedding（向量检索）、keyword（关键词检索）、mixed（混合检索）
        recall_ratio:
          type: number
          default: 0.8
          description: 混合检索中向量检索的权重，取值范围0~1
        enable_rerank:
          type: boolean
          default: false
          description: 是否开启重排，默认不开启
        enable_rewrite:
          type: boolean
          default: false
          description: 是否开启查询重写，可配合messages参数实现多轮对话改写，默认不开启
        enable_expansion:
          type: boolean
          default: false
          description: 是否开启扩召，默认不开启
        similarity_threshold:
          type: number
          default: 0.2
          description: 相似度阈值，低于该阈值的切片会被过滤
        messages:
          type: array
          description: 当前对话消息列表，用于多轮对话改写
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - assistant
              content:
                type: string
                description: 消息内容，仅支持文本
            required:
              - role
              - content
        search_filters:
          type: object
          description: 过滤条件
          properties:
            index_types:
              type: array
              description: 索引列表
              items:
                type: object
                properties:
                  know_id:
                    type: string
                    description: 知识库ID
                  index_type_id:
                    type: integer
                    description: 索引ID
                required:
                  - know_id
                  - index_type_id
            tags:
              type: array
              description: 标签列表
              items:
                type: object
                properties:
                  tag_id:
                    type: string
                    description: 标签ID
                  value_type:
                    type: string
                    enum:
                      - fixed
                      - ref
                    description: 固定值：fixed，引用变量：ref
                  filter_type:
                    type: integer
                    enum:
                      - 1
                      - 2
                      - 3
                      - 4
                    description: '过滤类型：1: >=，2: <=，3: 包含，4: 不包含'
                  filter_value:
                    type: string
                    description: 日期/文本/引用值
                  multiple_value:
                    type: array
                    description: 选项值列表
                    items:
                      type: string
                required:
                  - tag_id
                  - value_type
                  - filter_type
                  - filter_value
                  - multiple_value
            qa_intervention:
              type: object
              description: QA干预配置
              properties:
                qa_similarity_threshold:
                  type: number
                  default: 0.6
                  description: QA干预相似度阈值
                qa_intervention_ids:
                  type: array
                  description: QA知识库ID列表
                  items:
                    type: string
              required:
                - qa_similarity_threshold
                - qa_intervention_ids
      required:
        - knows
    ZragRetrieveResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            contents:
              type: array
              description: 检索结果列表
              items:
                type: object
                properties:
                  id:
                    type: string
                    description: 切片ID（UUID）
                  know_id:
                    type: string
                    description: 知识库ID
                  doc_id:
                    type: string
                    description: 文档ID
                  text:
                    type: string
                    description: 文本内容
                  medias:
                    type: array
                    description: 文本中的媒体文件
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          description: 图片ID
                        url:
                          type: string
                          description: 图片URL
                        description:
                          type: string
                          description: 图片描述
                  image_url:
                    type: object
                    description: 图像URL
                    properties:
                      url:
                        type: string
                        description: URL
                  video_url:
                    type: object
                    description: 视频URL
                    properties:
                      url:
                        type: string
                        description: URL
                  index:
                    type: integer
                    description: 召回位次
                  score:
                    type: number
                    description: 召回分数
                  rerank_index:
                    type: integer
                    description: 重排位次
                  rerank_score:
                    type: number
                    description: 重排分数
                  metadata:
                    type: object
                    description: 元数据
                    properties:
                      doc_type:
                        type: string
                        description: 文档类型，如 pdf、docx、jpeg、png、mp4、mp3 等
                      doc_name:
                        type: string
                        description: 文档名称
                      doc_url:
                        type: string
                        description: 文档URL
                      index:
                        type: integer
                        description: 切片下标
                      page_index:
                        type: integer
                        description: 文档页码
                      clip_index:
                        type: integer
                        description: 视频切片下标
                      start_time:
                        type: integer
                        description: 首帧时间戳
                      end_time:
                        type: integer
                        description: 尾帧时间戳
                      duration:
                        type: integer
                        description: 视频切片时长
                      frames:
                        type: array
                        description: 关键帧列表
                        items:
                          type: string
            rewritten_query:
              type: object
              description: 查询重写结果
              properties:
                original_query:
                  type: string
                  description: 原始查询
                multi_queries:
                  type: array
                  description: 备选查询列表
                  items:
                    type: string
            elapsed_ms:
              type: integer
              description: 请求耗时（毫秒）
            total_tokens:
              type: integer
              description: 消耗的token数量
            request_id:
              type: string
              description: 请求ID
        code:
          type: integer
          description: 错误码，200为成功
        message:
          description: 错误信息
          type: string
    LlmApplicationError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        标准的 HTTP Bearer 认证方式，在 [API
        Keys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys) 页面获取密钥。

````