> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get recommendations

> Get recommendations from any Algolia recommendation model.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Retrieve recommendations" href="/doc/libraries/sdk/methods/recommend/get-recommendations" />

**Required ACL:** `search`

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  public class Product
  {
      public string ObjectID { get; set; }
      public string Name { get; set; }
      public string Category { get; set; }
      public float Price { get; set; }
  }

  public class RecommendedProduct : Product, Algolia.Search.Models.Recommend.IRecommendHit
  {
      public float Score { get; set; }
  }

  var requests = new List<Algolia.Search.Models.Recommend.RecommendRequest> {
    new Algolia.Search.Models.Recommend.RecommendRequest {
        IndexName = "INDEX_NAME",
        ObjectID = "your_object_id",
        Model = "bought-together",
    }
  }

  var recommendations = recommendClient.GetRecommendations<RecommendedProduct>(requests);

  // Asynchronous
  var recommendations =
    await recommendClient.GetRecommendationsAsync<RecommendedProduct>(requests);
  ```

  ```go Go theme={"system"}
  options := recommend.RecommendationsOptions{IndexName: "IndexName", ObjectID: "B018APC4LE", Model: recommend.BoughtTogether}
  res, err = recommendClient.GetRecommendations([]recommend.RecommendationsOptions{options})
  ```

  ```java Java theme={"system"}
  class Product implements RecommendHit {
      String objectID;
      String name;
      Float score;

      @Nonnull
      @Override
      public Float getScore() { return score; }
      public void setScore(Float score) { this.score = score; }

      public String getObjectID() { return objectID; }
      public void setObjectID(String objectID) { this.objectID = objectID; }

      public String getName() { return name; }
      public void setName(String name) { this.name = name; }
    }

  RecommendationsQuery query = new RecommendationsQuery("yourIndexName", "bought-together", "yourObjectID");

  // Synchronous
  List<RecommendationsResult<Product>> recommendations = recommendClient.getRecommendations(Arrays.asList(query), Product.class);

  // Asynchronous
  CompletableFuture<List<RecommendationsResult<Product>>> recommendations = recommendClient.getRecommendationsAsync(Arrays.asList(query), Product.class);
  ```

  ```js JavaScript theme={"system"}
  recommendClient
    .getRecommendations([
      {
        indexName: "INDEX_NAME",
        objectID: "your_object_id",
        model: "bought-together",
      },
    ])
    .then(({ results }) => {
      console.log(results);
    })
    .catch((err) => {
      console.log(err);
    });
  ```

  ```kotlin Kotlin theme={"system"}
  val request = RecommendationsQuery(
      indexName = IndexName("yourIndexName"),
      objectID = ObjectID("yourObjectID"),
      model = RecommendationModel.BoughtTogether,
  )

  val recommendations = recommendClient.getRecommendations(requests = listOf(request))
  ```

  ```php PHP theme={"system"}
  $recommendations = $recommend_client->getRecommendations([
    [
      'indexName' => 'INDEX_NAME',
      'objectID' => 'your_object_id',
      'model' => 'bought-together',
    ],
  ]);
  ```

  ```python Python theme={"system"}
  recommendations = recommend_client.get_recommendations(
      [
          {
              "indexName": "INDEX_NAME",
              "objectID": "your_object_id",
              "model": "bought-together",
          },
      ]
  )
  ```

  ```ruby Ruby theme={"system"}
  recommendations = recommend_client.get_recommendations(
    [
      {
        indexName: "INDEX_NAME",
        objectID: "your_object_id",
        model: "bought-together"
      }
    ]
  )
  ```

  ```scala Scala theme={"system"}
  recommendClient.execute {
    val query = RecommendationsQuery(
      indexName = "yourIndexName",
      model = "bought-together",
      objectID = "yourObjectID",
    )
    get recommendations List(query)
  }
  ```

  ```swift Swift theme={"system"}
  let options = RecommendationsOptions(indexName: "IndexName",
                                       model: .boughtTogether,
                                       objectID: "B018APC4LE")
    recommendClient.getRecommendations(options: [options]) { result in 
      if case .success(let response) = result {
        print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="requests" type="object[]" required>
  <Expandable>
    <ParamField body="facetName" type="string" required>
      Facet attribute for which to get recommendations.
    </ParamField>

    <ParamField body="indexName" type="string" required>
      Name of the index.
    </ParamField>

    <ParamField body="model" type="enum<string>" required>
      Name of the recommendation model to use.
      One of: `bought-together`, `related-products`, `trending-items`, `trending-facets`.
    </ParamField>

    <ParamField body="objectID" type="string" required>
      Object ID for which to get recommendations.
    </ParamField>

    <ParamField body="threshold" type="number" required>
      Threshold for the recommendations confidence score (between 0 and 100).
      Only recommendations with a greater score are returned.
    </ParamField>

    <ParamField body="facetValue" type="string">
      Facet value for which to get recommendations for. This parameter must be used along with #{facetName}.
    </ParamField>

    <ParamField body="fallbackParameters" type="object">
      [Search parameters](/doc/api-reference/search-api-parameters) to use as fallback when there are no recommendations.
    </ParamField>

    <ParamField body="maxRecommendations" type="integer">
      Maximum number of recommendations to retrieve.
      Depending on the available recommendations and the other request parameters,
      the actual number of recommendations may be lower.
      If you don't set `maxRecommendations` or set it to 0,
      all matching recommendations are returned, and no fallback request is performed.
    </ParamField>

    <ParamField body="queryParameters" type="object">
      [Search parameters](/doc/api-reference/search-api-parameters) for filtering the recommendations.
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="results" type="object[]">
  List of results in the order they were submitted, one per query.

  **Example:**

  ```jsonc JSON icon=braces theme={"system"}
  {
    "results": [
      {
        "hits": [
          {
            // ...,
            "_score": 32.72
          }
        ],
      },
    ]
  }
  ```

  <Expandable>
    <ResponseField name="_score" type="number">
      Confidence score of the recommended item. The closer it is to 100, the more relevant.
    </ResponseField>
  </Expandable>
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "results": [
    {
      "hits": [
        {
          "_highlightResult": {
            "category": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Men - T-Shirts"
            },
            "image_link": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "https://example.org/image/D05927-8161-111-F01.jpg"
            },
            "name": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Jirgi Half-Zip T-Shirt"
            }
          },
          "_score": 32.72,
          "category": "Men - T-Shirts",
          "image_link": "https://example.org/image/D05927-8161-111-F01.jpg",
          "name": "Jirgi Half-Zip T-Shirt",
          "objectID": "D05927-8161-111",
          "position": 105,
          "url": "men/t-shirts/d05927-8161-111"
        }
      ],
      "processingTimeMS": 1,
    }
  ]
}
```
