Skip to content

Event & Observer API

EventEmitter Protocol

Bases: Protocol

Protocol for event emitters.

Defines the interface for objects that can emit events to observers.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class EventEmitter(Protocol):
    """Protocol for event emitters.

    Defines the interface for objects that can emit events to observers.
    """

    @abstractmethod
    def emit(self, event: PipelineEvent) -> None:
        """Emit an event to all registered observers.

        Parameters
        ----------
        event : PipelineEvent
            The event to emit.
        """
        ...

    @abstractmethod
    def register_observer(self, observer: "EventObserver") -> None:
        """Register an observer to receive events.

        Parameters
        ----------
        observer : EventObserver
            The observer to register.
        """
        ...

    @abstractmethod
    def unregister_observer(self, observer: "EventObserver") -> None:
        """Unregister an observer.

        Parameters
        ----------
        observer : EventObserver
            The observer to unregister.
        """
        ...

emit(event) abstractmethod

Emit an event to all registered observers.

Parameters

event : PipelineEvent The event to emit.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
25
26
27
28
29
30
31
32
33
34
@abstractmethod
def emit(self, event: PipelineEvent) -> None:
    """Emit an event to all registered observers.

    Parameters
    ----------
    event : PipelineEvent
        The event to emit.
    """
    ...

register_observer(observer) abstractmethod

Register an observer to receive events.

Parameters

observer : EventObserver The observer to register.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
36
37
38
39
40
41
42
43
44
45
@abstractmethod
def register_observer(self, observer: "EventObserver") -> None:
    """Register an observer to receive events.

    Parameters
    ----------
    observer : EventObserver
        The observer to register.
    """
    ...

unregister_observer(observer) abstractmethod

Unregister an observer.

Parameters

observer : EventObserver The observer to unregister.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
47
48
49
50
51
52
53
54
55
56
@abstractmethod
def unregister_observer(self, observer: "EventObserver") -> None:
    """Unregister an observer.

    Parameters
    ----------
    observer : EventObserver
        The observer to unregister.
    """
    ...

EventObserver Protocol

Bases: Protocol

Protocol for event observers.

Defines the interface for objects that can consume events from emitters.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class EventObserver(Protocol):
    """Protocol for event observers.

    Defines the interface for objects that can consume events from emitters.
    """

    @abstractmethod
    def on_event(self, event: PipelineEvent) -> None:
        """Handle an incoming event.

        Parameters
        ----------
        event : PipelineEvent
            The event to handle.
        """
        ...

on_event(event) abstractmethod

Handle an incoming event.

Parameters

event : PipelineEvent The event to handle.

Source code in packages/episteme-pipeline/episteme_pipeline/events/bus.py
65
66
67
68
69
70
71
72
73
74
@abstractmethod
def on_event(self, event: PipelineEvent) -> None:
    """Handle an incoming event.

    Parameters
    ----------
    event : PipelineEvent
        The event to handle.
    """
    ...

Event Models

All pipeline event payload models in pipeline/events/models.py:

Pydantic event schemas for the pipeline event system.

These events represent domain-level occurrences in the pipeline that are scientifically relevant for analysis and reproducibility.

All events inherit from BaseEvent and include timestamp, run_id, and phase for correlation and filtering.

ArtifactProjected

Bases: BaseEvent

An artifact was projected to a target system.

Attributes

artifact_type : str Type of artifact (e.g., "triple", "entity"). duration_seconds : float Projection duration in seconds. success : bool Whether the projection succeeded.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
class ArtifactProjected(BaseEvent):

    """An artifact was projected to a target system.

    Attributes
    ----------
    artifact_type : str
        Type of artifact (e.g., "triple", "entity").
    duration_seconds : float
        Projection duration in seconds.
    success : bool
        Whether the projection succeeded.
    """
    artifact_type: str
    duration_seconds: float
    success: bool

BaseEvent

Bases: BaseModel

Base class for all pipeline events.

Attributes

timestamp : datetime Time when the event was created. Uses UTC timezone. run_id : str, optional Identifier for the pipeline run this event belongs to. phase : str, optional Name of the pipeline phase when this event occurred.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class BaseEvent(BaseModel):
    """Base class for all pipeline events.

    Attributes
    ----------
    timestamp : datetime
        Time when the event was created. Uses UTC timezone.
    run_id : str, optional
        Identifier for the pipeline run this event belongs to.
    phase : str, optional
        Name of the pipeline phase when this event occurred.
    """
    timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
    run_id: Optional[str] = None
    phase: Optional[str] = None

CandidateRejectedByThreshold

Bases: BaseEvent

A candidate was rejected due to not meeting threshold.

This event is emitted when a candidate pair is rejected because its score falls below the required threshold.

Attributes

candidate_pair : tuple of (str, str) Pair of entity IDs that were rejected. score : float Score that was below the threshold. threshold : float Threshold that was not met. reason : str Reason for rejection (default: "Below threshold").

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class CandidateRejectedByThreshold(BaseEvent):
    """A candidate was rejected due to not meeting threshold.

    This event is emitted when a candidate pair is rejected because its score
    falls below the required threshold.

    Attributes
    ----------
    candidate_pair : tuple of (str, str)
        Pair of entity IDs that were rejected.
    score : float
        Score that was below the threshold.
    threshold : float
        Threshold that was not met.
    reason : str
        Reason for rejection (default: "Below threshold").
    """
    candidate_pair: tuple[str, str]  # entity IDs
    score: float
    threshold: float
    reason: str = "Below threshold"

ChunksGenerated

Bases: BaseEvent

Chunks were generated for a document.

Attributes

document_id : str Identifier of the document. document_title : str Title of the document. chunk_count : int Number of chunks generated. token_count : int Total token count across all chunks.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
class ChunksGenerated(BaseEvent):
    """Chunks were generated for a document.

    Attributes
    ----------
    document_id : str
        Identifier of the document.
    document_title : str
        Title of the document.
    chunk_count : int
        Number of chunks generated.
    token_count : int
        Total token count across all chunks.
    """
    document_id: str
    document_title: str
    chunk_count: int
    token_count: int

ComponentCompleted

Bases: BaseEvent

A component completed processing.

This event is emitted when a pipeline component finishes processing.

Attributes

component_name : str Name of the component that completed. duration_seconds : float Duration of component execution in seconds. output_description : str, optional Description of the output data. success : bool Whether the component completed successfully. error_message : str, optional Error message if the component failed.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
class ComponentCompleted(BaseEvent):
    """A component completed processing.

    This event is emitted when a pipeline component finishes processing.

    Attributes
    ----------
    component_name : str
        Name of the component that completed.
    duration_seconds : float
        Duration of component execution in seconds.
    output_description : str, optional
        Description of the output data.
    success : bool
        Whether the component completed successfully.
    error_message : str, optional
        Error message if the component failed.
    """
    component_name: str
    duration_seconds: float
    output_description: Optional[str] = None
    success: bool
    error_message: Optional[str] = None

ComponentStarted

Bases: BaseEvent

A component started processing.

This event is emitted when a pipeline component begins processing.

Attributes

component_name : str Name of the component that started. input_description : str, optional Description of the input data.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
368
369
370
371
372
373
374
375
376
377
378
379
380
381
class ComponentStarted(BaseEvent):
    """A component started processing.

    This event is emitted when a pipeline component begins processing.

    Attributes
    ----------
    component_name : str
        Name of the component that started.
    input_description : str, optional
        Description of the input data.
    """
    component_name: str
    input_description: Optional[str] = None

DenseCandidatesGenerated

Bases: BaseEvent

Dense candidate pairs were generated.

This event is emitted when the dense retrieval phase generates candidate entity pairs for further processing.

Attributes

candidate_count : int Number of candidate pairs generated. candidates : list of dict List of candidate pairs with their scores and metadata. entities_count : int Number of entities used to generate candidates.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class DenseCandidatesGenerated(BaseEvent):
    """Dense candidate pairs were generated.

    This event is emitted when the dense retrieval phase generates candidate
    entity pairs for further processing.

    Attributes
    ----------
    candidate_count : int
        Number of candidate pairs generated.
    candidates : list of dict
        List of candidate pairs with their scores and metadata.
    entities_count : int
        Number of entities used to generate candidates.
    """
    candidate_count: int
    candidates: List[dict]  # Simplified representation
    entities_count: int

EmbeddingGenerationCompleted

Bases: BaseEvent

Complete record of an embedding model batch generation call.

Emitted when an embedding model computes dense vector representations for one or more text items.

Attributes

model_name : str Name or identifier of the embedding model. text_count : int Number of texts processed in the batch. total_characters : int Total character length across all embedded texts. prompt_tokens : int Estimated or measured input tokens processed. total_tokens : int Total tokens consumed. duration_seconds : float Latency in seconds for the embedding operation. vector_dim : int, optional Dimensionality of the produced embeddings. operation : str Operation kind (e.g., "embedding", "batch_embedding"). cached : bool Whether the embeddings were served from a local cache.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
class EmbeddingGenerationCompleted(BaseEvent):
    """Complete record of an embedding model batch generation call.

    Emitted when an embedding model computes dense vector representations for one
    or more text items.

    Attributes
    ----------
    model_name : str
        Name or identifier of the embedding model.
    text_count : int
        Number of texts processed in the batch.
    total_characters : int
        Total character length across all embedded texts.
    prompt_tokens : int
        Estimated or measured input tokens processed.
    total_tokens : int
        Total tokens consumed.
    duration_seconds : float
        Latency in seconds for the embedding operation.
    vector_dim : int, optional
        Dimensionality of the produced embeddings.
    operation : str
        Operation kind (e.g., "embedding", "batch_embedding").
    cached : bool
        Whether the embeddings were served from a local cache.
    """
    model_name: str
    text_count: int
    total_characters: int
    prompt_tokens: int = 0
    total_tokens: int = 0
    duration_seconds: float = 0.0
    vector_dim: Optional[int] = None
    operation: str = "embedding"
    cached: bool = False

EntityLinkingCandidatesRetrieved

Bases: BaseEvent

Dense candidates retrieved for entity linking.

Attributes

mention_id : str ID of the mention being linked. mention_name : str Name of the mention. candidate_count : int Number of candidates retrieved. candidates : list of dict Retrieved candidates with their scores.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
class EntityLinkingCandidatesRetrieved(BaseEvent):
    """Dense candidates retrieved for entity linking.

    Attributes
    ----------
    mention_id : str
        ID of the mention being linked.
    mention_name : str
        Name of the mention.
    candidate_count : int
        Number of candidates retrieved.
    candidates : list of dict
        Retrieved candidates with their scores.
    """
    mention_id: str
    mention_name: str
    candidate_count: int
    candidates: List[dict]

EntityLinkingReranked

Bases: BaseEvent

A cross-encoder score assigned to a linking candidate.

Attributes

mention_id : str ID of the mention. mention_name : str Name of the mention. candidate_id : str ID of the canonical candidate. candidate_name : str Name of the candidate. score : float Cross-encoder similarity score. accepted : bool Whether the candidate was accepted above threshold. threshold : float Threshold used.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
class EntityLinkingReranked(BaseEvent):
    """A cross-encoder score assigned to a linking candidate.

    Attributes
    ----------
    mention_id : str
        ID of the mention.
    mention_name : str
        Name of the mention.
    candidate_id : str
        ID of the canonical candidate.
    candidate_name : str
        Name of the candidate.
    score : float
        Cross-encoder similarity score.
    accepted : bool
        Whether the candidate was accepted above threshold.
    threshold : float
        Threshold used.
    """
    mention_id: str
    mention_name: str
    candidate_id: str
    candidate_name: str
    score: float
    accepted: bool
    threshold: float

EntityMaturationSynthesized

Bases: BaseEvent

An entity description was synthesized from its envelopes.

Attributes

entity_id : str ID of the mature entity. entity_name : str Name of the entity. envelope_count : int Number of textual envelopes used for centroid calculation. top_k_used : int Number of Top-K envelopes fed into the LLM. synthesized_description : str The final synthesized description.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
class EntityMaturationSynthesized(BaseEvent):
    """An entity description was synthesized from its envelopes.

    Attributes
    ----------
    entity_id : str
        ID of the mature entity.
    entity_name : str
        Name of the entity.
    envelope_count : int
        Number of textual envelopes used for centroid calculation.
    top_k_used : int
        Number of Top-K envelopes fed into the LLM.
    synthesized_description : str
        The final synthesized description.
    """
    entity_id: str
    entity_name: str
    envelope_count: int
    top_k_used: int
    synthesized_description: str

EntityProcessed

Bases: BaseEvent

An entity was processed.

Attributes

entity_id : str Identifier of the processed entity. entity_name : str Display name of the entity. entity_type : str Type/label of the entity (schema class).

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class EntityProcessed(BaseEvent):
    """An entity was processed.

    Attributes
    ----------
    entity_id : str
        Identifier of the processed entity.
    entity_name : str
        Display name of the entity.
    entity_type : str
        Type/label of the entity (schema class).
    """
    entity_id: str
    entity_name: str
    entity_type: str

EnvelopeInjectionAttempted

Bases: BaseEvent

An attempt was made to inject a textual envelope for a mention.

Attributes

mention_name : str Name of the mention. chunk_id : str ID of the chunk where the mention was found.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
213
214
215
216
217
218
219
220
221
222
223
224
class EnvelopeInjectionAttempted(BaseEvent):
    """An attempt was made to inject a textual envelope for a mention.

    Attributes
    ----------
    mention_name : str
        Name of the mention.
    chunk_id : str
        ID of the chunk where the mention was found.
    """
    mention_name: str
    chunk_id: str

EnvelopeInjectionFailed

Bases: BaseEvent

Failed to inject a textual envelope for a mention after all fallbacks.

Attributes

mention_name : str Name of the mention. mention_quote : str The quote the LLM claimed for the mention. chunk_id : str ID of the chunk where the mention was found. reason : str Reason for failure.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
class EnvelopeInjectionFailed(BaseEvent):
    """Failed to inject a textual envelope for a mention after all fallbacks.

    Attributes
    ----------
    mention_name : str
        Name of the mention.
    mention_quote : str
        The quote the LLM claimed for the mention.
    chunk_id : str
        ID of the chunk where the mention was found.
    reason : str
        Reason for failure.
    """
    mention_name: str
    mention_quote: str
    chunk_id: str
    reason: str

EvaluationCompleted

Bases: BaseEvent

An evaluation run has completed.

Attributes

evaluation_id : str ID of the evaluation. run_id : str ID of the pipeline run. metrics : dict[str, float] Metrics computed during evaluation. outcome : str Overall outcome of the evaluation.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
class EvaluationCompleted(BaseEvent):
    """An evaluation run has completed.

    Attributes
    ----------
    evaluation_id : str
        ID of the evaluation.
    run_id : str
        ID of the pipeline run.
    metrics : dict[str, float]
        Metrics computed during evaluation.
    outcome : str
        Overall outcome of the evaluation.
    """
    evaluation_id: str
    run_id: str
    metrics: dict[str, float]
    outcome: str

EvaluationScoreLogged

Bases: BaseEvent

An evaluation metric or quality score was logged.

Emitted when a metric is computed (e.g., epistemic consistency, GM-GBS, OEP, relation confidence, clustering modularity) to attach to traces/sessions in observability backends.

Attributes

metric_name : str Name of the metric (e.g., "oep_score", "relation_confidence", "cluster_modularity"). score : float Numeric value of the metric. comment : str, optional Optional human-readable explanation or context. target_id : str, optional Target entity, triple, cluster, or phase identifier.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
class EvaluationScoreLogged(BaseEvent):
    """An evaluation metric or quality score was logged.

    Emitted when a metric is computed (e.g., epistemic consistency, GM-GBS, OEP,
    relation confidence, clustering modularity) to attach to traces/sessions in
    observability backends.

    Attributes
    ----------
    metric_name : str
        Name of the metric (e.g., "oep_score", "relation_confidence", "cluster_modularity").
    score : float
        Numeric value of the metric.
    comment : str, optional
        Optional human-readable explanation or context.
    target_id : str, optional
        Target entity, triple, cluster, or phase identifier.
    """
    metric_name: str
    score: float
    comment: Optional[str] = None
    target_id: Optional[str] = None

FusionDecisionMade

Bases: BaseEvent

A fusion decision was made.

Attributes

entities_fused : list[str] IDs of entities fused together. fusion_type : str Strategy or mode of fusion used. confidence : float Confidence score for the fusion decision. reason : str, optional Optional human-readable rationale.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
class FusionDecisionMade(BaseEvent):
    """A fusion decision was made.

    Attributes
    ----------
    entities_fused : list[str]
        IDs of entities fused together.
    fusion_type : str
        Strategy or mode of fusion used.
    confidence : float
        Confidence score for the fusion decision.
    reason : str, optional
        Optional human-readable rationale.
    """
    entities_fused: List[str]
    fusion_type: str
    confidence: float
    reason: Optional[str] = None

LLMDurationMeasured

Bases: BaseEvent

Duration of an LLM call was measured.

Attributes

model_name : str Name of the model used. prompt_tokens : int Number of input tokens. completion_tokens : int Number of output tokens. duration_seconds : float Latency in seconds for the operation. operation : str Operation kind (e.g., "chat", "embedding").

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
class LLMDurationMeasured(BaseEvent):
    """Duration of an LLM call was measured.

    Attributes
    ----------
    model_name : str
        Name of the model used.
    prompt_tokens : int
        Number of input tokens.
    completion_tokens : int
        Number of output tokens.
    duration_seconds : float
        Latency in seconds for the operation.
    operation : str
        Operation kind (e.g., "chat", "embedding").
    """
    model_name: str
    prompt_tokens: int
    completion_tokens: int
    duration_seconds: float
    operation: str

LLMGenerationCompleted

Bases: BaseEvent

Complete record of an LLM generation call.

Emitted when an LLM facade completes a text completion or structured prediction. Carries prompt, output, and detailed token usage for observability backends (e.g., Langfuse generations).

Attributes

model_name : str Name of the model used (e.g., "openai/gpt-4o-mini"). prompt : Any Rendered prompt string, list of messages, or prompt payload. output_text : str Raw string output from the LLM. output_json : Any, optional Structured / parsed JSON representation of the output if available. prompt_tokens : int Number of input/prompt tokens. completion_tokens : int Number of output/completion tokens. total_tokens : int Total tokens consumed. duration_seconds : float Latency in seconds for the operation. operation : str Operation kind (e.g., "structured_predict", "text_completion", "fallback_complete"). cached : bool Whether this result was served from cache. model_parameters : dict, optional Hyperparameters used (e.g., temperature, max_tokens).

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
class LLMGenerationCompleted(BaseEvent):
    """Complete record of an LLM generation call.

    Emitted when an LLM facade completes a text completion or structured prediction.
    Carries prompt, output, and detailed token usage for observability backends
    (e.g., Langfuse generations).

    Attributes
    ----------
    model_name : str
        Name of the model used (e.g., "openai/gpt-4o-mini").
    prompt : Any
        Rendered prompt string, list of messages, or prompt payload.
    output_text : str
        Raw string output from the LLM.
    output_json : Any, optional
        Structured / parsed JSON representation of the output if available.
    prompt_tokens : int
        Number of input/prompt tokens.
    completion_tokens : int
        Number of output/completion tokens.
    total_tokens : int
        Total tokens consumed.
    duration_seconds : float
        Latency in seconds for the operation.
    operation : str
        Operation kind (e.g., "structured_predict", "text_completion", "fallback_complete").
    cached : bool
        Whether this result was served from cache.
    model_parameters : dict, optional
        Hyperparameters used (e.g., temperature, max_tokens).
    """
    model_name: str
    prompt: Any
    output_text: str
    output_json: Optional[Any] = None
    prompt_tokens: int = 0
    completion_tokens: int = 0
    total_tokens: int = 0
    duration_seconds: float = 0.0
    operation: str = "structured_predict"
    cached: bool = False
    model_parameters: Optional[dict[str, Any]] = None
    prompt_name: Optional[str] = None
    prompt_version: Optional[str | int] = None
    prompt_label: Optional[str] = None

LLMRelationDecoded

Bases: BaseEvent

An LLM decoded a relation from a candidate pair.

This event is emitted when an LLM extracts a semantic relation between a candidate pair of entities.

Attributes

candidate_pair : tuple of (str, str) Pair of entity IDs between which the relation was decoded. relation : str or None The relation extracted by the LLM, or None if no relation found. direction : str or None Direction of the relation (e.g., "forward", "reverse", "bidirectional"). confidence : float or None Confidence score for the extracted relation. raw_response : Any, optional Raw response from the LLM (may contain sensitive data).

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
class LLMRelationDecoded(BaseEvent):
    """An LLM decoded a relation from a candidate pair.

    This event is emitted when an LLM extracts a semantic relation between
    a candidate pair of entities.

    Attributes
    ----------
    candidate_pair : tuple of (str, str)
        Pair of entity IDs between which the relation was decoded.
    relation : str or None
        The relation extracted by the LLM, or None if no relation found.
    direction : str or None
        Direction of the relation (e.g., "forward", "reverse", "bidirectional").
    confidence : float or None
        Confidence score for the extracted relation.
    raw_response : Any, optional
        Raw response from the LLM (may contain sensitive data).
    """
    candidate_pair: tuple[str, str]  # entity IDs
    relation: Optional[str]
    direction: Optional[str]
    confidence: Optional[float]
    raw_response: Optional[Any] = None

PhaseCompleted

Bases: BaseEvent

A pipeline phase completed.

This event is emitted when a pipeline phase finishes execution.

Attributes

phase_name : str Name of the completed phase. duration_seconds : float Duration of the phase execution in seconds. artifact_count : int Number of artifacts produced by the phase. success : bool Whether the phase completed successfully. error_message : str, optional Error message if the phase failed.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
class PhaseCompleted(BaseEvent):
    """A pipeline phase completed.

    This event is emitted when a pipeline phase finishes execution.

    Attributes
    ----------
    phase_name : str
        Name of the completed phase.
    duration_seconds : float
        Duration of the phase execution in seconds.
    artifact_count : int
        Number of artifacts produced by the phase.
    success : bool
        Whether the phase completed successfully.
    error_message : str, optional
        Error message if the phase failed.
    """
    phase_name: str
    duration_seconds: float
    artifact_count: int
    success: bool
    error_message: Optional[str] = None

ProgressAdvanced

Bases: BaseEvent

A progress-tracked task has advanced.

Attributes

task_name : str Name of the task being tracked. advance : int Number of items processed in this step (default: 1).

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
574
575
576
577
578
579
580
581
582
583
584
585
class ProgressAdvanced(BaseEvent):
    """A progress-tracked task has advanced.

    Attributes
    ----------
    task_name : str
        Name of the task being tracked.
    advance : int
        Number of items processed in this step (default: 1).
    """
    task_name: str
    advance: int = 1

ProgressCompleted

Bases: BaseEvent

A progress-tracked task has completed.

Attributes

task_name : str Name of the task that completed.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
588
589
590
591
592
593
594
595
596
class ProgressCompleted(BaseEvent):
    """A progress-tracked task has completed.

    Attributes
    ----------
    task_name : str
        Name of the task that completed.
    """
    task_name: str

ProgressStarted

Bases: BaseEvent

A progress-tracked task has started.

Attributes

task_name : str Name of the task being tracked. total_items : int or None Total number of items to process, if known. description : str Optional description of the task.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
class ProgressStarted(BaseEvent):
    """A progress-tracked task has started.

    Attributes
    ----------
    task_name : str
        Name of the task being tracked.
    total_items : int or None
        Total number of items to process, if known.
    description : str
        Optional description of the task.
    """
    task_name: str
    total_items: Optional[int] = None
    description: str = ""

RerankerScoreAssigned

Bases: BaseEvent

A reranker assigned a score to a candidate pair.

This event is emitted when a reranker processes a candidate pair and assigns a score, which determines whether the candidate proceeds to the next stage.

Attributes

candidate_pair : tuple of (str, str) Pair of entity IDs that were scored. score : float Score assigned by the reranker. accepted : bool Whether the candidate was accepted based on the threshold. threshold : float Threshold used to determine acceptance. entity_a : dict, optional Compact metadata for the query-side entity. entity_b : dict, optional Compact metadata for the document-side entity. reranker_input : dict, optional Size metadata for the final reranker query/document pair. reranker_payload : dict, optional Serialized reranker query/document texts for observability backends. recovery_attempts : list of dict, optional Recovery metadata when the reranker required retries before scoring.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class RerankerScoreAssigned(BaseEvent):
    """A reranker assigned a score to a candidate pair.

    This event is emitted when a reranker processes a candidate pair and assigns
    a score, which determines whether the candidate proceeds to the next stage.

    Attributes
    ----------
    candidate_pair : tuple of (str, str)
        Pair of entity IDs that were scored.
    score : float
        Score assigned by the reranker.
    accepted : bool
        Whether the candidate was accepted based on the threshold.
    threshold : float
        Threshold used to determine acceptance.
    entity_a : dict, optional
        Compact metadata for the query-side entity.
    entity_b : dict, optional
        Compact metadata for the document-side entity.
    reranker_input : dict, optional
        Size metadata for the final reranker query/document pair.
    reranker_payload : dict, optional
        Serialized reranker query/document texts for observability backends.
    recovery_attempts : list of dict, optional
        Recovery metadata when the reranker required retries before scoring.
    """
    candidate_pair: tuple[str, str]  # entity IDs
    score: float
    accepted: bool
    threshold: float
    entity_a: Optional[dict[str, Any]] = None
    entity_b: Optional[dict[str, Any]] = None
    reranker_input: Optional[dict[str, Any]] = None
    reranker_payload: Optional[dict[str, str]] = None
    recovery_attempts: Optional[List[dict[str, Any]]] = None

SchemaValidationRejectedRelation

Bases: BaseEvent

Schema validation rejected a decoded relation.

This event is emitted when a decoded relation fails schema validation.

Attributes

candidate_pair : tuple of (str, str) Pair of entity IDs for which the relation was rejected. relation : str The relation that was rejected. reason : str Explanation of why the relation was rejected.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
class SchemaValidationRejectedRelation(BaseEvent):
    """Schema validation rejected a decoded relation.

    This event is emitted when a decoded relation fails schema validation.

    Attributes
    ----------
    candidate_pair : tuple of (str, str)
        Pair of entity IDs for which the relation was rejected.
    relation : str
        The relation that was rejected.
    reason : str
        Explanation of why the relation was rejected.
    """
    candidate_pair: tuple[str, str]  # entity IDs
    relation: str
    reason: str

TripleCommitted

Bases: BaseEvent

A triple was committed to the graph.

This event is emitted when a validated relation is committed as a triple to the knowledge graph.

Attributes

subject_id : str ID of the subject entity. predicate : str Predicate representing the relationship. object_id : str ID of the object entity. confidence : float Confidence score for the triple. scope : str Scope or context of the triple. source_chunk_id : str ID of the source text chunk.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
class TripleCommitted(BaseEvent):
    """A triple was committed to the graph.

    This event is emitted when a validated relation is committed as a triple
    to the knowledge graph.

    Attributes
    ----------
    subject_id : str
        ID of the subject entity.
    predicate : str
        Predicate representing the relationship.
    object_id : str
        ID of the object entity.
    confidence : float
        Confidence score for the triple.
    scope : str
        Scope or context of the triple.
    source_chunk_id : str
        ID of the source text chunk.
    """
    subject_id: str
    predicate: str
    object_id: str
    confidence: float
    scope: str
    source_chunk_id: str

UnlinkableMentionError

Bases: Exception

Raised when a mention cannot be linked to the graph (e.g., missing envelope).

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
17
18
19
class UnlinkableMentionError(Exception):
    """Raised when a mention cannot be linked to the graph (e.g., missing envelope)."""
    pass

ValidationViolationDetected

Bases: BaseEvent

A graph validation violation was detected.

Attributes

rule_name : str Name of the violated rule. source_id : str ID of the source node. target_id : str ID of the target node. description : str Description of the violation.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
class ValidationViolationDetected(BaseEvent):
    """A graph validation violation was detected.

    Attributes
    ----------
    rule_name : str
        Name of the violated rule.
    source_id : str
        ID of the source node.
    target_id : str
        ID of the target node.
    description : str
        Description of the violation.
    """
    rule_name: str
    source_id: str
    target_id: str
    description: str

get_event_type_name(event)

Get the type name of an event for serialization/logging.

Parameters

event : BaseEvent The event instance.

Returns

str Name of the event class.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
678
679
680
681
682
683
684
685
686
687
688
689
690
691
def get_event_type_name(event: BaseEvent) -> str:
    """Get the type name of an event for serialization/logging.

    Parameters
    ----------
    event : BaseEvent
        The event instance.

    Returns
    -------
    str
        Name of the event class.
    """
    return event.__class__.__name__

serialize_event(event)

Serialize an event to a dictionary.

Parameters

event : BaseEvent The event instance to serialize.

Returns

dict Dictionary representation of the event.

Source code in packages/episteme-pipeline/episteme_pipeline/events/models.py
694
695
696
697
698
699
700
701
702
703
704
705
706
707
def serialize_event(event: BaseEvent) -> dict:
    """Serialize an event to a dictionary.

    Parameters
    ----------
    event : BaseEvent
        The event instance to serialize.

    Returns
    -------
    dict
        Dictionary representation of the event.
    """
    return event.model_dump()

Built-ins

  • SimpleEventEmitter — in‑process broadcast list
  • JsonlRunObserver — context‑managed JSONL writer
  • LoggingObserver — level‑aware summaries
  • MetricsObserver — acceptance rates and totals
  • RichProgressObserver — terminal live progress bars and logger coordination (requires an interactive TTY)
  • CompositeObserver — fan‑out dispatcher
  • LangfuseObserver — event→span mapping (requires Langfuse)

Concurrency & performance

  • Observers should be fast; heavy work should buffer/async off the hot path.
  • Consider protecting CompositeObserver with failure isolation.