ts-kg-build

Builds a research-pattern knowledge graph from a paper corpus using embeddings and clustering.

1.1k|19|Updated Jun 18, 2026
One-click install
npx skills add https://github.com/Spark-To-Paper-Skills/spark-to-paper-skills --skill ts-kg-build-spark-to-paper-skills
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ts-kg-build
Source: https://github.com/Spark-To-Paper-Skills/spark-to-paper-skills/tree/main/skills/ts-kg-build
Command: npx skills add https://github.com/Spark-To-Paper-Skills/spark-to-paper-skills --skill ts-kg-build-spark-to-paper-skills

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, scikit-learn, and includes scripts (resource) components.

What problem does it solve? Turning a raw corpus of academic papers into a reusable, structured knowledge graph of research patterns (problem, solution, story) is labor-intensive, and without it downstream idea-generation tools cannot recall prior problem-to-solution patterns for a new research idea. ## Core Features & Use Cases - Story-first pattern extraction: Claude reframes each paper's abstract into a transferable base_problem, solution_pattern, story, application, and idea seed, with self-QC rules against generic summaries. - Deterministic embedding and clustering: Scripts call a user-supplied OpenAI-compatible embedding endpoint and cluster papers with cosine-based AgglomerativeClustering (KMeans fallback), reporting membership, coherence, and exemplars. - Graph assembly and validation: kg_build.py deterministically creates paper/idea/pattern/domain nodes and typed edges (uses_pattern, in_domain, belongs_to, works_well_in), and kg_lint.py gates the output before downstream recall. - Use Case: Given a corpus.jsonl of 79 time-series papers, build a kg/ directory that ts-idea2story can recall over to surface relevant research patterns for a new idea; without an embedding endpoint it degrades to a lite in-context pattern shelf. ## Quick Start Build a research-pattern knowledge graph from my corpus.jsonl of papers for the time-series domain, using my configured embedding endpoint if available.

Frequently Asked Questions about ts-kg-build

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a knowledge graph from a corpus of research papers?

Provide a corpus.jsonl with one paper per line (paper_id, title, abstract, venue, year, and optional review scores), then run the extraction, embedding, clustering, and kg_build.py assembly steps. The output is a kg/ directory with nodes and edges JSON files validated by kg_lint.py.

What embedding models can I use for clustering paper abstracts?

Any OpenAI-compatible embeddings endpoint works by setting TS_EMBED_MODEL, TS_EMBED_API_KEY, and TS_EMBED_BASE_URL, for example text-embedding-3-large or bge-m3. The scripts batch requests and store a manifest with the model id so recall never mixes embedding spaces.

Can I build the knowledge graph without an embedding API key?

Yes, the skill degrades to a lite mode: per-paper patterns are written to patterns_shelf.jsonl and downstream recall reads the shelf in context instead of using clustered embeddings. This works for small corpora but produces no clusters or edges.

What clustering algorithm is used to group research patterns?

The cluster.py script uses scikit-learn AgglomerativeClustering with cosine distance and a configurable merge threshold, falling back to KMeans if agglomerative clustering fails. It reports per-member membership scores, cluster coherence, and exemplar papers.

Why does kg_lint.py report validation issues on my knowledge graph?

kg_lint.py fails when patterns have empty names, summaries, domains, or exemplar lists, when exemplars reference unknown paper ids, or when edges use unknown relations. Fix the flagged fields in cluster metadata or the papers file and rerun the lint until it returns ok true.