set_function

The function set_function(score_function_name, collection_name, function_name) sets a score function as part of Lexical Search or Hybrid Search. This step is mandatory.

Input -

  • score_function_name – Specifies one of the following

    • The name and path of the file containing the logic to be used in the search query, which is described in step #1 above. This loads the contents of this file to a local object.

    • The name of the function containing the logic to be used in the search

  • collection_name – Specifies the name of the Collection that contains the data to be searched.

  • function_name – Assigns the score function a local object name to be used later when running the search query.

Example 1-

hyperspace_client.set_function(score_function_filename = "sf.py",
                               collection_name=collection_name,
                               function_name='score_function')

In this example, the score function is set from a file named "sf.py"

Example 2-

def keyword_matching(params, doc):
    score = 0
    if match('keywords'):
        score = rarity_sum('keywords')
    return score + 2 * distance('img_clip', min_score=0.01) *  distance('txt_clip', min_score=0.01) + 1

hyperspace_client.set_function(keyword_matching, collection_name = collection_name , function_name='keyword_matching')

In this example, the score function is set from a python function named "keyword_matching"

The set_function module is optimized for performance. When used repeatedly with recurring value of function_name, the set_function module compares the new score function with the previously set one and will only be activated if the two are not identical.

Last updated