Which Query Type Do I Use? (v2, Beta)

v2 exposes one JSON query language over several endpoints. They share from / where / select; the endpoint (and a couple of top-level keys) picks the task. This guide is the "I know my problem, which endpoint?" map.

Quick reference

You want to…EndpointTop-level keyReturns
Filter & project rows_querywhere / selectmatching rows
Classify / fill a field_predictpredictranked values with $p
Rank options for an outcome_recommendrecommend + goalranked candidates
Estimate a number_estimateestimatea single numeric value
BM25 relevance search_searchsearchrows ranked by $score
Mine co-occurring patterns_relaterelateitemsets / correlations

There is no _similarity endpoint in v2 (it returns 404). Similarity is an in-query operator β€” $nearest (vector) and $knn/$nn (feature) β€” that composes inside any where/orderBy, which is strictly more flexible. ($similarity is the per-row score those operators expose, not the operator itself.)

v2 works on v2 collections

v2 is built for v2 collections ("type": "collection") β€” the CollectionDb engine, with native full-text search, links, vectors, and calibrated inference. A legacy rep1 table ("type": "table") can still be reached through /api/v2 for basic where / select filtering and predict, but that support is deliberately minimal β€” v1 tables are being retired. In particular the text matchers $match / $search (and a few other operators) are not available on a rep1 table via /api/v2; they fail loud with a message pointing here, rather than returning a wrong result.

To use v2 fully on data that currently lives in a v1 table:

  • Migrate it to a v2 collection β€” see Schema Migration. New tables should be defined as "type": "collection" from the start.
  • Or branch it into an environment and trial v2 features there, without touching production β€” the recommended way to test v2 on existing data.

For full-text search (and the other v1-native operations) on a table you haven't migrated, keep using the mature v1 API.

Query vs Predict β€” retrieve vs infer

_query returns the rows that match β€” deterministic, exact. Use it to filter, project, and page.

{ "from": "products", "where": { "name": { "$match": "milk" } },
  "select": ["name", "price"], "limit": 5 }

_predict infers the most likely values of a field from evidence, with a calibrated probability. Use it to classify or fill an unknown.

{ "from": "products", "where": { "name": { "$match": "milk" } },
  "predict": "category", "select": ["$value", "$p"] }
// -> [{ "$p": 0.738, "$value": "104" }, { "$p": 0.140, "$value": "109" }, …]

Rule of thumb: "which rows?" β†’ _query; "which value is this likely to be?" β†’ _predict.

Predict vs Recommend β€” classify vs optimize

_predict completes a single field for one row's evidence β€” "what GL code for this invoice?".

_recommend ranks candidates by how well each achieves a stated goal β€” "which product to surface so an impression converts?". It needs a goal.

{ "from": "impressions", "recommend": "product",
  "goal": { "purchase": true }, "select": ["$value", "$p"] }

Predict answers "what is this?"; recommend answers "which one should I pick to get outcome X?".

Predict vs Estimate β€” categorical vs numeric

_predict is for categorical targets β€” it returns a probability distribution over discrete values.

_estimate is for a numeric target β€” it returns one number.

{ "from": "products", "where": { "name": { "$match": "milk" } },
  "estimate": "price" }
// -> { "estimate": 1.62 }

If the target is a category/label/tag β†’ _predict. If it's a price, quantity, or duration β†’ _estimate.

Search vs the $match filter β€” ranked vs boolean

$match inside a _query where is a boolean filter β€” a row either contains the tokens or it doesn't.

_search ranks rows by BM25 relevance and returns a $score (and $highlight). Use it for "most relevant first", agent-assist, and FAQ retrieval.

{ "from": "prompts", "search": { "field": "prompt", "text": "refund" },
  "select": ["prompt", "$highlight"], "limit": 5 }

Multi-term $match and $knn match all tokens (AND); a term absent from every row empties the result. Use $search (its OR/NOT/phrase syntax), single terms, or the ranked search block. See Common Errors.

Content similarity β€” operators, not an endpoint

To rank by similarity, use an operator inside a query:

  • $knn / $nn β€” feature similarity (BM25 on text, shared features elsewhere). No vectors needed.
  • $similarity / $nearest β€” vector similarity on a Vector column.
{ "from": "products", "where": { "$knn": { "near": { "name": "semi-skimmed milk" } } },
  "select": ["name", "$similarity"], "limit": 3 }

Relate β€” discover patterns

_relate with { "$patterns": … } mines co-occurring itemsets (market basket, association rules) directly from array/set/text columns β€” no export, no batch job.

{ "from": "products", "relate": { "$patterns": ["tags"] } }

See Market Basket Analysis.

Decision tree

                       What do you need?
                              β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚           β”‚            β”‚            β”‚           β”‚
  exact       relevance    infer a      optimize    discover
  rows        ranking      value        an outcome   patterns
     β”‚           β”‚            β”‚            β”‚           β”‚
  _query      _search    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”   _recommend   _relate
                         β”‚         β”‚
                    categorical  numeric
                     _predict   _estimate

   want "similar to X"? β†’ $knn / $similarity operator inside a _query

Summary

EndpointInputOutputUse when
_querywhere / selectmatching rowsyou know exactly what to fetch
_searchsearch blockrows + $scoreyou want relevance-ranked results
_predictevidence wherevalues + $pyou're classifying / filling a category
_estimateevidence whereone numberyou're predicting a numeric value
_recommendrecommend + goalranked candidatesyou're optimizing for an outcome
_relaterelate $patternsitemsetsyou're discovering correlations

Related: Query Reference Β· Inference Β· Use Cases Β· Sandbox