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

> Find documents by query, tags or IDs and return their full text

# Search Documents



## OpenAPI

````yaml post /v1/tools/search_documents
openapi: 3.1.0
info:
  title: spectra-server
  description: The API for Spectra Backend.
  version: 0.1.0
servers:
  - url: https://api-spectra.duplik.cn
security: []
paths:
  /v1/tools/search_documents:
    post:
      tags:
        - Tools
      summary: Search Documents
      description: >-
        Find documents in one or more knowledge bases and return their **full
        text**, not passages. Use it when a whole document is the unit you want;
        use `/v1/tools/retrieval_knowledge` when you want the relevant passages
        for a question.


        Three ways to select documents, in priority order. `document_ids`
        short-circuits everything and fetches exactly those documents. Otherwise
        `query` runs vector + keyword retrieval and also matches document names,
        while `entity_names` resolves documents through their metadata tags;
        passing both returns the **intersection**. Passing none of the three
        returns an empty list.


        An unmatched or out-of-organization `knowledge_ids` yields an empty
        `documents` list rather than an error. Each returned document carries
        its full content assembled from every chunk, so responses can be large —
        prefer narrowing with `entity_names` or `document_ids` over broad
        queries.
      operationId: search_documents_v1_tools_search_documents_post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchDocumentsRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchDocumentsResponse'
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Request
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unprocessable Entity
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal Server Error
      security:
        - HTTPBearer: []
components:
  schemas:
    SearchDocumentsRequest:
      properties:
        knowledge_ids:
          items:
            type: string
          type: array
          title: Knowledge Ids
          description: Knowledge bases to search
        query:
          anyOf:
            - type: string
            - type: 'null'
          title: Query
          description: Vector + keyword retrieval, also matched against document names
        entity_names:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Entity Names
          description: >-
            Resolve documents through their metadata tags. Intersected with
            query when both are given
        document_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Document Ids
          description: >-
            Fetch these documents directly. Highest priority: query and
            entity_names are skipped
      type: object
      required:
        - knowledge_ids
      title: SearchDocumentsRequest
    SearchDocumentsResponse:
      properties:
        documents:
          items:
            $ref: '#/components/schemas/DocumentDetail'
          type: array
          title: Documents
          default: []
      type: object
      title: SearchDocumentsResponse
    ErrorResponse:
      properties:
        code:
          type: integer
          title: Code
        message:
          type: string
          title: Message
      type: object
      required:
        - code
        - message
      title: ErrorResponse
    DocumentDetail:
      properties:
        document_id:
          type: string
          title: Document Id
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        file_type:
          anyOf:
            - type: string
            - type: 'null'
          title: File Type
        content:
          type: string
          title: Content
          default: ''
          description: Full document text, assembled from every chunk
      type: object
      required:
        - document_id
      title: DocumentDetail
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````