Pipeline¶
novelentitymatcher.pipeline.discovery
¶
Public pipeline-first discovery API.
Classes¶
DiscoveryPipeline(entities=None, *, matcher=None, review_storage_path='./proposals/review_records.json', config=None, **kwargs)
¶
Bases: DiscoveryBase
Pipeline-first public entry point for discovery and promotion workflows.
Owns its own Matcher, NoveltyDetector, ScalableClusterer, and LLMClassProposer instances, and routes everything through a PipelineOrchestrator built from PipelineConfig.
Source code in src/novelentitymatcher/pipeline/discovery.py
Attributes¶
novel_entity_matcher
property
¶
Backward-compatible alias exposing detector/llm_proposer as if from NovelEntityMatcher.
Functions¶
discover(queries, *, existing_classes=None, context=None, return_metadata=True, run_llm_proposal=None)
async
¶
Run the full pipeline: match -> OOD -> cluster -> evidence -> propose.
Source code in src/novelentitymatcher/pipeline/discovery.py
promote_proposal(review_id, *, promoter=None)
¶
Promote a review record, optionally invoking a promoter callback.
If no promoter is provided, a default promoter updates the matcher's known entities from the proposal.
Source code in src/novelentitymatcher/pipeline/discovery.py
Functions¶
novelentitymatcher.pipeline.config
¶
Unified pipeline configuration for the discovery pipeline.
Classes¶
PipelineConfig
¶
Bases: BaseModel
Unified configuration driving stage selection and optional capabilities.
Functions¶
from_dict(data)
classmethod
¶
Construct a PipelineConfig from a plain dictionary.
to_dict()
¶
stages()
¶
Return an ordered list of enabled stage names.
Source code in src/novelentitymatcher/pipeline/config.py
novelentitymatcher.pipeline.contracts
¶
Internal staged discovery pipeline contracts.
Classes¶
StageContext(inputs, artifacts=dict(), metadata=dict())
dataclass
¶
StageResult(stage_name, artifacts=dict(), metadata=dict(), contract_version='1.0', timing_ms=None, stage_config_snapshot=dict(), errors=list())
dataclass
¶
Result returned by a single pipeline stage.
PipelineRunResult(context, stage_results=list(), timing_breakdown=dict())
dataclass
¶
Terminal result for an internal pipeline run.
novelentitymatcher.pipeline.orchestrator
¶
Internal pipeline orchestrator.
novelentitymatcher.pipeline.pipeline_builder
¶
Pipeline builder that consolidates 5-stage discovery pipeline construction.
Classes¶
PipelineStageConfig(match_enabled=True, collect_sync=None, collect_async=None, detector=None, clusterer=None, llm_proposer=None, use_novelty_detector=True, clustering_enabled=True, clustering_backend='auto', similarity_threshold=0.75, min_cluster_size=5, clustering_metric='cosine', clustering_min_samples=None, clustering_cluster_selection_epsilon=0.0, evidence_enabled=True, evidence_method='tfidf', max_keywords=8, max_examples=4, token_budget=256, use_tfidf=None, run_llm_proposal=True, existing_classes_resolver=None, context_text=None, max_retries=2, prefer_cluster_level=True, ood_strategies=None, ood_calibration_mode='none', ood_calibration_alpha=0.1, ood_mahalanobis_mode='class_conditional', proposal_mode='cluster', proposal_schema_discovery=False, proposal_schema_max_attributes=10, proposal_hierarchical=True)
dataclass
¶
Configuration for a single pipeline stage.
PipelineBuilder(config=None, **kwargs)
¶
Builds a 5-stage discovery pipeline orchestrator.
Consolidates pipeline construction logic that was previously duplicated between DiscoveryPipeline and NovelEntityMatcher.
Source code in src/novelentitymatcher/pipeline/pipeline_builder.py
Functions¶
build(*, existing_classes=None, context=None, run_llm_proposal=None)
¶
Build the 5-stage pipeline orchestrator.
Source code in src/novelentitymatcher/pipeline/pipeline_builder.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
from_pipeline_config(config, *, collect_sync=None, collect_async=None, detector=None, clusterer=None, llm_proposer=None, existing_classes_resolver=None)
classmethod
¶
Factory to create PipelineBuilder from a PipelineConfig object.
Source code in src/novelentitymatcher/pipeline/pipeline_builder.py
novelentitymatcher.pipeline.adapters
¶
Adapters that route existing matcher and discovery capabilities through stages.
Classes¶
MatcherMetadataStage(collect_sync, collect_async)
¶
Bases: PipelineStage
Collect rich matcher metadata and reference corpus for downstream stages.
Source code in src/novelentitymatcher/pipeline/adapters.py
OODDetectionStage(detector, enabled=True, ood_strategies=None, ood_calibration_mode='none', ood_calibration_alpha=0.1, ood_mahalanobis_mode='class_conditional')
¶
Bases: PipelineStage
Run novelty detection against the stable matcher metadata contract.
Source code in src/novelentitymatcher/pipeline/adapters.py
CommunityDetectionStage(clusterer, *, enabled=True, similarity_threshold=0.75, min_cluster_size=2, clustering_metric='cosine')
¶
Bases: PipelineStage
Cluster likely novel samples into discovery communities.
Source code in src/novelentitymatcher/pipeline/adapters.py
ClusterEvidenceStage(*, enabled=True, max_keywords=8, max_examples=4, token_budget=256, use_rake=True, evidence_method='tfidf', use_tfidf=None)
¶
Bases: PipelineStage
Extract compact evidence from clusters before proposal generation.
Source code in src/novelentitymatcher/pipeline/adapters.py
ProposalStage(proposer, existing_classes_resolver, enabled=True, context_text=None, max_retries=2, force_cluster_level=True, proposal_mode='cluster', proposal_schema_discovery=False, proposal_schema_max_attributes=10, proposal_hierarchical=True)
¶
Bases: PipelineStage
Optionally generate class proposals from a novelty report.
Source code in src/novelentitymatcher/pipeline/adapters.py
novelentitymatcher.pipeline.discovery_support
¶
Shared helpers for novelty-aware match and discovery orchestration.
Classes¶
Functions¶
collect_match_result_async(matcher, queries, top_k=5)
async
¶
Async helper to collect match result and reference corpus.
Consolidates duplicated logic from NovelEntityMatcher and DiscoveryPipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matcher
|
Any
|
Matcher instance |
required |
queries
|
list[str]
|
List of query texts |
required |
top_k
|
int
|
Number of top candidates to retrieve |
5
|
Returns:
| Type | Description |
|---|---|
tuple[MatchResultWithMetadata, dict[str, Any]]
|
Tuple of (match_result, reference_corpus) |
Source code in src/novelentitymatcher/pipeline/discovery_support.py
collect_match_result_sync(matcher, queries, top_k=5)
¶
Sync helper to collect match result and reference corpus.
Consolidates duplicated logic from NovelEntityMatcher and DiscoveryPipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matcher
|
Any
|
Matcher instance |
required |
queries
|
list[str]
|
List of query texts |
required |
top_k
|
int
|
Number of top candidates to retrieve |
5
|
Returns:
| Type | Description |
|---|---|
tuple[MatchResultWithMetadata, dict[str, Any]]
|
Tuple of (match_result, reference_corpus) |
Source code in src/novelentitymatcher/pipeline/discovery_support.py
export_pipeline_metrics(*, metrics, format='json', path=None)
¶
Export pipeline metrics to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict[str, Any]
|
Key-value pairs of metric data. |
required |
format
|
str
|
Export format ('json' or 'csv'). |
'json'
|
path
|
str | None
|
Output file path (default: './metrics_{timestamp}.{ext}'). |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to exported metrics file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If format is not 'json' or 'csv'. |
Source code in src/novelentitymatcher/pipeline/discovery_support.py
novelentitymatcher.pipeline.match_result
¶
Stable matcher metadata contracts used by novelty and pipeline internals.
Classes¶
MatchRecord(text, predicted_id, confidence, embedding, candidates=list(), raw_result=None, metadata=dict(), match_method=None, reference_embedding=None, distance=None)
dataclass
¶
Normalized per-query match metadata for downstream discovery stages.
MatchResultWithMetadata(predictions, confidences, embeddings, scores=None, metadata=None, candidate_results=list(), records=list())
dataclass
¶
Enhanced match result with stable downstream metadata.
The legacy attributes (predictions, confidences, embeddings, metadata)
remain available, while candidate_results and records provide a consistent
contract for novelty and pipeline stages.
Functions¶
normalize_candidate_results(raw_match_results, num_queries)
¶
Normalize raw matcher outputs into a stable list-of-lists shape.
Source code in src/novelentitymatcher/pipeline/match_result.py
build_match_records(texts, predictions, confidences, embeddings, candidate_results, match_method=None, reference_embeddings=None)
¶
Build normalized per-query records for downstream pipeline stages.
Source code in src/novelentitymatcher/pipeline/match_result.py
build_match_result_with_metadata(texts, predictions, confidences, embeddings, raw_match_results, metadata=None, scores=None, match_method=None)
¶
Create a stable metadata result from matcher outputs.
Source code in src/novelentitymatcher/pipeline/match_result.py
convert_match_result_to_metadata(match_result, embeddings, confidences=None)
¶
Convert standard match result to metadata-enhanced result.