Base
BaseGraphTransformation
dataclass
Bases: ABC
Abstract base class for graph transformations on a KnowledgeGraph.
transform
abstractmethod
async
transform(kg: KnowledgeGraph) -> Any
Abstract method to transform the KnowledgeGraph. Transformations should be idempotent, meaning that applying the transformation multiple times should yield the same result as applying it once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
Any
|
The transformed knowledge graph. |
Source code in src/ragas/testset/transforms/base.py
filter
filter(kg: KnowledgeGraph) -> KnowledgeGraph
Filters the KnowledgeGraph and returns the filtered graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be filtered. |
required |
Returns:
Type | Description |
---|---|
KnowledgeGraph
|
The filtered knowledge graph. |
Source code in src/ragas/testset/transforms/base.py
generate_execution_plan
abstractmethod
generate_execution_plan(
kg: KnowledgeGraph,
) -> List[Coroutine]
Generates a list of coroutines to be executed in sequence by the Executor. This coroutine will, upon execution, write the transformation into the KnowledgeGraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Coroutine]
|
A list of coroutines to be executed in parallel. |
Source code in src/ragas/testset/transforms/base.py
Extractor
dataclass
Extractor(
name: str = "",
filter_nodes: Callable[
[Node], bool
] = lambda: default_filter(),
)
Bases: BaseGraphTransformation
Abstract base class for extractors that transform a KnowledgeGraph by extracting specific properties from its nodes.
Methods:
Name | Description |
---|---|
transform |
Transforms the KnowledgeGraph by extracting properties from its nodes. |
extract |
Abstract method to extract a specific property from a node. |
transform
async
transform(
kg: KnowledgeGraph,
) -> List[Tuple[Node, Tuple[str, Any]]]
Transforms the KnowledgeGraph by extracting properties from its nodes. Uses
the filter
method to filter the graph and the extract
method to extract
properties from each node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Node, Tuple[str, Any]]]
|
A list of tuples where each tuple contains a node and the extracted property. |
Examples:
>>> kg = KnowledgeGraph(nodes=[Node(id=1, properties={"name": "Node1"}), Node(id=2, properties={"name": "Node2"})])
>>> extractor = SomeConcreteExtractor()
>>> extractor.transform(kg)
[(Node(id=1, properties={"name": "Node1"}), ("property_name", "extracted_value")),
(Node(id=2, properties={"name": "Node2"}), ("property_name", "extracted_value"))]
Source code in src/ragas/testset/transforms/base.py
extract
abstractmethod
async
extract(node: Node) -> Tuple[str, Any]
Abstract method to extract a specific property from a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The node from which to extract the property. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, Any]
|
A tuple containing the property name and the extracted value. |
Source code in src/ragas/testset/transforms/base.py
generate_execution_plan
generate_execution_plan(
kg: KnowledgeGraph,
) -> List[Coroutine]
Generates a list of coroutines to be executed in parallel by the Executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Coroutine]
|
A list of coroutines to be executed in parallel. |
Source code in src/ragas/testset/transforms/base.py
Splitter
dataclass
Bases: BaseGraphTransformation
Abstract base class for splitters that transform a KnowledgeGraph by splitting its nodes into smaller chunks.
Methods:
Name | Description |
---|---|
transform |
Transforms the KnowledgeGraph by splitting its nodes into smaller chunks. |
split |
Abstract method to split a node into smaller chunks. |
transform
async
transform(
kg: KnowledgeGraph,
) -> Tuple[List[Node], List[Relationship]]
Transforms the KnowledgeGraph by splitting its nodes into smaller chunks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[Node], List[Relationship]]
|
A tuple containing a list of new nodes and a list of new relationships. |
Source code in src/ragas/testset/transforms/base.py
split
abstractmethod
async
split(node: Node) -> Tuple[List[Node], List[Relationship]]
Abstract method to split a node into smaller chunks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The node to be split. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[Node], List[Relationship]]
|
A tuple containing a list of new nodes and a list of new relationships. |
Source code in src/ragas/testset/transforms/base.py
generate_execution_plan
generate_execution_plan(
kg: KnowledgeGraph,
) -> List[Coroutine]
Generates a list of coroutines to be executed in parallel by the Executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Coroutine]
|
A list of coroutines to be executed in parallel. |
Source code in src/ragas/testset/transforms/base.py
RelationshipBuilder
dataclass
Bases: BaseGraphTransformation
Abstract base class for building relationships in a KnowledgeGraph.
Methods:
Name | Description |
---|---|
transform |
Transforms the KnowledgeGraph by building relationships. |
transform
abstractmethod
async
transform(kg: KnowledgeGraph) -> List[Relationship]
Transforms the KnowledgeGraph by building relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Relationship]
|
A list of new relationships. |
Source code in src/ragas/testset/transforms/base.py
generate_execution_plan
generate_execution_plan(
kg: KnowledgeGraph,
) -> List[Coroutine]
Generates a list of coroutines to be executed in parallel by the Executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kg
|
KnowledgeGraph
|
The knowledge graph to be transformed. |
required |
Returns:
Type | Description |
---|---|
List[Coroutine]
|
A list of coroutines to be executed in parallel. |