Filters can be applied to the embeddings and user_files_v2 endpoints.

For pre-filtering documents, using tags_v2 is preferred to using tags (which is now deprecated). If both tags_v2 and tags are specified, tags is ignored. tags_v2 enables building complex filters through the use of “AND”, “OR”, and negation logic.

Take the below input as an example:

{
    "OR": [
        {
            "key": "subject",
            "value": "holy-bible",
            "negate": false
        },
        {
            "key": "person-of-interest",
            "value": "jesus christ",
            "negate": false
        },
        {
            "key": "genre",
            "value": "religion",
            "negate": true
        }
        {
            "AND": [
                {
                    "key": "subject",
                    "value": "tao-te-ching",
                    "negate": false
                },
                {
                    "key": "author",
                    "value": "lao-tzu",
                    "negate": false
                }
            ]
        }
    ]
}

In this case, files will be filtered such that:

  1. “subject” = “holy-bible” OR
  2. “person-of-interest” = “jesus christ” OR
  3. “genre” != “religion” OR
  4. “subject” = “tao-te-ching” AND “author” = “lao-tzu”

Note that the top level of the query must be either an “OR” or “AND” array. Currently, nesting is limited to 3. For tag blocks (those with “key”, “value”, and “negate” keys), the following typing rules apply:

  1. “key” isn’t optional and must be a string
  2. “value” isn’t optional and can be any or list[any]
  3. “negate” is optional and must be true or false. If present and true, then the filter block is negated in the resulting query. It is false by default.