| | |
- HNSWPredict(data=None, object=None, id_column=None, vector_column=None, top_k=10, ef_search=32, output_nearestvector=False, output_similarity=False, accumulate=None, single_inputrow=False, **generic_arguments)
- DESCRIPTION:
The HNSWPredict() function accepts the input in "data" argument and
finds the approximate nearest neighbors for the input data points
using the HNSW model generated from HNSW() function.
PARAMETERS:
data:
Required Argument.
Specifies the teradataml DataFrame containing input dataset for
HNSW model input dataset for scoring.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame containing the
HNSW model.
Types: teradataml DataFrame
id_column:
Required Argument.
Specifies the column name containing unique identifier from "data".
Types: str
vector_column:
Required Argument.
Specifies the column from the "data" to be used for training the
HNSW model.
Types: str
top_k:
Optional Argument.
Specifies number of top nearest neighbors to generate in the output.
Default Value: 10
Types: int
ef_search:
Optional Argument.
Specifies the number of neighbors to consider during search in HNSW model.
Default Value: 32
Types: int
output_nearestvector:
Optional Argument.
Specifies whether to output the vector for the nearest neighbor.
Default Value: False
Types: bool
output_similarity:
Optional Argument.
Specifies whether to output similarity of input datapoint to the
nearest vector. If set to false, then the function outputs
distance instead of similarity.
Default Value: False
Types: bool
accumulate:
Optional Argument.
Specifies the input "data" columns to copy to the output.
Types: str OR list of Strings (str)
single_inputrow:
Optional Argument.
Specifies whether input data contains only a single row.
Default Value: False
Types: bool
**generic_arguments:
Specifies the generic keyword arguments SQLE functions accept. Below
are the generic keyword arguments:
persist:
Optional Argument.
Specifies whether to persist the results of the
function in a table or not. When set to True,
results are persisted in a table; otherwise,
results are garbage collected at the end of the
session.
Default Value: False
Types: bool
volatile:
Optional Argument.
Specifies whether to put the results of the
function in a volatile table or not. When set to
True, results are stored in a volatile table,
otherwise not.
Default Value: False
Types: bool
Function allows the user to partition, hash, order or local
order the input data. These generic arguments are available
for each argument that accepts teradataml DataFrame as
input and can be accessed as:
* "<input_data_arg_name>_partition_column" accepts str or
list of str (Strings)
* "<input_data_arg_name>_hash_column" accepts str or list
of str (Strings)
* "<input_data_arg_name>_order_column" accepts str or list
of str (Strings)
* "local_order_<input_data_arg_name>" accepts boolean
Note:
These generic arguments are supported by teradataml if
the underlying SQL Engine function supports, else an
exception is raised.
RETURNS:
Instance of HNSWPredict.
Output teradataml DataFrames can be accessed using attribute
references, such as HNSWPredictObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
# Notes:
# 1. Get the connection to Vantage, before importing the
# function in user space.
# 2. User can import the function, if it is available on
# Vantage user is connected to.
# 3. To check the list of analytic functions available on
# Vantage user connected to, use
# "display_analytic_functions()".
# Load the example data.
load_example_data("teradataml", ["hnsw_data"])
# Create teradataml DataFrame objects.
hnsw_data = DataFrame.from_table("hnsw_data")
# Check the list of available analytic functions.
display_analytic_functions()
# Import function HNSW, HNSWPredict.
from teradataml import HNSW, HNSWPredict
# Example 1 : Find the approximate nearest neighbors for the input data points
# using the HNSW model.
# Generate the HNSW model.
HNSW_out = HNSW(data = hnsw_data,
id_column = "id",
vector_column = "array_col",
seed = 1,
ef_construction = 16,
numconn_pernode = 16,
maxnumconn_pernode = 20,
distance_measure = "EUCLIDEAN",
embedding_size = 2,
apply_heuristics = True
)
# Use the HNSW model to find the approximate nearest neighbors for the input data points.
HNSWPredict_out = HNSWPredict(data = hnsw_data,
object = HNSW_out,
id_column = "id",
vector_column = "array_col",
top_k = 2,
ef_search = 16,
output_nearestvector = True
)
# Print the result DataFrame.
print(HNSWPredict_out.result)
|