SourceTrackedGraph

org.llm4s.knowledgegraph.extraction.SourceTrackedGraph
See theSourceTrackedGraph companion object
case class SourceTrackedGraph(graph: Graph, sources: Seq[DocumentSource], nodeSources: Map[String, Set[String]], edgeSources: Map[(String, String, String), Set[String]])

A graph with source provenance tracking.

Wraps a standard Graph with metadata about which documents contributed each node and edge. The underlying Graph remains a pure data structure; provenance is tracked externally.

Value parameters

edgeSources

Mapping of (source, target, relationship) to the set of source document IDs

graph

The underlying knowledge graph

nodeSources

Mapping of node ID to the set of source document IDs that contributed it

sources

All document sources that contributed to this graph

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

Adds a document's extracted graph to this tracked graph, merging nodes/edges and recording provenance.

Adds a document's extracted graph to this tracked graph, merging nodes/edges and recording provenance.

Node IDs are namespaced with the document source ID before merging to prevent silent overwrites when two documents produce the same LLM-generated IDs. Entity linking (run afterwards by MultiDocumentGraphBuilder) is responsible for collapsing semantically equivalent nodes across documents.

Value parameters

docGraph

The graph extracted from the document

source

The document source metadata

Attributes

Returns

A new SourceTrackedGraph with the document incorporated

def getEdgeSources(source: String, target: String, relationship: String): Set[DocumentSource]

Returns the document sources that contributed a given edge.

Returns the document sources that contributed a given edge.

Value parameters

relationship

The relationship type

source

The source node ID

target

The target node ID

Attributes

Returns

Set of DocumentSource objects that contributed this edge

def getNodeSources(nodeId: String): Set[DocumentSource]

Returns the document sources that contributed a given node.

Returns the document sources that contributed a given node.

Value parameters

nodeId

The node ID to look up

Attributes

Returns

Set of DocumentSource objects that contributed this node

Replaces the underlying graph (e.g., after entity linking) while preserving source tracking. Node/edge source mappings are preserved as-is; callers performing node merges should update the mappings via withUpdatedNodeSources / withUpdatedEdgeSources.

Replaces the underlying graph (e.g., after entity linking) while preserving source tracking. Node/edge source mappings are preserved as-is; callers performing node merges should update the mappings via withUpdatedNodeSources / withUpdatedEdgeSources.

Value parameters

newGraph

The replacement graph

Attributes

Returns

A new SourceTrackedGraph with the updated graph

def withUpdatedEdgeSources(newEdgeSources: Map[(String, String, String), Set[String]]): SourceTrackedGraph

Returns a new SourceTrackedGraph with updated edge source mappings.

Returns a new SourceTrackedGraph with updated edge source mappings.

Value parameters

newEdgeSources

The replacement edge source mappings

Attributes

Returns

A new SourceTrackedGraph with updated mappings

def withUpdatedNodeSources(newNodeSources: Map[String, Set[String]]): SourceTrackedGraph

Returns a new SourceTrackedGraph with updated node source mappings.

Returns a new SourceTrackedGraph with updated node source mappings.

Value parameters

newNodeSources

The replacement node source mappings

Attributes

Returns

A new SourceTrackedGraph with updated mappings

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product