code: def get_item_item_recommendations(
      model: lightfm.LightFM,
      args: dict,
      item_ids: list = None,
      item_features=None,
  ) -> pd.DataFrame:
      """
      gets similar items to a given item index inside user-item interaction matrix
      NB by default it won't use item features,however if item features are provided
      it will use them to get similar items
  
      :param args:
      :param model:
      :param item_ids:
      :param item_features:
  
      :return:
      """
      # todo make sure its not slow across larger data
      # todo break into smaller functions
  
      n_recommendations = args["n_recommendations"]
  
      similar_items_dfs = []
  
      item_idx_to_id_map = args["item_idx_to_id_map"]
  
      if item_ids:
          # filter out item_ids that are not in the request
          item_idx_to_id_map = {
              key: val
              for key, val in args["item_idx_to_id_map"].items()
              if val in item_ids
          }
  
      for item_idx, item_id in item_idx_to_id_map.items():
          # ensure item_idx is int
          item_idx = int(item_idx)
  
          (
              item_biases,
              item_representations,
          ) = model.get_item_representations(features=item_features)
  
          # Cosine similarity
          scores = item_representations.dot(
              item_representations[item_idx, :]
          )
  
          # normalize
          item_norms = np.sqrt(
              (item_representations * item_representations).sum(axis=1)
          )
          scores /= item_norms
  
          # ensure n_recommendations is not greater than number of recommendations
          N = min(len(scores), n_recommendations)
  
          # get the top N items
          best = np.argpartition(scores, -N)
  
          # sort the scores
          rec = sorted(
              zip(best, scores[best] / item_norms[item_idx]),
              key=lambda x: -x[1],
          )
  
          intermediate_df = (
              pd.DataFrame(rec, columns=["item_idx", "score"])
              .tail(-1)  # remove the item itself
              .head(N)
          )
  
          intermediate_df["item_id_one"] = item_id
          similar_items_dfs.append(intermediate_df)
  
      similar_items_df = pd.concat(similar_items_dfs, ignore_index=True)
      similar_items_df["item_idx"] = similar_items_df[
          "item_idx"
      ].astype("str")
  
      similar_items_df["item_id_two"] = similar_items_df[
          "item_idx"
      ].map(args["item_idx_to_id_map"])
  
      return similar_items_df[["item_id_one", "item_id_two", "score"]]
  
imports: import lightfm
  import numpy
  import pandas
label_desc: Use image node_id 3 for calling a global function with example usage: get_item_item_recommendations(model, args, item_ids, item_features) and returns: similar_items_df