Skip to content

read_only_graph

Bluemi edited this page Sep 5, 2025 · 1 revision

ReadOnlyGraph

The ReadOnlyGraph can not be modified. It is usually created using a MutableGraph.

class deglib.graph.ReadOnlyGraph(graph_cpp: ReadOnlyGraph)

Bases: SearchGraph

classmethod from_graph(input_graph: SearchGraph, max_vertex_count: int = -1, feature_space: FloatSpace | None = None, edges_per_vertex: int = -1) → ReadOnlyGraph

Create a read only graph from the given graph by only keeping information that is useful for searching.

  • Parameters:
    • input_graph – The graph to build from
    • max_vertex_count – If given the new size of the returned graph, otherwise will be taken from input graph
    • feature_space – If given the feature space for the graph, otherwise the same as the feature space of the input graph
    • edges_per_vertex – The number of edges for the new graph. Should not be smaller than the edges of the input graph

size() → int

  • Returns: the number of vertices in the graph

get_feature_space() → FloatSpace

  • Returns: the feature space

get_internal_index(external_label: int) → int

Translates internal index to external label

  • Parameters: external_label – The external label to translate
  • Returns: The internal index

has_path(entry_vertex_indices: List[int], to_vertex: int, eps: float, k: int) → List[ObjectDistance]

Returns a path from one of the entry vertex indices to the given to_vertex.

  • Parameters:
    • entry_vertex_indices – List of start vertices
    • to_vertex – The vertex to find a path to
    • eps – Controls how many nodes are checked during search. Lower eps values like 0.001 are faster but less accurate. Higher eps values like 0.1 are slower but more accurate. Should always be greater 0.
    • k – TODO

get_entry_vertex_indices() → List[int]

Creates a list of internal indices that can be used as starting point for an anns search.

get_external_label(internal_index: int) → int

Translates external labels to internal index

  • Parameters: internal_index – The internal index to translate
  • Returns: The external label

explore(entry_vertex_index: int, k: int, include_entry: bool, max_distance_computation_count: int) → ResultSet

An exploration for similar element, limited by max_distance_computation_count

  • Parameters:
    • entry_vertex_index – The start point for which similar feature vectors should be searched
    • k – The number of similar feature vectors to return
    • include_entry – If True, the entry vertex is included in the result set.
    • max_distance_computation_count – Limit the number of distance calculations. If set to 0 this is ignored.

get_edges_per_vertex() → int

  • Returns: the number of edges of each vertex

get_neighbor_indices(internal_index: int, copy: bool = False) → ndarray

Get the neighbor indices (internal index) of the given vertex.

  • Parameters:
    • internal_index – The internal index to get the neighbors of
    • copy – If True the returned neighbor indices are a copy, otherwise they reference internal graph data.

has_vertex(external_label: int) → bool

  • Returns: whether the given external label is present in the graph.

has_edge(internal_index: int, neighbor_index: int) → bool

  • Returns: whether the vertex at internal_index has an edge to the vertex at neighbor_index.

deglib.graph.load_readonly_graph(path: Path | str) → ReadOnlyGraph

Read a saved ReadOnlyGraph from given file. The file can be created by calling SizeBoundedGraph.save_graph().

  • Parameters: path – The path where to look for the file
  • Raises: FileNotFoundError – If the given file does not exist

Clone this wiki locally