Skip to content
المشاريع

حول

مولّد رسوم بيانية معرفية مدعوم بالذكاء الاصطناعي.

البيانات والتحليلات

كيف تُقاس هذه الأرقام

3,145 نجمة421 التفرعات +1 خلال 24 ساعة

النمو المقاس للنجوم

خلال 24 ساعة
+١
خلال 7 أيام
+١
خلال 15 يومًا
+٣
خلال شهر
+١٠

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

AI Knowledge Graph

Turn documents into a knowledge map you can explore, question, correct, and grow. Use your choice of LLM, keep your collections in local files, and share interactive stories as portable HTML.

Explore the live examples · Workspace guide · Use from Claude (MCP) · Configuration · Contributing

Knowledge graph example

What's new

  • Inspect the evidence. Relationships carry exact source passages, document names, character offsets, and PDF page numbers. Claims repeated across documents retain all supporting passages.
  • Build a lasting collection. Add, update, or remove documents without re-extracting unchanged files. Preview document changes before generation and inspect claim changes before applying a browser update.
  • Correct your graph. Reject and restore claims, edit what a claim says (or let the model suggest the wording from the passage), merge entity names, and undo any of it. Corrections and saved views live alongside the original claims.
  • Follow a story. Start with community discovery cards, focus on a neighborhood, expand outward, trace a path, and save annotated views. Export a sequence of views as an offline interactive story.
  • Find the claims worth a second look. --verify asks the model whether each claim's passage really supports it, and lists the ones it doubts for you to reject or keep.
  • Read a summary you can check. Themes and entities can carry a few model-written sentences, each ending with numbers that open the claims behind it. They are marked when the claims they were written from change.
  • Ask better questions. Chat retrieves Unicode names, aliases, and source-passage terms. Overview questions draw facts from across communities. Inline citations open evidence; an extracted-only option excludes inferred facts from retrieved context.
  • Choose the task. General reading, research literature, and organizations profiles guide extraction. Relationships preserve negation, time, attribution, and full predicate text when supplied by the model.
  • See what is happening. Check the model connection, try a short extraction, inspect progress and extraction usage, cancel work, and retry partial runs.

The lightweight core still exports JSON, CSV, GraphML, Cypher, an Obsidian vault, and self-contained HTML. It needs no database or vector service. New generation and chat use an OpenAI-compatible chat completions endpoint; exploring existing graphs does not require one.

Quick start

Python 3.11 or later is required.

git clone https://github.com/robert-mcdermott/ai-knowledge-graph.git
cd ai-knowledge-graph
uv sync --extra web
# Alternative: pip install -e ".[web]"

Try the included graphs without calling a model:

uv run graph-serve --graphs data/samples --read-only --open

--read-only lets you explore and ask questions but refuses corrections, saved views and document updates, so the tracked sample files are not edited. Copy them elsewhere and drop the flag to try the review tools.

Or render an example as an offline file:

uv run generate-graph --from-json data/samples/marie-curie.json --output out/marie-curie.html

To use your own documents, set [llm].model and [llm].base_url in config.toml, or create a separate configuration file. For a local endpoint, for example:

[llm]
model = "your-installed-model"
base_url = "http://localhost:11434/v1/chat/completions"

For an endpoint requiring credentials, use api_key = "env:LLM_API_KEY" and set that environment variable. See the configuration reference for all settings.

uv run generate-graph --check
uv run graph-serve --graphs out --open

In the browser, paste text or upload documents, choose an extraction profile, and select Preview changes. Try a short extraction tests the first 2,000 characters of pasted text. The preview of document changes makes no model calls; connection checks, trial extraction, generation, and chat use your configured endpoint.

For PDF and DOCX input, install their extras with uv sync --extra all or pip install -e ".[all]". Scanned PDFs need OCR before import.

Grow a collection from the command line

# Create a collection, retaining its sources and corrections
uv run generate-graph --collection out/research.json --input papers/ --profile research

# Add a web page: the readable text of the page becomes a document named after its title
uv run generate-graph --collection out/research.json --url https://example.org/an-article

# Preview an addition or revision without extraction or writes
uv run generate-graph --collection out/research.json --input new-paper.txt --preview-update

# Apply the change; unchanged documents are skipped
uv run generate-graph --collection out/research.json --input new-paper.txt

# Remove one document and only its evidence
uv run generate-graph --collection out/research.json --remove-document new-paper.txt

# Check every claim against the passage it cites, and list the doubted ones
uv run generate-graph --collection out/research.json --verify

# Write a short cited summary of each theme (one model request per theme)
uv run generate-graph --collection out/research.json --summarize

# Ask a question using extracted facts
uv run graph-chat out/research.json "What are the main themes?" --extracted-only

A document's name identifies it within a collection. Reusing the name replaces that document; use distinct names for distinct sources. The browser stages updates for review; the CLI applies them directly. See the workspace guide for retries, source identity, corrections, and backups.

The original single-run workflow is also available:

uv run generate-graph --input data/industrial-revolution.txt --output out/industrial.html
uv run generate-graph --input notes.txt --output out/notes.html --no-inference --strict-evidence
uv run generate-graph --from-json out/notes.json --output out/notes.html --export csv,graphml,cypher
uv run graph-chat out/notes.json "What connections does this document describe?"

Use generate-graph --help, graph-chat --help, graph-serve --help, and graph-mcp --help for every option. --preview limits ordinary generation to the first 2,000 characters of the first document; choose a separate output name for that trial.

Use a collection from Claude

graph-mcp is an MCP server that lets Claude Code, Claude Desktop and other agents search your collections, trace connections, quote the source passage behind a claim, and add documents. Reading makes no model calls; the agent writes the answer from the claims it retrieves.

uv sync --extra mcp
uv run graph-mcp --graphs data/samples --read-only --check    # what a client would see
claude mcp add knowledge-graph -- uv run --directory /path/to/ai-knowledge-graph --extra mcp graph-mcp --graphs out

Then ask, for example, "What does my research collection say about radium, and where does it say it?" See the MCP guide for Claude Desktop setup, the tool list, and what --read-only turns off.

Explore, review, and share

  1. Pick a theme in Explore, or search for an entity with /.
  2. Select Focus nearby, then Expand to grow the visible neighborhood. Full map clears the neighborhood restriction; other filters still apply.
  3. Open a source passage to inspect a claim. Source-linked means the cited passage exists, not that the claim has been independently verified. Legacy source text is explicitly marked unverified.
  4. Use Review in the local app to reject/restore claims or merge/unmerge names, and Edit this claim in a claim's evidence to correct its wording. Claims a check doubted are listed in Review first.
  5. Save a title and note in Stories. Saved views retain selection, filters, path, and camera position. Play story walks through the views; Export HTML packages them for offline viewing.

Share view copies a link with the current view in its URL. Recipients need access to the same graph URL; a localhost link only works on your machine. For a portable result, export the HTML story instead.

A graph of more than 300 entities opens with each theme drawn as one circle; click a circle to open it, or use Group themes (g) to regroup or open them all. Timeline appears when claims carry dates: drag the slider or press Play to watch the graph grow, by day or month when the dates name them and by year otherwise, with a line saying what each step adds. Sources filters by document, and Read opens a document with the passages behind its claims highlighted; click a passage to see what was drawn from it. Communities filters by community, entity type, relationship, and minimum connections. Display contains physics, labels, inferred-edge visibility, fitting, and statistics. Export writes visible triples as JSON/CSV or an image as PNG. Dark mode is remembered in the browser.

Static pages can save views in browser storage and export stories, and show the summaries stored with the collection. Persistent claim corrections, collection changes, writing a summary, and model-backed chat require graph-serve.

Understand the evidence

A selected entity with its dated, source-linked claims

Extraction first gives the model labeled passages and then checks its returned source IDs against those passages. It never guesses a citation by matching entity names. With --strict-evidence, any claim lacking a valid source reference fails its chunk, allowing an explicit retry. Without it, such claims are retained as unverified.

Source references do not establish entailment: a model can still link a real passage to an incorrect claim. --verify (or Check all claims in the Review panel) asks the model a second time, claim by claim, whether the passage says it, and lists the claims it doubts with a reason so that you can reject or keep them. That check is also a model's judgement and can be wrong either way, so review the passage before relying on a relationship. Inferred edges are dashed and record their method. A relationship a model proposed is kept only when the model, shown the passages about both entities, points at one that supports it; that passage is shown with the claim. The check is made by a model and can be wrong. Rule-based links, such as “steel production is a production”, follow from the names and are not checked; a path through a graph is a connection, not proof of causation. Chat citation validation resolves fact numbers but does not independently verify the answer.

Full relationship text and qualifiers remain in JSON and exports. Claim identity includes polarity, time, and attribution, so differently qualified claims are not silently collapsed. Duplicate evidence references are deduplicated; multiple documents are not automatically treated as independent corroboration.

Files and compatibility

File Contents
name.json Compatible flat list of the currently active triples
name.workspace.json Versioned sources, original claims, corrections, saved views, summaries, and recent run summaries
name.html Portable explorer, including evidence and saved views
name.meta.json Stored community names and generation metadata
name.csv, .graphml, .cypher, name-vault/ Optional exports (--export csv,graphml,cypher,obsidian); the vault is a folder of linked Obsidian notes

Keep the workspace sidecar with its JSON file. It is authoritative when present; edit through the app instead of modifying only the flat export. Older triples files still open without a migration. Their old source snippets remain unverified until regenerated from the original documents.

generate-graph.py, json_to_html.py and requirements.txt at the repository root exist only so that older instructions keep working: the two scripts run the same code as the installed commands, and requirements.txt is an export of the dependencies for pip. New set-ups should use uv run generate-graph and the other commands above.

The local server defaults to out/ and binds to 127.0.0.1:8008. It has no accounts or authentication and is intended for personal local use. Generation sends source text to your configured model endpoint. Workspace files retain the extracted text; back up or share them accordingly. One generation or pending update runs at a time; jobs are kept in .jobs/ inside the graphs folder, so an update waiting to be applied survives a restart.

Examples and development

The six committed examples cover the Manhattan Project, the Industrial Revolutions, Marie Curie, the Apollo Program, a coffee supply chain, and the Alhambra in Spanish. The Manhattan Project example is built from eight documents (about 6,000 words, in data/samples/manhattan-project/) and has about 640 entities; use its Sources panel to see the graph one document at a time. The others are single short texts. Every extracted claim links to its source passage, and many carry a date. Each example has cited summaries of its themes and of its most connected entities, and its claims have been checked against their passages: open Review to see the few the check doubted. They can be explored offline. Chat and regenerating the examples require your model.

uv sync --extra dev --extra all
uv run ruff check src tests
uv run pytest -q
uv run python scripts/build_docs.py

The last command rebuilds the GitHub Pages gallery from existing sample JSON without model calls. Shared-library gallery pages export a self-contained story by embedding their loaded assets; when opened directly from disk, re-render with --from-json without --library-path if the browser blocks fetching those local assets.

See CONTRIBUTING.md for architecture and validation, CHANGELOG.md for this release, and the roadmap for what comes next.

Troubleshooting

  • Connection check fails: verify the endpoint URL, model name, credentials, and that a local model server is running. The check bypasses the reply cache.
  • Empty, truncated, or invalid extraction: inspect the reported chunk error. Increase the response budget or reduce chunk size. --continue-on-error publishes explicit partial results; the browser offers a retry.
  • A partial collection: retry through its job page, or resubmit the affected documents using --collection. Cached successful requests can be reused; failed or malformed extraction replies are not retained as successful cache entries.
  • An update conflicts: the collection changed after extraction. Discard the pending update and create a fresh preview. This preserves newer corrections and views.
  • Missing links in a filtered graph: clear the source, relationship, community, type, and neighborhood filters. Turn on inferred edges only if you want model- or rule-proposed connections too.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…