All skills
github avatar

/mini-context-graph

@4214189 official
by githubgithub/awesome-copilot40k stars
5,040

A persistent, compounding knowledge base combining Karpathy's LLM Wiki pattern with a structured knowledge graph. Ingest documents once — the LLM writes wiki pages, extracts entities/relations into the graph, and stores raw content for evidence retrieval. Knowledge accumulates and cross-references; it is never re-derived from scratch.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/mini-context-graph

This session only. Nothing lands on disk.

referencesretrieval.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Retrieval Instructions

This file defines how the agent answers queries using the two-layer retrieval strategy: wiki-first (fast path), then graph traversal with evidence (deep path).


Overview

Retrieval is a 7-step process:

  1. Parse the query
  2. Check the wiki first (fast path)
  3. Find seed nodes in the graph
  4. Expand the graph via BFS
  5. Prune noisy nodes
  6. Build the subgraph with provenance
  7. Return structured context

Step 1: Parse the Query

Read the query string and identify:

  • Key noun phrases: potential entity names (e.g., "system crash", "memory leak")
  • Keywords: individual meaningful words (e.g., "crash", "leak", "memory")
  • Normalize all terms to lowercase

Ignore stopwords (e.g., "the", "a", "is", "why", "does", "how", "what").


Step 2: Check the Wiki First (Fast Path)

Before touching the graph, search the wiki. The wiki contains compiled knowledge — cross-references already resolved, contradictions flagged, syntheses written.

from scripts.tools import wiki_store

results = wiki_store.search_wiki(query)

For each relevant result, read the page:

content = wiki_store.read_page_by_slug(result["slug"])

If the wiki has a sufficient answer:

  • Synthesize from wiki pages.
  • Cite the source pages (e.g., "According to [[memory-leak]] and [[system-crash]]...").
  • File the answer as a new wiki topic page if it's valuable and not already captured:
    wiki_store.write_page(category="topic", title="Why System Crashes", content=..., summary=...)
  • Return early — no graph traversal needed.

If the wiki answer is incomplete or missing: proceed to Step 3.


Step 3: Find Seed Nodes

Call index_store.search(query) with the original query string.

This returns node IDs matching entity names or keywords.

If no seed nodes are found:

  • Try searching with individual keywords from Step 1.
  • If still no results, return an empty subgraph: "No relevant entities found."

Step 4: Expand the Graph (BFS)

Call retrieval_engine.retrieve(seed_node_ids, depth=2).

BFS from seed nodes:

  • Depth 1: direct neighbors
  • Depth 2: neighbors of neighbors

Rules:

  • Only traverse edges with confidence ≥ MIN_CONFIDENCE (from config.py)
  • Do NOT traverse beyond depth 2
  • Collect all visited node IDs

Step 5: Prune Nodes

  • Limit total nodes to MAX_NODES (from config.py)
  • Prioritize:
    1. Seed nodes (always include)
    2. Nodes at depth 1
    3. Nodes at depth 2 (as space allows)
  • Remove nodes only weakly connected (edge confidence < MIN_CONFIDENCE)

Step 6: Build the Subgraph with Provenance

For a standard query, call:

subgraph = skill.query(query)
# Returns: {"nodes": {node_id: {name, type, source_document, source_chunks}},
#           "edges": [{source, target, type, confidence, source_document, supporting_text, chunk_id}]}

For queries requiring evidence (citations, fact-checking), call:

result = skill.query_with_evidence(query)
# Returns:
# {
#   "query": str,
#   "subgraph": {"nodes": {...}, "edges": [...]},
#   "supporting_documents": [
#     {
#       "doc_id": str,
#       "doc_title": str,
#       "supporting_chunks": [{"chunk_id": str, "text": str}, ...]
#     }
#   ],
#   "evidence_chain": "memory leak --[causes]--> system crash"
# }

Step 7: Return Structured Context

Return the result with:

  • Subgraph: nodes + edges (the graph answer)
  • Supporting documents: source chunks that prove each relation
  • Evidence chain: human-readable path summary
  • Wiki references: links to relevant wiki pages found in Step 2

If valuable, file the answer back into the wiki:

wiki_store.write_page(
    category="topic",
    title=query,
    content=f"# {query}\n\n**Evidence chain:** {result['evidence_chain']}\n\n...",
    summary="...",
)

This way, future queries on the same topic find the answer instantly in the wiki.


Rules

  • NEVER fabricate nodes or edges not present in the graph
  • NEVER traverse deeper than depth 2
  • ALWAYS check the wiki before the graph (wiki-first)
  • Always include seed nodes in the result, even if they have no edges
  • Prefer edges with higher confidence when pruning
  • File valuable answers back into the wiki as topic pages
  • Return an empty subgraph (not an error) if no relevant nodes are found

Source: SKILL.md on GitHub

No alerts15d3 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    The skill is safe to use but contains a potential vulnerability to indirect prompt injection due to its design of processing untrusted document content without strict boundary markers.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

Signed by skilld at 4214189. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
  • Python
  • knowledge-graph
  • rag
  • wiki
  • persistence
  • entity-extraction
  • provenance
  • llm

README badge

README badge for github/awesome-copilot/mini-context-graph

Builds a persistent knowledge base that combines markdown wiki pages with a structured entity-relation graph, extracting entities and relations from ingested documents once and storing them with full provenance. On query, it searches the wiki first for fast answers, then traverses the graph with confidence thresholds and depth limits to retrieve evidence-backed subgraphs without re-deriving knowledge from scratch.

Generated from the current SKILL.md.

Does this skill re-ingest documents on every query?
No. Documents are ingested once — entities, relations, and wiki pages are extracted and stored persistently. Queries traverse the stored graph and wiki without re-deriving knowledge from source text.
What happens if I ingest a document that contradicts existing graph data?
The skill stores both versions with provenance links. The SKILL.md requires flagging contradictions in wiki pages when new data conflicts with old claims, so the LLM can reconcile them during synthesis.
Can I query without writing to the wiki?
Yes. `skill.query_with_evidence()` and `skill.query()` retrieve from the graph without modifying it. However, the workflow pattern expects the LLM to write wiki pages after ingesting or answering valuable queries.
What's the maximum graph depth for a query?
Traversal depth is capped at 2 hops (configurable MAX_GRAPH_DEPTH). Only edges with confidence >= 0.6 are traversed, and results are limited to 50 nodes maximum.
Do I need to provide supporting text for every entity and relation?
Yes. Every entity and relation must include `supporting_text` from the source document. This enables provenance tracking and prevents hallucinated graph nodes.

Generated from the current SKILL.md. These answers refresh after source changes.