Recommend API (1.0.0)
Download OpenAPI specification:Download
The Recommend API lets you retrieve recommendations from one of Algolia's AI recommendation models that you previously trained on your data.
Use Algolia's API clients and libraries to reliably integrate Algolia's APIs with your apps. The official API clients are covered by Algolia's Service Level Agreement.
See: Algolia's ecosystem
The base URLs for requests to the Recommend API are:
https://{APPLICATION_ID}.algolia.net
https://{APPLICATION_ID}-dsn.algolia.net
. If your subscription includes a Distributed Search Network, this ensures that requests are sent to servers closest to users.
Both URLs provide high availability by distributing requests with load balancing.
All requests must use HTTPS.
To guarantee a high availability, implement a retry strategy for all API requests using the URLs of your servers as fallbacks:
https://{APPLICATION_ID}-1.algolianet.com
https://{APPLICATION_ID}-2.algolianet.com
https://{APPLICATION_ID}-3.algolianet.com
These URLs use a different DNS provider than the primary URLs. You should randomize this list to ensure an even load across the three servers.
All Algolia API clients implement this retry strategy.
To authenticate your API requests, add these headers:
x-algolia-application-id
. Your Algolia application ID.x-algolia-api-key
. An API key with the necessary permissions to make the request. The required access control list (ACL) to make a request is listed in each endpoint's reference.
You can find your application ID and API key in the Algolia dashboard.
The Recommend API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order of attributes in the API response.
Successful responses return a 2xx
status. Client errors return a 4xx
status. Server errors are indicated by a 5xx
status.
Error responses have a message
property with more information.
The current version of the Recommend API is version 1, as indicated by the /1/
in each endpoint's URL.
Retrieve recommendations from a pre-trained AI model. You can train models in the Algolia dashboard.
Retrieve recommendations
Retrieves recommendations from selected AI models.
Request Body schema: application/jsonrequired
required | Array of Frequently bought together (object) or Related products (object) or Trending items (object) or Trending facet values (object) or Looking similar (object) or Recommended for you (object) Recommendation request with parameters depending on the requested model. | ||||||||||||
Array One of
|
Responses
Request samples
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// Initialize the client var client = new RecommendClient(new RecommendConfig("YOUR_APP_ID", "YOUR_API_KEY")); // Call the API var response = await client.GetRecommendationsAsync( new GetRecommendationsParams { Requests = new List<RecommendationsRequest> { new RecommendationsRequest( new RelatedQuery { IndexName = "indexName", ObjectID = "objectID", Model = Enum.Parse<RelatedModel>("RelatedProducts"), Threshold = 42.1, } ) }, } );
Response samples
- 200
- 400
- 402
- 403
- 404
{- "results": [
- {
- "abTestID": 0,
- "abTestVariantID": 1,
- "aroundLatLng": "40.71,-74.01",
- "automaticRadius": "string",
- "exhaustive": {
- "facetsCount": true,
- "facetValues": true,
- "nbHits": true,
- "rulesMatch": true,
- "typo": true
}, - "exhaustiveFacetsCount": true,
- "exhaustiveNbHits": true,
- "exhaustiveTypo": true,
- "facets": {
- "category": {
- "food": 1,
- "tech": 42
}
}, - "facets_stats": {
- "property1": {
- "min": 0.1,
- "max": 0.1,
- "avg": 0.1,
- "sum": 0.1
}, - "property2": {
- "min": 0.1,
- "max": 0.1,
- "avg": 0.1,
- "sum": 0.1
}
}, - "hitsPerPage": 20,
- "index": "indexName",
- "indexUsed": "indexNameAlt",
- "message": "string",
- "nbHits": 20,
- "nbPages": 1,
- "nbSortedHits": 20,
- "page": 0,
- "parsedQuery": "george clo",
- "processingTimeMS": 20,
- "processingTimingsMS": { },
- "queryAfterRemoval": "string",
- "redirect": {
- "index": [
- {
- "source": "string",
- "dest": "string",
- "reason": "string",
- "succeed": true,
- "data": {
- "ruleObjectID": "string"
}
}
]
}, - "renderingContent": {
- "facetOrdering": {
- "facets": {
- "order": [
- "string"
]
}, - "values": {
- "facet1": {
- "order": [
- "string"
], - "sortRemainingBy": "alpha",
- "hide": [
- "string"
]
}, - "facet2": {
- "order": [
- "string"
], - "sortRemainingBy": "alpha",
- "hide": [
- "string"
]
}
}
}, - "redirect": {
- "url": "string"
}
}, - "serverTimeMS": 20,
- "serverUsed": "c2-uk-3.algolia.net",
- "userData": {
- "settingID": "f2a7b51e3503acc6a39b3784ffb84300",
- "pluginVersion": "1.6.0"
}, - "queryID": "a00dbc80a8d13c4565a442e7e2dca80a",
- "hits": [
- {
- "objectID": "test-record-123",
- "_highlightResult": {
- "attribute1": {
- "value": "<em>George</em> <em>Clo</em>oney",
- "matchLevel": "full",
- "matchedWords": [
- "action"
], - "fullyHighlighted": true
}, - "attribute2": {
- "value": "<em>George</em> <em>Clo</em>oney",
- "matchLevel": "full",
- "matchedWords": [
- "action"
], - "fullyHighlighted": true
}
}, - "_snippetResult": {
- "attribute1": {
- "value": "<em>George</em> <em>Clo</em>oney",
- "matchLevel": "full"
}, - "attribute2": {
- "value": "<em>George</em> <em>Clo</em>oney",
- "matchLevel": "full"
}
}, - "_rankingInfo": {
- "filters": 0,
- "firstMatchedWord": 0,
- "geoDistance": 0,
- "geoPrecision": 1,
- "matchedGeoLocation": {
- "lat": 0.1,
- "lng": 0.1,
- "distance": 0
}, - "personalization": {
- "filtersScore": 0,
- "rankingScore": 0,
- "score": 0
}, - "nbExactWords": 0,
- "nbTypos": 0,
- "promoted": true,
- "proximityDistance": 0,
- "userScore": 0,
- "words": 1,
- "promotedByReRanking": true
}, - "_distinctSeqID": 0,
- "_score": 100
}
]
}
]
}
Curate your recommendations with rules, which are if-then statements.
Retrieve a rule
Retrieves a Recommend rule that you previously created in the Algolia dashboard.
path Parameters
indexName required | string Example: YourIndexName Name of the index on which to perform the operation. |
model required | string Enum: "bought-together" "related-products" "trending-facets" "trending-items" |
objectID required | string Example: test-record-123 Unique record identifier. |
Responses
Request samples
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// Initialize the client var client = new RecommendClient(new RecommendConfig("YOUR_APP_ID", "YOUR_API_KEY")); // Call the API var response = await client.GetRecommendRuleAsync( "indexName", Enum.Parse<RecommendModels>("RelatedProducts"), "objectID" );
Response samples
- 200
- 400
- 402
- 403
- 404
{- "_metadata": {
- "lastUpdate": "2023-07-04T12:49:15Z"
}, - "objectID": "string",
- "condition": {
- "filters": "(category:Book OR category:Ebook) AND _tags:published",
- "context": "mobile"
}, - "consequence": {
- "hide": [
- {
- "objectID": "test-record-123"
}
], - "promote": [
- {
- "objectID": "test-record-123",
- "position": 0
}
], - "params": {
- "automaticFacetFilters": [
- {
- "facet": "string",
- "negative": true
}
], - "filters": "(category:Book OR category:Ebook) AND _tags:published",
- "optionalFilters": [
- "category:books<score=1>",
- "category:-movies<score=1>"
]
}
}, - "description": "Display a promotional banner",
- "enabled": true
}
Delete a rule
Deletes a Recommend rule from a recommendation scenario.
path Parameters
indexName required | string Example: YourIndexName Name of the index on which to perform the operation. |
model required | string Enum: "bought-together" "related-products" "trending-facets" "trending-items" |
objectID required | string Example: test-record-123 Unique record identifier. |
Responses
Request samples
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// Initialize the client var client = new RecommendClient(new RecommendConfig("YOUR_APP_ID", "YOUR_API_KEY")); // Call the API var response = await client.DeleteRecommendRuleAsync( "indexName", Enum.Parse<RecommendModels>("RelatedProducts"), "objectID" );
Response samples
- 200
- 400
- 402
- 403
- 404
{- "taskID": 1514562690001,
- "deletedAt": "2023-06-27T14:42:38.831Z"
}
Check task status
Checks the status of a given task.
Deleting a Recommend rule is asynchronous. When you delete a rule, a task is created on a queue and completed depending on the load on the server. The API response includes a task ID that you can use to check the status.
path Parameters
indexName required | string Example: YourIndexName Name of the index on which to perform the operation. |
model required | string Enum: "bought-together" "related-products" "trending-facets" "trending-items" |
taskID required | integer <int64> Example: 1514562690001 Unique task identifier. |
Responses
Request samples
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// Initialize the client var client = new RecommendClient(new RecommendConfig("YOUR_APP_ID", "YOUR_API_KEY")); // Call the API var response = await client.GetRecommendStatusAsync( "indexName", Enum.Parse<RecommendModels>("RelatedProducts"), 12345L );
Response samples
- 200
- 400
- 402
- 403
- 404
{- "status": "notPublished"
}
Search for rules
Searches for Recommend rules.
Use an empty query to list all rules for this recommendation scenario.
path Parameters
indexName required | string Example: YourIndexName Name of the index on which to perform the operation. |
model required | string Enum: "bought-together" "related-products" "trending-facets" "trending-items" |
Request Body schema: application/json
context | string Only search for rules with matching context. |
enabled | boolean Whether to only show rules where the value of their |
facets | Array of strings Include facets and facet values in the response. Use |
filters | string Filter expression. This only searches for rules matching the filter expression. |
hitsPerPage | integer [ 1 .. 1000 ] Default: 20 Maximum number of hits per page. |
maxValuesPerFacet | integer [ 1 .. 1000 ] Maximum number of values to return for each facet. |
page | integer >= 0 Requested page of the API response. |
query | string Default: "" Search query. |
Responses
Request samples
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// Initialize the client var client = new RecommendClient(new RecommendConfig("YOUR_APP_ID", "YOUR_API_KEY")); // Call the API var response = await client.SearchRecommendRulesAsync( "indexName", Enum.Parse<RecommendModels>("RelatedProducts") );
Response samples
- 200
- 400
- 402
- 403
- 404
{- "hits": [
- {
- "_metadata": {
- "lastUpdate": "2023-07-04T12:49:15Z"
}, - "objectID": "string",
- "condition": {
- "filters": "(category:Book OR category:Ebook) AND _tags:published",
- "context": "mobile"
}, - "consequence": {
- "hide": [
- {
- "objectID": "test-record-123"
}
], - "promote": [
- {
- "objectID": "test-record-123",
- "position": 0
}
], - "params": {
- "automaticFacetFilters": [
- {
- "facet": "string",
- "negative": true
}
], - "filters": "(category:Book OR category:Ebook) AND _tags:published",
- "optionalFilters": [
- "category:books<score=1>",
- "category:-movies<score=1>"
]
}
}, - "description": "Display a promotional banner",
- "enabled": true
}
], - "nbHits": 20,
- "page": 0,
- "nbPages": 1
}