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

# 知识库检索

> 用于检索个人知识库，支持向量检索、关键词检索、混合检索，支持自定义重排模型。



## OpenAPI

````yaml /openapi/openapi.json post /llm-application/open/knowledge/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:
  /llm-application/open/knowledge/retrieve:
    post:
      tags:
        - 知识库 API
      summary: 知识库检索
      description: 用于检索个人知识库，支持向量检索、关键词检索、混合检索，支持自定义重排模型。
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/KnowledgeRetrieveRequest'
        required: true
      responses:
        '200':
          description: 业务处理成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgeRetrieveResponse'
        default:
          description: 请求失败。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LlmApplicationError'
components:
  schemas:
    KnowledgeRetrieveRequest:
      type: object
      properties:
        request_id:
          type: string
          description: 请求唯一id，用于定位日志
        query:
          type: string
          description: 查询内容，限制在1000字以内
        knowledge_ids:
          type: array
          description: 知识库ID列表
          items:
            type: string
        document_ids:
          type: array
          description: 文档ID列表
          items:
            type: string
        top_k:
          type: integer
          description: 最终召回数量，取值范围为[1~20]，默认为8
        top_n:
          type: integer
          description: 初始召回数量，取值范围为[1~100]，默认为10
        recall_method:
          type: string
          enum:
            - embedding
            - keyword
            - mixed
          default: mixed
          description: |-
            检索类型 
            - embedding: 向量化检索
            - keyword:关键词检索
            - mixed: 混合检索（默认）
        recall_ratio:
          type: integer
          default: 80
          description: 混合检索中向量检索的权重，取值范围(0~100)，默认为80
        rerank_status:
          type: integer
          enum:
            - 0
            - 1
          description: '是否开启重排，0: 不开启，1: 开启，默认不开启'
        rerank_model:
          type: string
          enum:
            - rerank
            - rerank-pro
          description: 重排模型，支持rerank、rerank-pro
        fractional_threshold:
          type: number
          description: 相似度阈值，低于该阈值的切片会被过滤，取值范围为(0~1)
      required:
        - query
        - knowledge_ids
    KnowledgeRetrieveResponse:
      type: object
      properties:
        data:
          type: array
          description: 检索结果列表
          items:
            type: object
            properties:
              text:
                type: string
                description: 切片内容
              score:
                type: number
                description: 相似度分数
              metadata:
                type: object
                description: 切片元数据
                properties:
                  _id:
                    type: string
                    description: 切片ID
                  knowledge_id:
                    type: string
                    description: 知识库ID
                  doc_id:
                    type: string
                    description: 文档ID
                  doc_name:
                    type: string
                    description: 文档名称
                  doc_url:
                    type: string
                    description: 文档URL
                  contextual_text:
                    type: string
                    description: 上下文增强内容，不开启上下文增强则为空
        code:
          type: integer
          description: 响应码，200为成功
        message:
          type: string
          description: 响应信息
        timestamp:
          type: integer
          description: 响应时间戳
    LlmApplicationError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        使用以下格式进行身份验证：Bearer [<your api
        key>](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)

````