Dynamic targetHits in Vespa yql

241 views Asked by At

I'm trying to create a Vespa query where I would like to set the rate limit of the targetHits. For example the query below has a constant number of 3 targetHits:

'yql': 'select id, title from sources * where \
        ([{"targetHits":3}]nearestNeighbor(embeddings_vector,query_embeddings_vector));'

Is there some way I can set this number dynamically in every call?

Also what is the difference between hits and targetHits? Does it have to do with the minimum and desired requirement?

Thanks a lot.

2

There are 2 answers

5
Jo Kristian Bergum On

I'm not sure what you mean by rate limit of targetHits but generally

  • The targetHits is per content node if you run Vespa with multi-node cluster
  • The targetHits is the number of hits you want to expose to the ranking profile's first phase ranking function
  • hits only controls how many to return in the SERP response. It's perfectly valid to ask for targethits 500 per content node for ranking and finally just the global best 10 (according to your ranking profile)
0
Jon On

Is there some way I can set this number dynamically in every call?

You can modify the SQL you send of course, but a better way to do this is often to create a Searcher as part of your application that modifies it programmatically, e.g:

    public class TargetHitsSearcher extends Searcher {
    
        @Override
        public Result search(Query query, Execution execution) {
            Item root = query.getModel().getQueryTree().getRoot();
            if (root instanceof NearestNeighborItem) { // In general; search recursively
                int target = query.properties().getInteger("myTarget");
                ((NearestNeighborItem)root).setTargetNumHits(target);
            }
            return execution.search(query);
        }

    }