Similarity Algorithms

class graphdatascience.procedure_surface.api.similarity.KnnEndpoints

Bases:

abstractmethod estimate(G: Graph | dict[str, Any], node_properties: str | list[str] | dict[str, str], top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None) → EstimationResult

Estimates the memory requirements for running the K-Nearest Neighbors algorithm.

Parameters:
  • G (Graph | dict[str, Any]) – Graph object to use or a dictionary representing the graph dimensions.

  • node_properties (str | list[str] | dict[str, str],) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id – Identifier for the computation.

Returns:

Object containing the estimated memory requirements.

Return type:

EstimationResult

abstract property filtered: KnnFilteredEndpoints
abstractmethod mutate(G: Graph, mutate_relationship_type: str, mutate_property: str, node_properties: str | list[str] | dict[str, str], top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → KnnMutateResult

Runs the K-Nearest Neighbors algorithm and stores the results as new relationships in the graph catalog.

Parameters:
  • G (Graph) – Graph object to use

  • mutate_relationship_type (str) – Name of the relationship type to store the results in.

  • mutate_property (str) – Name of the node property to store the results in.

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing metadata from the execution.

Return type:

KnnMutateResult

abstractmethod stats(G: Graph, node_properties: str | list[str] | dict[str, str], top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → KnnStatsResult

Runs the K-Nearest Neighbors algorithm and returns execution statistics.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str],) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing execution statistics and algorithm-specific results.

Return type:

KnnStatsResult

abstractmethod stream(G: Graph, node_properties: str | list[str] | dict[str, str], top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → DataFrame

Runs the K-Nearest Neighbors algorithm and returns the result as a DataFrame.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str],) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

The similarity results as a DataFrame with columns ‘node1’, ‘node2’, and ‘similarity’.

Return type:

pandas.DataFrame

abstractmethod write(G: Graph, write_relationship_type: str, write_property: str, node_properties: str | list[str] | dict[str, str], top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None, write_concurrency: int | None = None) → KnnWriteResult

Runs the K-Nearest Neighbors algorithm and writes the results back to the database.

Parameters:
  • G (Graph) – Graph object to use

  • write_relationship_type (str) – Name of the relationship type to store the results in.

  • write_property (str) – Name of the node property to store the results in.

  • node_properties (str | list[str] | dict[str, str],) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • write_concurrency (int | None) – Number of concurrent threads to use for writing.Returns

  • -------

  • KnnWriteResult – Object containing metadata from the execution.

Return type:

KnnWriteResult

class graphdatascience.procedure_surface.api.similarity.KnnFilteredEndpoints

Bases:

abstractmethod estimate(G: Graph | dict[str, Any], node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, username: str | None = None, concurrency: int | None = None) → EstimationResult

Estimates the memory requirements for running the Filtered K-Nearest Neighbors algorithm.

The Filtered K-Nearest Neighbors algorithm computes a distance value for node pairs in the graph with customizable source and target node filters, creating new relationships between each node and its k nearest neighbors within the filtered subset.

Parameters:
  • G (Graph | dict[str, Any]) – Graph object to use or a dictionary representing the graph dimensions.

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

Returns:

Object containing the estimated memory requirements.

Return type:

EstimationResult

abstractmethod mutate(G: Graph, mutate_relationship_type: str, mutate_property: str, node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → KnnMutateResult

Runs the Filtered K-Nearest Neighbors algorithm and stores the results as new relationships in the graph catalog.

The Filtered K-Nearest Neighbors algorithm computes a distance value for node pairs in the graph with customizable source and target node filters, creating new relationships between each node and its k nearest neighbors within the filtered subset.

Parameters:
  • G (Graph) – Graph object to use

  • mutate_relationship_type (str) – Name of the relationship type to store the results in.

  • mutate_property (str) – Name of the node property to store the results in.

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing metadata from the execution.

Return type:

KnnMutateResult

abstractmethod stats(G: Graph, node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → KnnStatsResult

Runs the Filtered K-Nearest Neighbors algorithm and returns execution statistics.

The Filtered K-Nearest Neighbors algorithm computes a distance value for node pairs in the graph with customizable source and target node filters, creating new relationships between each node and its k nearest neighbors within the filtered subset.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing execution statistics and algorithm-specific results.

Return type:

KnnStatsResult

abstractmethod stream(G: Graph, node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → DataFrame

Runs the Filtered K-Nearest Neighbors algorithm and returns the result as a DataFrame.

The Filtered K-Nearest Neighbors algorithm computes a distance value for node pairs in the graph with customizable source and target node filters, creating new relationships between each node and its k nearest neighbors within the filtered subset.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

The similarity results as a DataFrame with columns ‘node1’, ‘node2’, and ‘similarity’.

Return type:

pandas.DataFrame

abstractmethod write(G: Graph, write_relationship_type: str, write_property: str, node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], write_concurrency: int | None = None, sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → KnnWriteResult

Runs the Filtered K-Nearest Neighbors algorithm and writes the results back to the database.

The Filtered K-Nearest Neighbors algorithm computes a distance value for node pairs in the graph with customizable source and target node filters, creating new relationships between each node and its k nearest neighbors within the filtered subset.

Parameters:
  • G (Graph) – Graph object to use

  • write_relationship_type (str) – Name of the relationship type to store the results in.

  • write_property (str) – Name of the node property to store the results in.

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • write_concurrency (int | None) – Number of concurrent threads to use for writing.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing metadata from the execution.

Return type:

KnnWriteResult

class graphdatascience.procedure_surface.api.similarity.KnnFilteredSessionEndpoints

Bases: KnnFilteredEndpoints

KnnFiltered endpoints as exposed by a GDS Session.

abstractmethod compute(G: Graph, node_properties: str | list[str] | dict[str, str], source_node_filter: str, target_node_filter: str, *, seed_target_nodes: bool = False, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → JobHandle

Starts the computation as a job and returns a handle to it.

The computation runs without materializing its result. Use the returned handle to mutate, write or stream the result afterwards.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • source_node_filter (str) – A Cypher expression to filter which nodes can be sources in the similarity computation.

  • target_node_filter (str) – A Cypher expression to filter which nodes can be targets in the similarity computation.

  • seed_target_nodes (bool) – Whether to use a seeded approach for target node selection.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Handle to the started computation

Return type:

JobHandle

class graphdatascience.procedure_surface.api.similarity.KnnMutateResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
did_converge: bool
mutate_millis: int
node_pairs_considered: int
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
ran_iterations: int
relationships_written: int
similarity_distribution: dict[str, int | float]
class graphdatascience.procedure_surface.api.similarity.KnnSessionEndpoints

Bases: KnnEndpoints

Knn endpoints as exposed by a GDS Session.

abstractmethod compute(G: Graph, node_properties: str | list[str] | dict[str, str], *, top_k: int = 10, similarity_cutoff: float = 0.0, delta_threshold: float = 0.001, max_iterations: int = 100, sample_rate: float = 0.5, perturbation_rate: float = 0.0, random_joins: int = 10, random_seed: int | None = None, initial_sampler: str = 'UNIFORM', relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → JobHandle

Starts the computation as a job and returns a handle to it.

The computation runs without materializing its result. Use the returned handle to mutate, write or stream the result afterwards.

Parameters:
  • G (Graph) – Graph object to use

  • node_properties (str | list[str] | dict[str, str]) – Node properties to use for the similarity computation.

  • top_k (int) – Number of most similar nodes to return for each node.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • delta_threshold (float) – Minimum change between iterations.

  • max_iterations (int) – Maximum number of iterations to run.

  • sample_rate (float) – The sampling rate for the algorithm.

  • perturbation_rate (float) – The rate at which to perturb the similarity graph.

  • random_joins (int) – The number of random joins to perform.

  • random_seed (int | None) – Seed for random number generation to ensure reproducible results.

  • initial_sampler (str) – Sampling strategy for the initial nearest neighbors.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Handle to the started computation

Return type:

JobHandle

abstract property filtered: KnnFilteredSessionEndpoints

Access to the filtered K-Nearest Neighbors endpoints.

class graphdatascience.procedure_surface.api.similarity.KnnStatsResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
did_converge: bool
node_pairs_considered: int
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
ran_iterations: int
similarity_distribution: dict[str, int | float]
similarity_pairs: int
class graphdatascience.procedure_surface.api.similarity.KnnWriteResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
did_converge: bool
node_pairs_considered: int
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
ran_iterations: int
relationships_written: int
similarity_distribution: dict[str, int | float]
write_millis: int
class graphdatascience.procedure_surface.api.similarity.NodeSimilarityEndpoints

Bases:

abstractmethod estimate(G: Graph, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, username: str | None = None, concurrency: int | None = None) → EstimationResult

Estimates the memory requirements for running the Node Similarity algorithm.

Parameters:
  • G (Graph) – Graph object to use

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

Returns:

Object containing the estimated memory requirements.

Return type:

EstimationResult

abstract property filtered: NodeSimilarityFilteredEndpoints
abstractmethod mutate(G: Graph, mutate_relationship_type: str, mutate_property: str, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → NodeSimilarityMutateResult

Runs the Node Similarity algorithm and stores the results as new relationships in the graph catalog.

Parameters:
  • G (Graph) – Graph object to use

  • mutate_relationship_type (str) – Name of the relationship type to store the results in.

  • mutate_property (str) – Name of the node property to store the results in.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing metadata from the execution.

Return type:

NodeSimilarityMutateResult

abstractmethod stats(G: Graph, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → NodeSimilarityStatsResult

Runs the Node Similarity algorithm and returns execution statistics.

Parameters:
  • G (Graph) – Graph object to use

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing execution statistics and algorithm-specific results.

Return type:

NodeSimilarityStatsResult

abstractmethod stream(G: Graph, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → DataFrame

Runs the Node Similarity algorithm and returns the result as a DataFrame.

Parameters:
  • G (Graph) – Graph object to use

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

The similarity results as a DataFrame with columns ‘node1’, ‘node2’, and ‘similarity’.

Return type:

pandas.DataFrame

abstractmethod write(G: Graph, write_relationship_type: str, write_property: str, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None, write_concurrency: int | None = None) → NodeSimilarityWriteResult

Runs the Node Similarity algorithm and writes the results back to the database.

Parameters:
  • G (Graph) – Graph object to use

  • write_relationship_type (str) – Name of the relationship type to store the results in.

  • write_property (str) – Name of the node property to store the results in.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • write_concurrency (int | None) – Number of concurrent threads to use for writing.Returns

  • -------

  • NodeSimilarityWriteResult – Object containing metadata from the execution.

Return type:

NodeSimilarityWriteResult

class graphdatascience.procedure_surface.api.similarity.NodeSimilarityFilteredEndpoints

Bases:

abstractmethod estimate(G: Graph | dict[str, Any], source_node_filter: str | list[int], target_node_filter: str | list[int], top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, username: str | None = None, concurrency: int | None = None) → EstimationResult

Estimates the memory requirements for running the Filtered Node Similarity algorithm.

Parameters:
  • G (Graph | dict[str, Any]) – Graph object to use or a dictionary representing the graph dimensions.

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

Returns:

Object containing the estimated memory requirements.

Return type:

EstimationResult

abstractmethod mutate(G: Graph, mutate_relationship_type: str, mutate_property: str, source_node_filter: str | list[int], target_node_filter: str | list[int], top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → NodeSimilarityMutateResult

Runs the Filtered Node Similarity algorithm and stores the results as new relationships in the graph catalog.

Parameters:
  • G (Graph) – Graph object to use

  • mutate_relationship_type (str) – Name of the relationship type to store the results in.

  • mutate_property (str) – Name of the node property to store the results in.

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing metadata from the execution.

Return type:

NodeSimilarityMutateResult

abstractmethod stats(G: Graph, source_node_filter: str | list[int], target_node_filter: str | list[int], top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → NodeSimilarityStatsResult

Runs the Filtered Node Similarity algorithm and returns execution statistics.

Parameters:
  • G (Graph) – Graph object to use

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Object containing execution statistics and algorithm-specific results.

Return type:

NodeSimilarityStatsResult

abstractmethod stream(G: Graph, source_node_filter: str | list[int], target_node_filter: str | list[int], top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → DataFrame

Runs the Filtered Node Similarity algorithm and returns the result as a DataFrame.

Parameters:
  • G (Graph) – Graph object to use

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

The similarity results as a DataFrame with columns ‘node1’, ‘node2’, and ‘similarity’.

Return type:

pandas.DataFrame

abstractmethod write(G: Graph, write_relationship_type: str, write_property: str, source_node_filter: str | list[int], target_node_filter: str | list[int], top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None, write_concurrency: int | None = None) → NodeSimilarityWriteResult

Runs the Filtered Node Similarity algorithm and writes the results back to the database.

Parameters:
  • G (Graph) – Graph object to use

  • write_relationship_type (str) – Name of the relationship type to store the results in.

  • write_property (str) – Name of the node property to store the results in.

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • write_concurrency (int | None) – Number of concurrent threads to use for writing.Returns

  • -------

  • NodeSimilarityWriteResult – Object containing metadata from the execution.

Return type:

NodeSimilarityWriteResult

class graphdatascience.procedure_surface.api.similarity.NodeSimilarityFilteredSessionEndpoints

Bases: NodeSimilarityFilteredEndpoints

NodeSimilarityFiltered endpoints as exposed by a GDS Session.

abstractmethod compute(G: Graph, source_node_filter: str | list[int], target_node_filter: str | list[int], *, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → JobHandle

Starts the computation as a job and returns a handle to it.

The computation runs without materializing its result. Use the returned handle to mutate, write or stream the result afterwards.

Parameters:
  • G (Graph) – Graph object to use

  • source_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be sources.

  • target_node_filter (str | list[int]) – A Cypher expression or list of node IDs to filter which nodes can be targets.

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Handle to the started computation

Return type:

JobHandle

class graphdatascience.procedure_surface.api.similarity.NodeSimilarityMutateResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
mutate_millis: int
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
relationships_written: int
similarity_distribution: dict[str, Any]
class graphdatascience.procedure_surface.api.similarity.NodeSimilaritySessionEndpoints

Bases: NodeSimilarityEndpoints

NodeSimilarity endpoints as exposed by a GDS Session.

abstractmethod compute(G: Graph, top_k: int = 10, bottom_k: int = 10, top_n: int = 0, bottom_n: int = 0, similarity_cutoff: float = 1e-42, degree_cutoff: int = 1, upper_degree_cutoff: int = 2147483647, similarity_metric: str = 'JACCARD', use_components: bool | str = False, relationship_weight_property: str | None = None, relationship_types: list[str] = ['*'], node_labels: list[str] = ['*'], sudo: bool = False, log_progress: bool = True, username: str | None = None, concurrency: int | None = None, job_id: str | None = None) → JobHandle

Starts the computation as a job and returns a handle to it.

The computation runs without materializing its result. Use the returned handle to mutate, write or stream the result afterwards.

Parameters:
  • G (Graph) – Graph object to use

  • top_k (int) – Number of most similar nodes to return for each node.

  • bottom_k (int) – The maximum number of neighbors with the lowest similarity scores to compute per node.

  • top_n (int) – The maximum number of neighbors to select globally based on similarity scores.

  • bottom_n (int) – The maximum number of neighbors to select globally based on lowest similarity scores.

  • similarity_cutoff (float) – The threshold for similarity scores.

  • degree_cutoff (int) – The minimum degree a node must have to be considered.

  • upper_degree_cutoff (int) – The maximum degree a node can have to be considered.

  • similarity_metric (str) – The similarity metric to use for computation. JACCARD, OVERLAP or COSINE.

  • use_components (bool | str) – Whether to compute similarity within connected components. Given a string uses the node property stored in the graph

  • relationship_weight_property (str | None) – Name of the property to be used as weights.

  • relationship_types (list[str]) – Filter the graph using the given relationship types. Relationships with any of the given types will be included.

  • node_labels (list[str]) – Filter the graph using the given node labels. Nodes with any of the given labels will be included.

  • sudo (bool) – Disable the memory guard.

  • log_progress (bool) – Display progress logging.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

Returns:

Handle to the started computation

Return type:

JobHandle

abstract property filtered: NodeSimilarityFilteredSessionEndpoints

Access to the filtered Node Similarity endpoints.

class graphdatascience.procedure_surface.api.similarity.NodeSimilarityStatsResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
similarity_distribution: dict[str, Any]
similarity_pairs: int
class graphdatascience.procedure_surface.api.similarity.NodeSimilarityWriteResult

Bases: BaseResult

compute_millis: int
configuration: dict[str, Any]
nodes_compared: int
post_processing_millis: int
pre_processing_millis: int
relationships_written: int
similarity_distribution: dict[str, Any]
write_millis: int
class graphdatascience.procedure_surface.api.similarity.SimilarityFunctions

Bases:

cosine(vector1: list[float | int], vector2: list[float | int]) → float

Compute the cosine similarity between two vectors.

Parameters:
Returns:

Cosine similarity in [-1, 1].

Return type:

float

euclidean(vector1: list[float | int], vector2: list[float | int]) → float

Compute the normalized Euclidean similarity between two vectors.

Parameters:
Returns:

Euclidean similarity in (0, 1].

Return type:

float

euclidean_distance(vector1: list[float | int], vector2: list[float | int]) → float

Compute the Euclidean distance between two vectors.

Parameters:
Returns:

Euclidean distance in [0, inf).

Return type:

float

jaccard(vector1: list[float | int], vector2: list[float | int]) → float

Compute the Jaccard similarity between two vectors.

Parameters:
Returns:

Jaccard similarity in [0, 1].

Return type:

float

overlap(vector1: list[float | int], vector2: list[float | int]) → float

Compute the overlap coefficient between two vectors.

Parameters:
Returns:

Overlap coefficient in [0, 1].

Return type:

float

pearson(vector1: list[float | int], vector2: list[float | int]) → float

Compute the Pearson correlation coefficient between two vectors.

Parameters:
Returns:

Pearson correlation in [-1, 1].

Return type:

float

class graphdatascience.procedure_surface.api.similarity.similarity_functions.SimilarityFunctions
__init__()
classmethod __new__(*args, **kwargs)