Hi David,
the functionality is currently not offered by default (see open issue on github)
There might be a few options and solutions that fit you case, feel free to have a look:

  

      github.com/tensorflow/recommenders
  

  
    
  
	  
  

  
    
      Excluding previously seen items from test recommendations
    

    
      
        opened 
        
          
        
        Oct 14, 2020
      
      


      
        
          
          nialloh23
        
      
    

    
        
          enhancement
        
    
  


  
    In other libraries (e.g. Lightfm) it's common to have a facility to exclude prev…iously seen items from test\eval reccomendations by passing in a set of train_interactions into our evaluation method ([see lightfm approach](https://making.lyst.com/lightfm/docs/lightfm.evaluation.html)). This mimics what we would do in production and as such gives us a more accurate read evaluation results in our offline training.  Without this ability we would find it hard to know if we are overfitting on our training data as the eval results become a lot less meaningful when your real performance is being masked.

I noticed in the tutorials provided it explicitly states that this is approach has not been adopted for TFRS and that we should **"appropriately specify models to learn this behaviour automatically"**.   

1. What does an appropriately specified model in this instance look like? (e.g. do we need to capture sequence behaviour via [RNNS (e.g. like in this paper)](https://arxiv.org/pdf/1902.08588.pdf)? Should including timestamp data as context info in our queries capture this behaviour?)..... is there an intention to provide more details on this?

2. Is it envisaged that a provision will be made to exclude previously interacted with items (or is this a decision that's dictated by the modelling approach?)
  

  

  
    
    
  

  


  

      github.com/tensorflow/recommenders
  

  
    
  
	  
  

  
    
      Save & Serve tfrs that does not recommend items previously interacted with using BruteForce layer
    

    
      
        opened 
        
          
        
        Nov 5, 2021
      
      


      
        
          
          yrianderreumaux
        
      
    

    
    
  


  
    I am working with a relatively small data set and am noticing that users are bei…ng recommended a lot of items they have previously interacted with and I would like to pre-filter out these items before saving and serving the mode on ai platform. I realize this could also be done after the list has been generated, but the way our app works makes it rather difficult (and slow) to filter post hoc on the client side.

I have seen a few other issues addressing related questions (e.g., [307](https://github.com/tensorflow/recommenders/issues/335), [113](https://github.com/tensorflow/recommenders/issues/113)). However, I have not seen a definitive solution, and these seem to deal with either excluding a set of items for all users (rather than a unique set for each user), or excluding items from test recommendations.


Currently, I generate an index with 80 recommended items: `index = tfrs.layers.factorized_top_k.BruteForce(model.user_model, k = 80)`

and then remove any duplicates that existed in the training df: `
index.index_from_dataset(
  tf.data.Dataset.zip((unique_recipe_id_pred.batch(80), unique_recipe_id_pred.batch(80).map(model.recipe_model))))
`

This works well, but how could I also exclude items in the index that users have interacted with? Could the [query with exclusions function](https://www.tensorflow.org/recommenders/api_docs/python/tfrs/layers/factorized_top_k/TopK) be a possible solution?

Apologies if I have missed something here and thanks in advance for any advice!