Hi,
I currently encounter an error when loading objectSet using a function. It returns the folloing error - ObjectSet:TooManyClauses
{
“instanceof conjure-client#ConjureError”: true,
“type”: “STATUS”,
“status”: 400,
“body”: {
“errorCode”: “INVALID_ARGUMENT”,
“errorName”: “ObjectSet:TooManyClauses”,
“errorInstanceId”: “secret”,
“parameters”: {}
},
“qos”: {}
}
To provide more context, it is a TSV1 function which takes 2 parameters and filters specificially for patters using parse which gives the exact expected result instead of exactMatch.
This only happens when we query with alot of search values. I want to know if there is threshold and how can I overcome
This usually happens when a large number of phrase filters are combined into one query. Try the following:
-
Remove blank values and deduplicate the search list.
-
If you need exact matching, use one multi-value filter instead of a large OR:
object.property.exactMatch(...uniqueValues)
-
If phrase matching is required, process the values in smaller batches. Start with 250–500 values per query, and combine and deduplicate the results by primary key in your application.
-
For a recurring workflow with thousands of values, add a normalized search-key property during ingestion and query that property with exactMatch. This is generally more scalable than building thousands of phrase alternatives dynamically.
Also check for unusually long or broad search values, since a single value can expand into many terms.
The ObjectSet:TooManyClauses error occurs when Foundry’s backend search index exceeds its internal clause limit. This typically happens when token-based filters such as parse, matchAnyToken, fuzzyMatchAnyToken, or matchAllTokens are used with large lists of search values, causing the search engine to generate too many internal clauses.
Recommended Solutions
-
Use exactMatch whenever possible
- Most efficient option.
- Creates only one clause per value.
- Best when exact matching is sufficient.
-
Batch values and combine results with .union()
- Use when token-based or fuzzy matching is required.
- Split large input lists into smaller chunks (e.g., 20 values per batch).
- Run separate searches and union the results to stay below the clause limit.
-
Use aggregations instead of loading objects
- Ideal when only counts, totals, or summary metrics are needed.
- More performant and avoids object-loading overhead.
-
Consider migrating to TypeScript v2
- Supports streaming (
asyncIter()), higher memory limits (1024 MiB vs. 128 MiB), and better scalability for large queries.
- Recommended as a long-term solution for functions handling large value sets.
Key Takeaway
The fastest and most impactful fix is to replace token-based filters with exactMatch() whenever business requirements allow. If fuzzy or token matching is necessary, use a batch-and-union approach to prevent exceeding the search index clause limit.
Thanks for the suggestion 
The issue was not just the number of clauses per query, but how the platform resolves ObjectSet unions returned from functions. When multiple filtered object sets are combined with .union() and returned as a single ObjectSet, the platform compiles the entire union into one compound search query at resolution time. For large input lists this causes the clause count to far exceed the platform limit of 1024, regardless of how the input was split.
What resolved it - The fix was to move result merging out of the query engine and into the function itself:
- Changed the function to async with return type Promise<Object[]> instead of ObjectSet
- Each batch executes independently against the search index via an async call
- Results from all batches are merged in memory within the function before being returned
This ensures each batch query is sent independently to the search index, keeping each query well within the clause limit. The caller receives a flat merged array of results as if it were a single query.