graph_retriever.edges¶
Specification and implementation of edges functions.
These are responsible for extracting edges from nodes and expressing them in way that the adapters can implement.
EdgeFunction
module-attribute
¶
A function for extracting edges from nodes.
Implementations should be deterministic.
EdgeSpec
module-attribute
¶
The definition of an edge for traversal, represented as a pair of fields representing the source and target of the edge. Each may be:
- A string,
key
, indicatingdoc.metadata[key]
as the value. - The placeholder Id, indicating
doc.id
as the value.
Examples:
Edge ¶
Bases: ABC
An edge identifies properties necessary for finding matching nodes.
Sub-classes should be hashable.
Edges
dataclass
¶
Information about the incoming and outgoing edges.
PARAMETER | DESCRIPTION |
---|---|
incoming
|
Incoming edges that link to this node. |
outgoing
|
Edges that this node link to. These edges should be defined in terms of
the incoming |
Id ¶
Place-holder type indicating that the ID should be used.
MetadataEdge
dataclass
¶
Bases: Edge
Link to nodes with specific metadata.
A MetadataEdge
connects to nodes with either:
node.metadata[field] == value
node.metadata[field] CONTAINS value
(if the metadata is a collection).
PARAMETER | DESCRIPTION |
---|---|
incoming_field
|
The name of the metadata field storing incoming edges.
TYPE:
|
value
|
The value associated with the key for this edge
TYPE:
|
Source code in packages/graph-retriever/src/graph_retriever/edges/_base.py
MetadataEdgeFunction ¶
Helper for extracting and encoding edges in metadata.
This class provides tools to extract incoming and outgoing edges from document metadata. Both incoming and outgoing edges use the same target name, enabling equality matching for keys.
PARAMETER | DESCRIPTION |
---|---|
edges
|
Definitions of edges for traversal, represented as a pair of fields representing the source and target of the edges. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If an invalid edge definition is provided. |
Source code in packages/graph-retriever/src/graph_retriever/edges/metadata.py
__call__ ¶
Extract incoming and outgoing edges for a piece of content.
This method retrieves edges based on the declared edge definitions, taking into account whether nested metadata is used.
PARAMETER | DESCRIPTION |
---|---|
content
|
The content to extract edges from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Edges
|
the incoming and outgoing edges of the node |