API
Metarank's API provides an easy way to integrate Metarank with your applications.
Feedback API receives the stream of events
Train API trains the model on your data
Ranking API provides personalized results generated by the trained model
Recommend API - retrieval of recommendations.
Inference API - using LLMs for encoding and cross-encoding texts.
Prometheus endpoint - to have a nice metrics dashboard about Metarank internals.
Feedback
API Endpoint: /feedback
Method: POST
Feedback endpoint receives several types of events: item, user, interaction, ranking.
Integrating these events is crucial for personalization to operate properly and provide relevant results.
Payload format
You can find events and their description on the Supported events.
Response
A JSON message with the following fields:
accepted
: how many events from the submitted batch were processedstatus
: "ok" when no errors foundtookMillis
: how many milliseconds batch processing tookupdated
: how many underlying ranking features were recomputed.
Example:
Example
Train
API Endpoint: /train/<model name>
Method: POST
Train endpoint runs the training on persisted click-through data. You can run this method at any time to re-train the model. See the Model retraining how-to on how to set up the retraining.
Payload: none
Response
A JSON response with the following fields:
weights
: per-field model weightssizeBytes
: model size in bytesfeatures
: test/train error loss while training.
Example:
Ranking
API Endpoint: /rank/<model name>
Method: POST
Querystring Parameters:
explain: boolean
: used to provide extra information in the response containing calculated feature values.
Ranking endpoint does the real work of personalizing items that are passed to it. You need to explicitly define which model to invoke.
Payload format
id
: a request identifier later used to join ranking and interaction events. This will be the same value that you will pass to feedback endpoint for impression and ranking events.user
: an optional unique visitor identifier.session
: an optional session identifier, a single visitor may have multiple sessions.timestamp
: when this event happened. (see timestamp format description on which formats are supported)fields
: an optional array of extra fields that you can use in your model, for more information refer to Supported events.items
: which particular items were displayed to the visitor.items.id
: id of the content item. Should match theitem
property from item metadata event.items.fields
: an optional set of per-item fields, for example BM25 scores coming from ES. See how to use BM25 scores in ranking.items.label
: an optional field for explicit relevance judgments.
Response format
took
: number of millis spend processing requestitems.id
: id of the content item. Will matchitem
property from the item metadata event.items.score
: a score calculated by personalization modelitems.features
: an array of feature values calculated by pesonaliization model. This field will be returned ifexplain
field is set totrue
in the request. The structure of this object will vary depending on the feature type.
Recommendations
API Endpoint: /recommend/<model-name>
Method: POST
Recommend endpoint returns recommended items that are produced by recommendations model types.
Payload format:
Where:
count
- number of items to recommend.user
- optional, current user iditems
- context of recommendation. For example, it can be single item for "similar-items" recommendation, and multiple items at once for "cart-style" recommendations.
Response format
took
: number of millis spend processing requestitems.id
: id of the content item.items.score
: a score calculated by recommender model.
Inference with LLMs
Metarank has API for quick and dirty LLM inference and encoding of texts. It can be useful for implementing hybrid search applications, when you need an actual embedding vector for a query.
LMM bi-encoders
API Endpoint: /inference/encoder/<name>
Method: POST
Encode a batch of strings into vectors using configured model <name>
.
Payload format
Response format
LLM with cross-encoders
API Endpoint: /inference/cross/<name>
Method: POST
Encode a batch of query-document pairs into similarity scores using configured model <name>
.
Payload format
Response format
Prometheus metrics
API Endpoint: /metrics
Method: GET
Dumps app and JVM metrics in a prometheus format.
Example
Last updated