FL_FILTER_PAGES
functionnot supportedData loading & unloadingSelects pages of a multi-page document for processing by Cortex AI Functions for document intelligence. Use this function as the file argument of AI_EXTRACT or AI_PARSE_DOCUMENT when you only need part of a document. The function processes the pages you select instead of the whole document.
Syntax
FL_FILTER_PAGES( <file> , <pages> )
Parameters
| Name | Required | Description |
|---|---|---|
file | required | A FILE value that refers to a multi-page document. |
pages | required | An ARRAY of objects, each of which selects a range of pages. The array must contain at least one object and at most 4,096. Each object can contain a start field, an end field, or both. Both fields are signed integers and specify the first (inclusive) and last (exclusive) page of the range. Page indexes start at 0. For example, {'start': 0, 'end': 3} selects the first three pages. Omit either field to leave that end of the range open. An omitted start means the first page of the document, and an omitted end means the last page. Use a negative value to count backward from the end of the document: {'start': -3} selects the last three pages, and {'end': -1} selects everything except the last page. |
Returns
A FILE value that carries the page selection. Pass it directly as the file argument of AI_EXTRACT and AI_PARSE_DOCUMENT functions, which then process only the selected pages.
Usage notes
- FL_FILTER_PAGES is only meaningful as the file argument of a Cortex AI Function for document processing that supports page ranges. Today those functions are AI_EXTRACT and AI_PARSE_DOCUMENT. Used anywhere else, the statement fails to compile.
- end is always exclusive, whether it’s positive, negative, or omitted. This is the same rule that ARRAY_SLICE uses.
- Ranges that reach past the document are clamped rather than rejected. On a 10-page document, both [{'start': -100}] and [{'end': 100}] select the whole document.
- Each object in the array selects pages from the original document, independently of the others. The result is the union of all the ranges: overlapping ranges don’t process a page twice, and pages are processed in document order no matter what order you write the objects in.
- To process the whole document, either omit FL_FILTER_PAGES or pass [{}], which is an explicit “all pages” selection.
- You can’t select pages both with FL_FILTER_PAGES and with the page_filter option of the same call. There’s no precedence rule and the two selections aren’t merged, so specify the pages in one place only.
- A page selection applies only to the call you write it in. It isn’t stored on the FILE value, and later operations on that value don’t honor it.
- Page indexes in the result are indexes in the original document. Selecting pages 7, 8, and 9 doesn’t renumber them to 0, 1, and 2, and a selection with a gap in it doesn’t close that gap.
- In AI_PARSE_DOCUMENT output, metadata.pageCount is the total number of pages in the source document, not the number of pages you selected. The number of pages processed and billed is in metadata.processedPageCount. Neither count tells you which pages were processed, so they aren’t a reliable way to confirm how a relative range resolved. Use the page indexes in the result instead.
- An input that isn’t paginated, such as plain text, can’t be filtered by page and returns an error.
Error conditions
Errors are reported per row: the offending row fails and the rest of the query continues. Condition | Result The array is empty or isn’t an array. | Rejected. A selection, when you supply one, needs at least one object. The array contains more than 4,096 objects. | Rejected. The whole call fails, so a selection is never silently narrowed to the first 4,096 ranges. An item isn’t an object, or contains a field other than start and end. | Rejected. start or end is present but isn’t an integer. This includes NULL, a decimal value, a string, and a value outside the range of a signed 32-bit integer. | Rejected. Omitting a field is valid; setting it to NULL isn’t. Both fields are present, both are non-negative or both are negative, and end is less than or equal to start. | Rejected. Ranges such as {'start': 3, 'end': 3}, {'start': 5, 'end': 2}, and {'start': -1, 'end': -2} are empty for every document. end is 0, whatever start is. | Rejected. Ranges such as {'end': 0} and {'start': -3, 'end': 0} are empty for every document. The selection is valid but resolves to no pages for a particular document. | AI_PARSE_DOCUMENT fails the row. AI_EXTRACT returns an empty result for the row. Any other range, including one that mixes a negative value with a non-negative one, is accepted and resolved against the actual number of pages in each document.