Skip to content

BlogGuides

Knowledge graph from PDF and code: one graph for both

· 5 minute read

A knowledge graph from PDF and code is one graph where functions and classes sit next to the design docs, specs, and papers that explain them. Graphify builds it in two passes. Code is parsed locally with tree-sitter. Docs, PDFs, Office files, and images are read by a model that links concepts to the code they describe.

Why build a knowledge graph from PDF and code together?Link to Why build a knowledge graph from PDF and code together?

Code says what a system does. Docs say why. When they live in separate tools, an agent sees the function but not the decision record behind it. One graph puts both in reach of one query. Asking "what implements the retry policy in the design doc?" returns the doc section and the functions in a single answer.

Which files can Graphify read alongside code?Link to Which files can Graphify read alongside code?

Graphify's README lists the supported file types and the optional extras some of them need. Code is parsed locally with tree-sitter. Markdown, PDFs, Office documents, and images go through the model pass instead. Check the table below before you add a folder, because files of an unsupported type are skipped rather than reported as errors.

| Type | Extensions | Extra needed | |---|---|---| | Code | .py .ts .go .rs .java and more | None | | Docs | .md .mdx .html .txt .rst .yaml | None | | PDFs | .pdf | None | | Office | .docx .xlsx | graphifyy[office] | | Images | .png .jpg .webp .gif | None | | Audio and video | .mp4 .mov .mp3 .wav | graphifyy[video] |

Install an extra with quotes around the name, for example uv tool install "graphifyy[office]".

How does Graphify extract a graph from PDFs and docs?Link to How does Graphify extract a graph from PDFs and docs?

It treats prose differently from code. Code has a syntax tree, so the parser reads calls and imports directly. A PDF has no tree. Graphify sends docs, PDFs, and images to a model, which returns entities and relationships. Office files are converted to text first. Audio and video are transcribed locally with faster-whisper, then extracted as text.

Edges from that pass are tagged INFERRED, with a confidence score. Edges parsed from code are EXTRACTED. Our post on Graphify's edge tags explains how to read them.

Comments count too. Notes such as # WHY: and # HACK:, docstrings, and design rationale from docs become their own nodes, linked to the code they explain.

How do you build the graph?Link to How do you build the graph?

Put the docs next to the code, or in a folder inside the project, so one run covers both. Graphify then reads code locally and sends only the documents to the model your assistant already uses. You do not need a separate API key for this route. Then run the skill in your assistant:

text
/graphify .

In Claude Code, the docs go to the model your session already uses. To add a paper or a page from the web, run /graphify add <url>. The --mode deep flag asks for more aggressive relationship extraction.

Can you extract without an IDE?Link to Can you extract without an IDE?

Yes. graphify extract runs the full extraction headless, which suits CI jobs, scheduled rebuilds, or scripts. It needs a model backend for the documents, because no assistant is present to read them. Code is still parsed locally. The README lists Gemini, Kimi, Claude, OpenAI, and a local Ollama instance:

bash
graphify extract ./docs --backend ollama

With Ollama, set OLLAMA_BASE_URL and OLLAMA_MODEL to point at your local model. Nothing leaves your machine in that setup. The Ollama documentation covers running a model locally.

What leaves your machine?Link to What leaves your machine?

The README's privacy section is specific. Code files are processed locally. Audio and video are transcribed locally. Docs, PDFs, and images go to your assistant's model for extraction, or to the backend you choose for headless runs. There is no telemetry. Keep sensitive documents out of the corpus with a .graphifyignore file, which uses .gitignore syntax.

How does this compare with RAG over documents?Link to How does this compare with RAG over documents?

Retrieval-augmented generation, introduced in a 2020 paper by Lewis and colleagues, retrieves text chunks that look similar to a question. A graph stores the relationships themselves: this doc section describes that function. You can follow those links, and each one carries a tag. The Graphify vs RAG page compares the two.

How do you keep document extraction small?Link to How do you keep document extraction small?

Graph only the documents that explain the code. Put design docs, specs and runbooks in the folder, and leave out exports, scans and archives. Add a .graphifyignore file to skip large or irrelevant paths. Code still parses locally with no model, so only the documents cost model tokens.

Start with one folder of docs. Check the result, then widen it.

FAQLink to FAQ

Do I need an API key to graph PDFs?Link to Do I need an API key to graph PDFs?

Inside an assistant, no extra key: the assistant's model does the work. Headless graphify extract needs a backend key or a local Ollama instance.

Are scanned PDFs supported?Link to Are scanned PDFs supported?

Graphify extracts from the PDF's text. A scan with no text layer gives the model little to read, so run OCR first.

Can I graph only the docs folder?Link to Can I graph only the docs folder?

Yes. Pass the folder, for example /graphify ./docs, or exclude paths with .graphifyignore.

Do doc edges update when files change?Link to Do doc edges update when files change?

Run /graphify . --update to re-extract only changed files. Code-only changes rebuild locally with graphify update ..

Where do the PDF results end up?Link to Where do the PDF results end up?

In graphify-out/graph.json, next to the code nodes. Each node records the source file it came from.

Try itLink to Try it

Graphify is open source on GitHub. Install it with uv: uv tool install graphifyy. The documents and media docs cover file types. New to setup on Windows? Read Graphify on Windows.

Try Graphify now.

Try for free