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

# Items-For-Item Recommendations

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/4/fusion-ai/concepts/boosting/items-for-item

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-ai/concepts/boosting/items-for-item

[old doc.lw link]: https://doc.lucidworks.com/fusion/5.9/476

Items-for-item recommendations present items that are similar to a specified item. For example, when the user is viewing a BMX bicycle, Fusion can recommend other BMX bicycles. Similarity can be based on different criteria, such as click patterns, people who bought this also bought that, percentage match of document tags, and so on.

<LwTemplate />

## Collaborative items-for-item recommendations

If you have enabled signals and recommendations for a collection, then the default `COLLECTION_NAME_item_recommendations` job is already created and configured to produce items-for-item recommendations (as well as [items-for-user recommendations](/docs/4/fusion-ai/concepts/boosting/items-for-user)):

<img src="https://mintcdn.com/lucidworks/vupE2UCZdg04NdXx/assets/images/4.2/recommendations_job_default.png?fit=max&auto=format&n=vupE2UCZdg04NdXx&q=85&s=c69e5e6a2855522f4110a73090d3f265" alt="Default recommendations job" width="2562" height="1284" data-path="assets/images/4.2/recommendations_job_default.png" />

This is an [ALS Recommender](/docs/4/fusion-ai/reference/jobs/als-recommender) job.

<Tip>
  If you want to use different parameters for items-for-item recommendations and [items-for-user recommendations](/docs/4/fusion-ai/concepts/boosting/items-for-user), simply create separate jobs for each, where one job configuration includes an output collection for items-for-item recommendations only and the other includes an output collection for items-for-user recommendations only.
</Tip>

## Learn more

<Accordion title="Fetch Items-for-Item Recommendations (Collaborative/ALS Method)">
  <Note>The BPR method is recommended and the ALS method is deprecated.</Note>

  If you have enabled signals and recommendations for a collection, then the `_items_for_item_recommendations` query pipeline is created by default and configured to fetch items-for-item recommendations using the output from the ALS Recommender job. It is similar to the default query pipeline that fetches content from your main collection, but it has an additional Recommend Items for Item stage:

  <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/recommendations-item-item-pipeline.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=ef5c904764d92788f02c6ef15ef1e018" alt="Default items-for-item recommendations pipeline" width="2562" height="1284" data-path="assets/images/4.2/recommendations-item-item-pipeline.png" />

  This pipeline is a template that you can use two different ways:

  * [Use *only* the Recommend Items for Item stage](#fetching-with-the-recommend-items-for-item-stage)\
    This method returns only the document IDs of the recommended items. Your search application must perform additional queries to retrieve the desired fields for those items, such as their names, images, categories, and so on.
  * [Query Solr directly](#querying-solr-directly)\
    This method returns complete documents about the recommended items from the `_items_for_item_recommendations` collection. The fields that are included in these recommender documents are configured in the recommender job’s `itemMetadataJoinField` **Item Metadata Join Field** and `itemMetadataFields` **Item Metadata Fields** fields.

  ## Fetching recommendations from App Studio

  App Studio can only access user-created collections; it cannot access system collections such as the default collections that Fusion creates for recommendations. If you are using App Studio to create your front-end search application, you must:

  * Create a new collection for item-for-item recommendations
  * Configure the recommender job to send output to the user-created collection instead of the system collection
  * Direct your queries to the user-created collection

  Once this is done, you can fetch recommendations as usual, using either of the methods explained below.

  ## Fetching with the Recommend Items for Item stage

  With this method, we use only one query pipeline stage: the Recommend Items for Item query stage. This stage works with the output from the ALS Recommender job.

  This method returns only the document IDs of the recommended items. Your search application must perform additional queries to retrieve the desired fields for those items, such as their names, images, categories, and so on.

  **How to fetch recommendations using the Recommend Items for Item stage**

  1. From your  `_items_for_item_recommendations` collection, navigate to **Querying** > **Query Workbench**.

  <Tip>
    If this collection is empty, you must run one of the items-for-item recommender jobs.
  </Tip>

  2. Click **Load...** and open the  `_items_for_item_recommendations` query pipeline, if it is not open already.
  3. Disable all of the pipeline stages *except* Recommend Items for Item.
  4. Verify that the following fields are correctly configured in the Recommend Items for Item query stage:
     * `numRecommendations`/**Number of Recommendations**\
       This is the number of recommendations to return. It should be less than or equal to the value of the `numSims`/**Number of Item Similarities to Compute** parameter in the model tuning parameters of the `COLLECTION_NAME_item_recommendations` job configuration.
     * `modelID`/**Model ID**\
       This must match the `modelId`/**Recommender Model ID** value in the recommender job’s model settings.
     * `collection`/**Recommendation Collection**\
       This should be the collection specified in the `outputItemSimCollection`/**Item-to-item Similarity Collection** parameter of the recommender job’s Input/output settings.
     * `resultsLocation`/**Results Location**\
       Select the **As Response** value for this field.
     * There are several fields that specify the names of fields that should be present in the documents in the `_items_for_item_recommendations` collection. Verify that these values match the field names in that collection.
     * To use live signals in addition to historical signals, enable **Estimate Recent Results**.\
       Be sure to click **Apply** after changing any of the stage configuration parameters.\
       <Note>   At this point, the results panel should display "No Search Results". This is normal; we will see results at a later step.</Note>
  5. Click **Save**.

  <Tip>
    Save the modified pipeline as a new pipeline with a different name, to distinguish it from the default pipeline.
  </Tip>

  6. Test the pipeline configuration:
     1. Select an item from your main collection to use for testing.
        1. Navigate to your main collection and open the Query Workbench.
        2. Search for an item and copy the value of its `id` field.
        3. Return to the `_items_for_item_recommendations` collection and the Query Workbench.
     2. Click **Parameters**.
     3. Click **Edit Parameters**.\
        The **Parameters and Values** window appears.
     4. Click the Add <img className="inline-image" alt="Add icon" src="https://mintcdn.com/lucidworks/5yWZ-KtZuBe4Y_Fg/assets/images/4.0/icons/add-icon.png?fit=max&auto=format&n=5yWZ-KtZuBe4Y_Fg&q=85&s=4a774a0fe7398e91eb7273f8e8aff7be" width="44" height="42" data-path="assets/images/4.0/icons/add-icon.png" /> icon.
     5. Enter the parameter name `item_id` and the value that you copied from the `id` field of the item in your main collection.\\
          <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/recommendations-items-for-item-item_id.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=02fdfb027c5521790586f9e3e822ab36" alt="item_id query parameter" width="2562" height="1284" data-path="assets/images/4.2/recommendations-items-for-item-item_id.png" />
     6. Click **Close** to close the **Parameters and Values** window.
     7. In the lower right, select **View As: JSON**:
          <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/query-workbench-view-as-json.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=ade6bdc004787e18a8e4d8bdc8225a4f" alt="View as JSON" width="715" height="397" data-path="assets/images/4.2/query-workbench-view-as-json.png" />
        Notice that the search results contain only a document ID and a weight, as you can see when you expand the `items` field and any of its `Object` fields:
          <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/recommendations-items-for-item-stage-only.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=c3a2d3f14415ce3f126d515798a6a67c" alt="Recommend Items for Item query stage" width="2562" height="1284" data-path="assets/images/4.2/recommendations-items-for-item-stage-only.png" />

  <Tip>
    If the `items` field is empty, choose another item from your main collection and update the `item_id` query parameter to match it. Some items in your main collection may have no recommendations.
  </Tip>

  7. Get the query URI that your search application can use to retrieve recommendations from your modified pipeline:
     1. Click **URI**.\
        The Query Workbench displays a **Working URI** and a **Published URI**.\\
          <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/recommendations-items-for-item-uri.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=8fcd5d27954fa183b2001632643d2ff1" alt="Query URI" width="2562" height="1284" data-path="assets/images/4.2/recommendations-items-for-item-uri.png" />
     2. Click the **Published URI** to copy it to your clipboard.\
        This is the URI and parameters that your search application should use to query for additional recommendations.

  **Tips:**

  * Each time you query for recommendations, replace the `item_id` parameter value with the ID of the item for which you want recommendations.
  * Replace the Fusion hostname as needed, depending on your production environment.
  * As shown above, Fusion returns an array of document IDs and weights. Your search application must then query the main collection to retrieve the details about each of the recommended documents.

    That is, for each `docId` value returned from the recommendations collection, query for the corresponding `id` value in the main collection, and order the set of results according to the `weight` value from the recommendations collection.

  ## Querying Solr directly

  With this method, we use only the Solr Query pipeline stage.

  This method returns only the document IDs of the recommended items. Your search application must perform additional queries to retrieve the desired fields for those items, such as their names, images, categories, and so on.

  **How to fetch recommendations using the Solr Query stage**

  1. From your `_items_for_item_recommendations` collection, navigate to **Querying** > **Query Workbench**.
  2. Click **Load**.
  3. Select the `_items_for_item_recommendations` query pipeline.
  4. Disable all stages in the pipeline *except* the Solr Query stage.
  5. Click **Save**.

  <Tip>
    Save the modified pipeline as a new pipeline with a different name, to distinguish it from the default pipeline.
  </Tip>

  6. Test the pipeline configuration:
     1. Select an item from your main collection to use for testing.
        1. Navigate to your main collection and open the Query Workbench.
        2. Search for an item and copy the value of its `id` field.
        3. Return to the `_items_for_item_recommendations` collection and the Query Workbench.
     2. In the search field, enter the parameter name `itemId` and the value that you copied from the `id` field of the item in your main collection.\
        For example, enter `itemId:10463303` (substituting the value from your main collection) and click the Search button.\
        The number of results should be the same as the `numRecs`/**Number of User Recommendations to Compute** value in the `_item_recommendations` job (the default is 10).
       <Tip>
         If the results panel displays "No Search Results", choose another item from your main collection and update the `item_id` query parameter to match it. Some items in your main collection may have no recommendations.
       </Tip>
     3. In any of the search results, click **show fields**.\
        Notice these important fields:
        * `itemId` is the original item to which the recommendation pertains.
        * `otherItemId` is the recommended item.
        * `sim` is the similarity score, or the estimated likelihood that the recommended item is related to the original item.
  7. Get the query URI that your search application can use to retrieve recommendations from your modified pipeline:
     1. Click **URI**.\
        The Query Workbench displays a **Working URI** and a **Published URI**.\\
          <img src="https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/recommendations-items-for-item-uri-solr.png?fit=max&auto=format&n=1R8QVvJzt46cZDT6&q=85&s=80ec3a476f6fa00230556055cdcc258d" alt="Query URI" width="2562" height="1284" data-path="assets/images/4.2/recommendations-items-for-item-uri-solr.png" />
     2. Click the **Published URI** to copy it to your clipboard.\
        This is the URI and parameters that your search application should use to query for additional recommendations.

  **Tips:**

  * Each time you query for recommendations, replace the `itemId` parameter value with the ID of the item for which you want recommendations.
  * Replace the Fusion hostname as needed, depending on your production environment.
  * As shown above, Fusion returns a set of results that each include an `otherItemId` and a `sim` score. Your search application must then query the main collection to retrieve the details about each of the recommended documents.

    That is, for each `otherItemId` value returned from the recommendations collection, query for the corresponding `id` value in the main collection, and order the set of results according to the `sim` value from the recommendations collection.

  <Tip>
    You can eliminate these additional queries by configuring the join field and item metadata fields in the `_item_recommendations` job’s Item metadata settings. This copies the specified metadata fields from the main collection into the recommendations collection so that they can be retrieved in a single query. For example, if you specify `name`, `url`, `category`, `image`, or similar fields in the job configuration, then those are returned in the recommender results without the need for additional queries.
  </Tip>
</Accordion>
