| | |
- HNSW(data=None, object=None, id_column=None, vector_column=None, num_layer=None, seed=None, ef_construction=32, numconn_pernode=32, maxnumconn_pernode=32, distance_measure='EUCLIDEAN', embedding_size=None, apply_heuristics=False, alter_operation=None, delete_method='RECONSTRUCTION', **generic_arguments)
- DESCRIPTION:
The Hierarchical Navigable Small World(HNSW) function generates
the HNSW model using the input data points which is then used by
HNSWPredict() function for determining the approximate nearest neighbors
for any given input data point.
PARAMETERS:
data:
Required Argument.
Specifies the teradataml DataFrame containing input dataset for
HNSW model training/update/delete operation.
Types: teradataml DataFrame
object:
Optional Argument.
Specifies the teradataml DataFrame containing the HNSW model for
update/delete operation.
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 containing the vector embeddings.
Types: str
num_layer:
Optional Argument.
Specifies the maximum number of layers for the HNSW model.
Types: int
seed:
Optional Argument.
Specifies the random seed value for repeatable results.
DefaultValue : Any random number
Types: int
ef_construction:
Optional Argument.
Specifies number of neighbors to search during training of HNSW
model.
Default Value: 32
Types: int
numconn_pernode:
Optional Argument.
Specifies number of connections for a node during training of HNSW
model.
Default Value: 32
Types: int
maxnumconn_pernode:
Optional Argument.
Specifies maximum number of connections allowed for a node during
training of HNSW model.
Default Value: 32
Types: int
distance_measure:
Optional Argument.
Specifies the distance measure to be used for distance computation.
Default Value: "EUCLIDEAN"
Permitted Values: EUCLIDEAN, COSINE, DOTPRODUCT
Types: str
embedding_size:
Optional Argument.
Specifies the embedding size of the vectors.
Types: int
apply_heuristics:
Optional Argument.
Specifies whether to apply heuristics optimizations during training of
HNSW model.
Default Value: False
Types: bool
alter_operation:
Required when "object" is specified, otherwise optional argument.
Specifies the alter operation for HNSW model.
Permitted Values:
* UPDATE: Insert new nodes into existing HNSW graph.
* DELETE: Delete specified nodes from existing HNSW graph.
Types: str OR list of strs
delete_method:
Optional Argument.
Specifies the method for delete operation.
Default Value: "RECONSTRUCTION"
Permitted Values:
* RECONSTRUCTION: HNSW graph gets reconstructed after deletion of nodes
from existing HNSW graph.
* DELETENODE: Only the specified nodes get deleted from existing HNSW graph
without any reconstruction.
Types: str OR list of strs
**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 HNSW.
Output teradataml DataFrames can be accessed using attribute
references, such as HNSWObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
1. result
2. model_data
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", "hnsw_alter_data"])
# Create teradataml DataFrame objects.
hnsw_data = DataFrame.from_table("hnsw_data")
hnsw_alter_data = DataFrame.from_table("hnsw_alter_data")
# Check the list of available analytic functions.
display_analytic_functions()
# Import function HNSW.
from teradataml import HNSW
# Example 1 : Generate HNSW model using input data points present in "array_col" column.
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
)
# Print the result DataFrame.
print(HNSW_out.result)
print(HNSW_out.model_data)
# Example 2 : Update the HNSW model by inserting new nodes from 'hnsw_alter_data' DataFrame.
HNSW_update = HNSW(data = hnsw_alter_data,
object = HNSW_out,
id_column = "id",
vector_column = "array_col",
alter_operation = "UPDATE"
)
# Print the result DataFrame.
print(HNSW_update.result)
print(HNSW_update.model_data)
# Example 3 : Update the HNSW model by deleting specified nodes from 'hnsw_alter_data' DataFrame.
HNSW_delete = HNSW(data = hnsw_alter_data,
object = HNSW_out,
id_column = "id",
vector_column = "array_col",
alter_operation = "DELETE"
)
# Print the result DataFrame.
print(HNSW_delete.result)
print(HNSW_delete.model_data)
|