-
Notifications
You must be signed in to change notification settings - Fork 7
User Defined Function Usage
This query will execute objects_inference over metadata and return the inference results.
async def async_objects_inference(blob_id):
for service in aidb_engine._config.inference_bindings:
if service.service.name == 'objects00':
inference_service = service
# replaced by your own ML inference
outputs = await inference_service.infer(blob_id)
return outputs[0]
def objects_inference(blob_id):
df = pd.DataFrame({'blob_id': [blob_id]})
return asyncio_run(async_objects_inference(df))
This query will return matched pairs of text and image.
# Pseudo code
def is_match(img, text, threshold):
match_pro = CLIP_model(img, text)
if match_pro > threshold:
return True
else:
return False
By utilizing SQL queries with UDFs for data filtering, you can bypass the need for coding logical operations and frequently modifying filtering conditions in the code after obtaining the function results.
If the User Defined Function produces multiple output columns, direct filtering on specific UDF outputs is still feasible by assigning aliases to these outputs.
-
No output: we will drop that input row.
-
Single value: like integer or float value.
-
Multiple rows outputs: using a list of elements (e.g. [1, 2, 3]) or dataframe (e.g. pd.Dataframe({'x': [1, 2, 3]})).
-
Multiple columns outputs: using a list of tuple (e.g. [(1, 2, 3)] or dataframe (e.g. pd.Dataframe({'x': [1], 'y':[2], 'z':[3]}))