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

# Count chunks above threshold

> This route can be used to determine the number of chunk results that match a search query including score threshold and filters. It may be high latency for large limits. There is a dataset configuration imposed restriction on the maximum limit value (default 10,000) which is used to prevent DDOS attacks. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.



## OpenAPI

````yaml post /api/chunk/count
openapi: 3.0.3
info:
  title: Trieve API
  description: >-
    Trieve OpenAPI Specification. This document describes all of the operations
    available through the Trieve API.
  contact:
    name: Trieve Team
    url: https://trieve.ai
    email: developers@trieve.ai
  license:
    name: BSL
    url: https://github.com/devflowinc/trieve/blob/main/LICENSE.txt
  version: 0.13.0
servers:
  - url: https://api.trieve.ai
    description: Production server
  - url: http://localhost:8090
    description: Local development server
security: []
tags:
  - name: Invitation
    description: Invitation endpoint. Exists to invite users to an organization.
  - name: Auth
    description: Authentication endpoint. Serves to register and authenticate users.
  - name: User
    description: User endpoint. Enables you to modify user roles and information.
  - name: Organization
    description: >-
      Organization endpoint. Enables you to modify organization roles and
      information.
  - name: Dataset
    description: >-
      Dataset endpoint. Datasets belong to organizations and hold configuration
      information for both client and server. Datasets contain chunks and chunk
      groups.
  - name: Chunk
    description: >-
      Chunk endpoint. Think of chunks as individual searchable units of
      information. The majority of your integration will likely be with the
      Chunk endpoint.
  - name: Chunk Group
    description: >-
      Chunk groups endpoint. Think of a chunk_group as a bookmark folder within
      the dataset.
  - name: Crawl
    description: Crawl endpoint. Used to create and manage crawls for datasets.
  - name: File
    description: >-
      File endpoint. When files are uploaded, they are stored in S3 and broken
      up into chunks with text extraction from Apache Tika. You can upload files
      of pretty much any type up to 1GB in size. See chunking algorithm details
      at `docs.trieve.ai` for more information on how chunking works. Improved
      default chunking is on our roadmap.
  - name: Events
    description: >-
      Notifications endpoint. Files are uploaded asynchronously and events are
      sent to the user when the upload is complete.
  - name: Topic
    description: >-
      Topic chat endpoint. Think of topics as the storage system for gen-ai chat
      memory. Gen AI messages belong to topics.
  - name: Message
    description: >-
      Message chat endpoint. Messages are units belonging to a topic in the
      context of a chat with a LLM. There are system, user, and assistant
      messages.
  - name: Stripe
    description: >-
      Stripe endpoint. Used for the managed SaaS version of this app. Eventually
      this will become a micro-service. Reach out to the team using contact info
      found at `docs.trieve.ai` for more information.
  - name: Health
    description: Health check endpoint. Used to check if the server is up and running.
  - name: Metrics
    description: Metrics endpoint. Used to get information for monitoring
  - name: Analytics
    description: Analytics endpoint. Used to get information for search and RAG analytics
  - name: Experiment
    description: Experiment endpoint. Used to create and manage experiments
paths:
  /api/chunk/count:
    post:
      tags:
        - Chunk
      summary: Count chunks above threshold
      description: >-
        This route can be used to determine the number of chunk results that
        match a search query including score threshold and filters. It may be
        high latency for large limits. There is a dataset configuration imposed
        restriction on the maximum limit value (default 10,000) which is used to
        prevent DDOS attacks. Auth'ed user or api key must have an admin or
        owner role for the specified dataset's organization.
      operationId: count_chunks
      parameters:
        - name: TR-Dataset
          in: header
          description: >-
            The dataset id or tracking_id to use for the request. We assume you
            intend to use an id if the value is a valid uuid.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: JSON request payload to count chunks for a search query
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CountChunksReqPayload'
        required: true
      responses:
        '200':
          description: Number of chunks satisfying the query
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CountChunkQueryResponseBody'
        '404':
          description: Failed to count chunks
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseBody'
      security:
        - ApiKey:
            - readonly
components:
  schemas:
    CountChunksReqPayload:
      type: object
      required:
        - search_type
        - query
      properties:
        filters:
          allOf:
            - $ref: '#/components/schemas/ChunkFilter'
          nullable: true
        limit:
          type: integer
          format: int64
          description: >-
            Set limit to restrict the maximum number of chunks to count. This is
            useful for when you want to reduce the latency of the count
            operation. By default the limit will be the number of chunks in the
            dataset.
          nullable: true
          minimum: 0
        query:
          $ref: '#/components/schemas/QueryTypes'
        score_threshold:
          type: number
          format: float
          description: >-
            Set score_threshold to a float to filter out chunks with a score
            below the threshold. This threshold applies before weight and bias
            modifications. If not specified, this defaults to 0.0.
          nullable: true
        search_type:
          $ref: '#/components/schemas/CountSearchMethod'
        use_quote_negated_terms:
          type: boolean
          description: >-
            If true, quoted and - prefixed words will be parsed from the queries
            and used as required and negated words respectively. Default is
            false.
          nullable: true
      example:
        query: Some search query
        score_threshold: 0.5
        search_type: semantic
    CountChunkQueryResponseBody:
      type: object
      required:
        - count
      properties:
        count:
          type: integer
          format: int32
          minimum: 0
    ErrorResponseBody:
      type: object
      required:
        - message
      properties:
        message:
          type: string
      example:
        message: Bad Request
    ChunkFilter:
      type: object
      description: >-
        ChunkFilter is a JSON object which can be used to filter chunks. This is
        useful for when you want to filter chunks by arbitrary metadata. Unlike
        with tag filtering, there is a performance hit for filtering on
        metadata.
      properties:
        must:
          type: array
          items:
            $ref: '#/components/schemas/ConditionType'
          description: >-
            All of these field conditions have to match for the chunk to be
            included in the result set.
          nullable: true
        must_not:
          type: array
          items:
            $ref: '#/components/schemas/ConditionType'
          description: >-
            None of these field conditions can match for the chunk to be
            included in the result set.
          nullable: true
        should:
          type: array
          items:
            $ref: '#/components/schemas/ConditionType'
          description: >-
            Only one of these field conditions has to match for the chunk to be
            included in the result set.
          nullable: true
      example:
        must:
          - field: tag_set
            match_all:
              - A
              - B
          - field: num_value
            range:
              gte: 10
              lte: 25
    QueryTypes:
      oneOf:
        - $ref: '#/components/schemas/SearchModalities'
        - type: array
          items:
            $ref: '#/components/schemas/MultiQuery'
      description: >-
        Query is the search query. This can be any string. The query will be
        used to create an embedding vector and/or SPLADE vector which will be
        used to find the result set.  You can either provide one query, or
        multiple with weights. Multi-query only works with Semantic Search and
        is not compatible with cross encoder re-ranking or highlights.
    CountSearchMethod:
      type: string
      enum:
        - fulltext
        - semantic
        - bm25
    ConditionType:
      oneOf:
        - $ref: '#/components/schemas/FieldCondition'
        - $ref: '#/components/schemas/HasChunkIDCondition'
      description: >-
        Filters can be constructed using either fields on the chunk objects, ids
        or tracking ids of chunks, and finally ids or tracking ids of groups.
    SearchModalities:
      oneOf:
        - type: object
          title: Image
          required:
            - image_url
          properties:
            image_url:
              type: string
            llm_prompt:
              type: string
              nullable: true
        - type: string
          title: Text
        - type: object
          title: Audio
          required:
            - audio_base64
          properties:
            audio_base64:
              type: string
    MultiQuery:
      type: object
      description: >-
        MultiQuery allows you to construct a dense vector from multiple queries
        with a weighted sum. This is useful for when you want to emphasize
        certain features of the query. This only works with Semantic Search and
        is not compatible with cross encoder re-ranking or highlights.
      required:
        - query
        - weight
      properties:
        query:
          $ref: '#/components/schemas/SearchModalities'
        weight:
          type: number
          format: float
          description: >-
            Float value which is applies as a multiplier to the query vector
            when summing.
    FieldCondition:
      type: object
      description: >-
        FieldCondition is a JSON object which can be used to filter chunks by a
        field. This is useful for when you want to filter chunks by arbitrary
        metadata. To access fields inside of the metadata that you provide with
        the card, prefix the field name with `metadata.`.
      required:
        - field
      properties:
        boolean:
          type: boolean
          description: >-
            Boolean is a true false value for a field. This only works for
            boolean fields. You can specify this if you want values to be true
            or false.
          nullable: true
        date_range:
          allOf:
            - $ref: '#/components/schemas/DateRange'
          nullable: true
        field:
          type: string
          description: >-
            Field is the name of the field to filter on. Commonly used fields
            are `timestamp`, `link`, `tag_set`, `location`, `num_value`,
            `group_ids`, and `group_tracking_ids`. The field value will be used
            to check for an exact substring match on the metadata values for
            each existing chunk. This is useful for when you want to filter
            chunks by arbitrary metadata. To access fields inside of the
            metadata that you provide with the card, prefix the field name with
            `metadata.`.
        geo_bounding_box:
          allOf:
            - $ref: '#/components/schemas/LocationBoundingBox'
          nullable: true
        geo_polygon:
          allOf:
            - $ref: '#/components/schemas/LocationPolygon'
          nullable: true
        geo_radius:
          allOf:
            - $ref: '#/components/schemas/LocationRadius'
          nullable: true
        match_all:
          type: array
          items:
            $ref: '#/components/schemas/MatchCondition'
          description: >-
            Match all lets you pass in an array of values that will return
            results if all of the items match. The match value will be used to
            check for an exact substring match on the metadata values for each
            existing chunk. If both match_all and match_any are provided, the
            match_any condition will be used.
          nullable: true
        match_any:
          type: array
          items:
            $ref: '#/components/schemas/MatchCondition'
          description: >-
            Match any lets you pass in an array of values that will return
            results if any of the items match. The match value will be used to
            check for an exact substring match on the metadata values for each
            existing chunk. If both match_all and match_any are provided, the
            match_any condition will be used.
          nullable: true
        range:
          allOf:
            - $ref: '#/components/schemas/Range'
          nullable: true
      example:
        field: metadata.key1
        match:
          - value1
          - value2
        range:
          gt: 0
          gte: 0
          lt: 1
          lte: 1
    HasChunkIDCondition:
      type: object
      description: >-
        HasChunkIDCondition is a JSON object which can be used to filter chunks
        by their ids or tracking ids. This is useful for when you want to filter
        chunks by their ids or tracking ids.
      properties:
        ids:
          type: array
          items:
            type: string
            format: uuid
          description: >-
            Ids of the chunks to apply a match_any condition with. Only chunks
            with one of these ids will be returned.
          nullable: true
        tracking_ids:
          type: array
          items:
            type: string
          description: >-
            Tracking ids of the chunks to apply a match_any condition with. Only
            chunks with one of these tracking ids will be returned.
          nullable: true
    DateRange:
      type: object
      description: >-
        DateRange is a JSON object which can be used to filter chunks by a range
        of dates. This leverages the time_stamp field on chunks in your dataset.
        You can specify this if you want values in a certain range. You must
        provide ISO 8601 combined date and time without timezone.
      properties:
        gt:
          type: string
          nullable: true
        gte:
          type: string
          nullable: true
        lt:
          type: string
          nullable: true
        lte:
          type: string
          nullable: true
      example:
        gt: '2021-01-01 00:00:00.000'
        gte: '2021-01-01 00:00:00.000'
        lt: '2021-01-01 00:00:00.000'
        lte: '2021-01-01 00:00:00.000'
    LocationBoundingBox:
      type: object
      required:
        - top_left
        - bottom_right
      properties:
        bottom_right:
          $ref: '#/components/schemas/GeoInfo'
        top_left:
          $ref: '#/components/schemas/GeoInfo'
    LocationPolygon:
      type: object
      required:
        - exterior
      properties:
        exterior:
          type: array
          items:
            $ref: '#/components/schemas/GeoInfo'
        interior:
          type: array
          items:
            type: array
            items:
              $ref: '#/components/schemas/GeoInfo'
          nullable: true
    LocationRadius:
      type: object
      required:
        - center
        - radius
      properties:
        center:
          $ref: '#/components/schemas/GeoInfo'
        radius:
          type: number
          format: double
    MatchCondition:
      oneOf:
        - type: string
        - type: integer
          format: int64
        - type: number
          format: double
    Range:
      type: object
      properties:
        gt:
          allOf:
            - $ref: '#/components/schemas/RangeCondition'
          nullable: true
        gte:
          allOf:
            - $ref: '#/components/schemas/RangeCondition'
          nullable: true
        lt:
          allOf:
            - $ref: '#/components/schemas/RangeCondition'
          nullable: true
        lte:
          allOf:
            - $ref: '#/components/schemas/RangeCondition'
          nullable: true
      example:
        gt: 0
        gte: 0
        lt: 1
        lte: 1
    GeoInfo:
      type: object
      description: Location that you want to use as the center of the search.
      required:
        - lat
        - lon
      properties:
        lat:
          $ref: '#/components/schemas/GeoTypes'
        lon:
          $ref: '#/components/schemas/GeoTypes'
    RangeCondition:
      oneOf:
        - type: number
          format: double
        - type: integer
          format: int64
    GeoTypes:
      oneOf:
        - type: integer
          format: int64
        - type: number
          format: double
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

````