structures
¤
Node
dataclass
¤
Node(
text: str,
index: int,
children: set[int],
embeddings: list[float],
metadata: dict[str, Any] | None = None,
layer: int = 0,
)
A node in the RAPTOR tree.
Attributes:
-
text(str) –The text of the node.
-
index(int) –The global index of the node in the tree.
-
children(set[int]) –The global indices of the children nodes.
-
embeddings(list[float]) –Embeddings of the node’s text.
-
metadata(dict[str, Any] | None) –Metadata about the node’s text.
-
layer(int) –Tree layer the node belongs to.
from_text
classmethod
¤
from_text(
index: int,
text: str,
embedding_model: EmbeddingModelLike,
children_indices: set[int] | None = None,
metadata: dict[str, str] | None = None,
layer: int = 0,
) -> Node
Create a node from text by embedding it using the given embedding model.
Parameters:
-
index(int) –The global index of the node in the tree.
-
text(str) –The text of the node.
-
embedding_model(EmbeddingModelLike) –The embedding model to use for embedding the text.
-
children_indices(set[int] | None, default:None) –The global indices of the children nodes.
-
metadata(dict[str, str] | None, default:None) –Metadata about the node’s text.
-
layer(int, default:0) –Tree layer the node belongs to.
Returns:
-
Node–A node created from the text.
from_children
classmethod
¤
from_children(
children: list[Node],
embedding_model: EmbeddingModelLike,
summarization_model: SummarizationModelLike,
index: int,
layer: int = 0,
) -> Node
Create a node from a list of children nodes by summarizing their texts.
The text of the children nodes is concatenated using concatenate_node_texts() and passed to the summarization model to generate a summary.
Parameters:
-
children(list[Node]) –A list of children nodes.
-
embedding_model(EmbeddingModelLike) –The embedding model to use for embedding the summarized text.
-
summarization_model(SummarizationModelLike) –The summarization model to use for summarizing the text of the children nodes.
-
index(int) –The global index of the node in the tree.
-
layer(int, default:0) –Tree layer the node belongs to.
Returns:
-
Node–A node created from the children nodes.
Tree
dataclass
¤
Tree(
all_nodes: dict[int, Node],
root_nodes: dict[int, Node],
leaf_nodes: dict[int, Node],
num_layers: int,
layer_to_nodes: dict[int, list[Node]],
)
A RAPTOR tree.
Attributes:
-
all_nodes(dict[int, Node]) –All nodes in the tree, mapped to their global indices.
-
root_nodes(dict[int, Node]) –Root nodes in the tree, mapped to their global indices.
-
leaf_nodes(dict[int, Node]) –Leaf nodes in the tree, mapped to their global indices.
-
num_layers(int) –Number of layers in the tree.
-
layer_to_nodes(dict[int, list[Node]]) –Nodes in a layer, mapped to their layer index.