Skip to main content

Overview

Each pipeline function corresponds to a CLI command but takes explicit parameters instead of reading from config files. Use these from Jupyter notebooks, web apps, or anywhere you want sift-kg as a library.

run_pipeline

Run the full pipeline: extract → build → narrate. Skips resolve/apply-merges (those require human review).

Signature

Parameters

Path
required
Directory containing documents (PDF, text, HTML, 75+ formats)
str
required
LLM model string (e.g. "openai/gpt-4o-mini", "anthropic/claude-3-5-sonnet-20241022")
DomainConfig
required
Domain configuration object loaded via load_domain()
Path
required
Output directory for all artifacts (extractions, graph, narratives)
float | None
default:"None"
Budget cap in USD. Pipeline stops if cost exceeds this limit.
bool
default:"True"
Whether to generate narrative summary at the end

Returns

Path
Path to output directory containing all pipeline artifacts

Example


run_extract

Extract entities and relations from all documents in a directory.

Signature

Parameters

Path
required
Directory containing documents to extract from
str
required
LLM model string (e.g. "openai/gpt-4o-mini")
DomainConfig
required
Domain configuration
Path
required
Where to save extraction JSON files
float | None
default:"None"
Budget cap in USD
int
default:"4"
Concurrent LLM calls per document
int
default:"10000"
Characters per text chunk. Larger = fewer API calls but longer context.
bool
default:"False"
Re-extract all documents, ignoring cached results
str
default:"kreuzberg"
Extraction backend — "kreuzberg" (default) or "pdfplumber"
bool
default:"False"
Enable OCR for scanned documents
str
default:"tesseract"
OCR engine — "tesseract", "easyocr", "paddleocr", or "gcv"
str
default:"eng"
OCR language code (ISO 639-3, e.g. "eng", "spa", "fra")
int
default:"40"
Max requests per minute for rate limiting

Returns

list[DocumentExtraction]
List of extraction results, one per document

Example


run_build

Build knowledge graph from extraction results. Also flags relations for review and saves the graph.

Signature

Parameters

Path
required
Directory with extraction JSON files (from run_extract)
DomainConfig
required
Domain configuration (used for review_required types)
float
default:"0.7"
Flag relations below this confidence for human review
bool
default:"True"
Whether to remove redundant edges during graph construction

Returns

KnowledgeGraph
Populated knowledge graph saved to output_dir/graph_data.json

Example


run_resolve

Find duplicate entities using LLM-based resolution. Generates merge proposals for human review.

Signature

Parameters

Path
required
Directory with graph_data.json
str
required
LLM model string for entity comparison
DomainConfig | None
default:"None"
Domain configuration (provides system context for smarter resolution)
bool
default:"False"
Use semantic clustering for batching candidates (requires sift-kg[embeddings])
int
default:"4"
Concurrent LLM calls
int
default:"40"
Max requests per minute

Returns

MergeFile
Merge file with DRAFT proposals saved to output_dir/merge_proposals.yaml

Example


run_apply_merges

Apply confirmed entity merges and relation rejections after human review.

Signature

Parameters

Path
required
Directory with graph_data.json and review files (merge_proposals.yaml, relation_review.yaml)

Returns

dict
Stats dict with keys:
  • merges_applied (int): Number of entity merges applied
  • rejected_count (int): Number of relations rejected

Example


run_narrate

Generate narrative summary from the knowledge graph using community detection and LLM summarization.

Signature

Parameters

Path
required
Directory with graph_data.json
str
required
LLM model string
str
default:""
Optional domain context injected into LLM prompts
bool
default:"True"
Generate per-entity descriptions (more expensive)
float | None
default:"None"
Budget cap in USD
bool
default:"False"
Only regenerate community labels (~$0.01 cost)

Returns

Path
Path to generated narrative.md or communities.json

Example


run_view

Generate interactive graph visualization with optional pre-filters.

Signature

Parameters

Path
required
Directory with graph_data.json
Path | None
default:"None"
Output HTML path (default: output_dir/graph.html)
bool
default:"True"
Whether to open the visualization in a browser automatically
int | None
default:"None"
Show only top N entities by degree (useful for large graphs)
float | None
default:"None"
Hide nodes/edges below this confidence threshold
str | None
default:"None"
Show only entities from this document
str | None
default:"None"
Center visualization on entity ID (e.g. "person:alice")
int
default:"1"
Number of hops for neighborhood filter (used with neighborhood)
str | None
default:"None"
Focus on a specific community label

Returns

Path
Path to generated interactive HTML file

Example


run_export

Export the knowledge graph to various formats.

Signature

Parameters

Path
required
Directory with graph_data.json
str
default:"json"
Export format — "json", "graphml", "gexf", "csv", or "sqlite"
Path | None
default:"None"
Where to write output (default: output_dir/graph.{fmt})

Returns

Path
Path to the exported file or directory (for CSV format)

Example