---
title: "Count chunks above threshold"
method: POST
path: "/api/chunk/count"
tags: ["Chunk"]
---

# Count chunks above threshold

`POST /api/chunk/count`

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.

## Headers

- `TR-Dataset` string, uuid, required

## Request body

- CountChunksReqPayload
  - `filters` ChunkFilter — 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.
    - `must` ConditionType[], nullable — All of these field conditions have to match for the chunk to be included in the result set.
      - union — 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.
        - FieldCondition — 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.`.
          - `boolean` boolean, nullable — 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.
          - `date_range` DateRange — 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.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — 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` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — 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.
            - union
              - …
          - `match_any` MatchCondition[], nullable — 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.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — 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.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
    - `must_not` ConditionType[], nullable — None of these field conditions can match for the chunk to be included in the result set.
      - union — 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.
        - FieldCondition — 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.`.
          - `boolean` boolean, nullable — 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.
          - `date_range` DateRange — 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.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — 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` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — 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.
            - union
              - …
          - `match_any` MatchCondition[], nullable — 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.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — 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.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
    - `should` ConditionType[], nullable — Only one of these field conditions has to match for the chunk to be included in the result set.
      - union — 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.
        - FieldCondition — 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.`.
          - `boolean` boolean, nullable — 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.
          - `date_range` DateRange — 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.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — 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` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — 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.
            - union
              - …
          - `match_any` MatchCondition[], nullable — 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.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — 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.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
  - `limit` integer, nullable — 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.
  - `query` union, required — 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.
    - union
      - object
        - `image_url` string, required
        - `llm_prompt` string, nullable
      - string
      - object
        - `audio_base64` string, required
    - MultiQuery[]
      - `query` union, required
        - object
          - `image_url` string, required
          - `llm_prompt` string, nullable
        - string
        - object
          - `audio_base64` string, required
      - `weight` number, float, required — Float value which is applies as a multiplier to the query vector when summing.
  - `score_threshold` number, float, nullable — 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.
  - `search_type` 'fulltext' | 'semantic' | 'bm25', required
  - `use_quote_negated_terms` boolean, nullable — If true, quoted and - prefixed words will be parsed from the queries and used as required and negated words respectively. Default is false.

## Response `200`

Number of chunks satisfying the query

- CountChunkQueryResponseBody
  - `count` integer, required

## Other responses

- `404` — Failed to count chunks

---

[API](https://skmtc.net/devflowinc/apis/trieve-api.md) · [All operations](https://skmtc.net/devflowinc/apis/trieve-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/devflowinc/trieve-api/revisions/84583e7c9fc1/schema)
