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

# Top Snippets

> Get the top K snippets that match the given query.

You may choose between coarse and precise snippets. Precise snippets will average ~200 characters, while coarse snippets will average ~2000 characters. The default is coarse snippets. Use the `precise_responses` parameter to adjust.



## OpenAPI

````yaml post /queries/top-snippets
openapi: 3.1.0
info:
  title: ZeroEntropy API
  description: This API provides access to ZeroEntropy's SoTA retrieval pipeline. Enjoy!
  version: 0.1.0
servers:
  - url: https://api.zeroentropy.dev/v1
    description: ZeroEntropy API
  - url: https://eu-api.zeroentropy.dev/v1
    description: ZeroEntropy API (EU datacenters)
security: []
paths:
  /queries/top-snippets:
    post:
      tags:
        - Queries
      summary: Top Snippets
      description: >-
        Get the top K snippets that match the given query.


        You may choose between coarse and precise snippets. Precise snippets
        will average ~200 characters, while coarse snippets will average ~2000
        characters. The default is coarse snippets. Use the `precise_responses`
        parameter to adjust.
      operationId: top_snippets_queries_top_snippets_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TopSnippetsRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TopSnippetsResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              example:
                detail: Description of Error
        '404':
          description: Not Found
          content:
            application/json:
              example:
                detail: Description of Error
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    TopSnippetsRequest:
      properties:
        collection_name:
          type: string
          title: Collection Name
          description: The name of the collection.
        query:
          type: string
          title: Query
          description: >-
            The natural language query to search with. This cannot exceed 4096
            characters (A single UTF-8 codepoint, is considered to be 1
            character).
        k:
          type: integer
          title: K
          description: >-
            The number of snippets to return. If there are not enough snippets
            matching your filters, then fewer may be returned. This number must
            be between 1 and 128, inclusive.
        reranker:
          anyOf:
            - type: string
            - type: 'null'
          title: Reranker
          description: >-
            The reranker to use after initial retrieval. The default is `null`.
            You can find available model ids, along with more information, at
            [/models/rerank](/api-reference/models/rerank).
        filter:
          anyOf:
            - $ref: '#/components/schemas/StrJson'
            - type: 'null'
          description: >-
            The query filter to apply. Please read [Metadata
            Filtering](/metadata-filtering) for more information. If not
            provided, then all documents will be searched.
        precise_responses:
          type: boolean
          title: Precise Responses
          description: >-
            Enable precise responses. Precise responses will have higher
            latency, but provide much more precise snippets. When
            `precise_responses` is set to `true`, the responses will average 200
            characters. If set to `false`, the responses will average 2000
            characters. The default is `false`.
          default: false
        include_document_metadata:
          type: boolean
          title: Include Document Metadata
          description: >-
            If true, the `document_results` returns will additionally contain
            document metadata. This is false by default, as returning metadata
            can add overhead if the amount of data to return is large.
          default: false
      type: object
      required:
        - collection_name
        - query
        - k
      title: TopSnippetsRequest
    TopSnippetsResponse:
      properties:
        results:
          items:
            $ref: '#/components/schemas/SnippetResponse'
          type: array
          title: Results
          description: >-
            The array of snippets returned by this endpoint. Each snippet result
            refers to a particular document path, and index range. Note that all
            documents, regardless of filetype, are converted into
            `UTF-8`-encoded strings. The `start_index` and `end_index` of a
            snippet refer to the range of characters in that string, that have
            been matched by this snippet.
        document_results:
          items:
            $ref: '#/components/schemas/DocumentRetrievalResponse'
          type: array
          title: Document Results
          description: >-
            The array of associated document information. Note how each snippet
            has an associated document path. After deduplicating the document
            paths, this array will contain document info for each document path
            that is referenced by at least one snippet result.
      type: object
      required:
        - results
        - document_results
      title: TopSnippetsResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    StrJson:
      anyOf:
        - type: string
        - items:
            type: string
          type: array
        - items:
            $ref: '#/components/schemas/StrJson'
          type: array
        - additionalProperties:
            $ref: '#/components/schemas/StrJson'
          type: object
    SnippetResponse:
      properties:
        path:
          type: string
          title: Path
          description: The path of the document that this snippet comes from.
        start_index:
          type: integer
          title: Start Index
          description: The start index of this snippet.
        end_index:
          type: integer
          title: End Index
          description: The end index of this snippet.
        page_span:
          prefixItems:
            - type: integer
            - type: integer
          type: array
          items:
            type: integer
          maxItems: 2
          minItems: 2
          title: Page Span
          description: >-
            The range of page indices spanned by this snippet, as a 2-tuple of
            integers. Inclusive on the first page_index and exclusive on the
            second page_index.
        content:
          type: string
          title: Content
          description: The full string content of this snippet.
        score:
          type: number
          title: Score
          description: The relevancy score assigned to this snippet.
      type: object
      required:
        - path
        - start_index
        - end_index
        - page_span
        - content
        - score
      title: SnippetResponse
      description: >-
        This is a Snippet.


        A snippet refers to a particular document path, and index range. Note
        that all documents, regardless of filetype, are converted into
        `UTF-8`-encoded strings. The `start_index` and `end_index` refer to the
        range of characters in that string, that have been matched by this
        snippet.
    DocumentRetrievalResponse:
      properties:
        path:
          type: string
          title: Path
          description: The path of the document.
        score:
          type: number
          title: Score
          description: The relevancy score assigned to this document.
        metadata:
          anyOf:
            - $ref: '#/components/schemas/DocumentMetadataJson'
            - type: 'null'
          description: >-
            The metadata for that document. Will be `None` if `include_metadata`
            is `False`.
        file_url:
          type: string
          title: File Url
          description: >-
            A URL to the document data, which can be used to download the raw
            document content or to display the document in frontend
            applications.


            NOTE: If a `/documents/update-document` call returned a new document
            id, then this url will be invalidated and must be retrieved again.
      type: object
      required:
        - path
        - score
        - metadata
        - file_url
      title: DocumentRetrievalResponse
    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
    DocumentMetadataJson:
      additionalProperties:
        anyOf:
          - type: string
          - items:
              type: string
            type: array
      type: object
  securitySchemes:
    HTTPBearer:
      type: http
      description: >-
        The `Authorization` header must be provided in the format `Bearer
        <your-api-key>`.


        You can get your API Key at the
        [Dashboard](https://dashboard.zeroentropy.dev/)!
      scheme: bearer

````