The first version of my personal knowledge graph came together over a couple of days. By the end of it it had a Neo4j graph over my Paperless-ngx archive, embeddings in pgvector, a Next.js graph explorer, streaming answers with citations, and every model call routed through my self-hosted LiteLLM proxy. Almost everything I've done since has been about making that first version right instead of making it bigger.
This post is about building it. The project page describes how the system works now, layer by layer. Here I want to cover why I built it, what surprised me along the way, and what I'd do differently if I started again.
Tap to enlarge, then pinch to zoom
Why keyword search wasn't enough
Paperless-ngx is a great home for paperwork. It takes in scans and uploads, runs OCR, applies tags, and gives every document an ID, metadata and text through its API. As of writing, my archive holds just over a thousand documents, mostly the usual mix of tax forms, insurance policies, statements, receipts and contracts.
Keyword search finds documents. It doesn't answer questions. I can search for my insurance company and get every document that mentions it, but I can't ask "what's my deductible across all my policies?" or "what estimated tax payments did I make last year?" Those take reading several documents, knowing which one is newer, and putting the pieces together. A graph seemed like the right shape for that. A utility company connects to an account number, the account connects to an address, and the address connects to payment records across several years. You can walk those relationships even when two documents share no words at all.
I also didn't want to touch Paperless itself. It stays the source of truth, and everything the graph knows can be rebuilt from it. Documents that Tesseract reads badly can go through Paperless OCR Enhanced first, which writes better text back into Paperless through the API. The graph just reads whatever text Paperless has.
The first version was simple on purpose. Each document got classified, an LLM pulled out people, organizations, dates and amounts, and those went into Neo4j as nodes and relationships. Document text went into PostgreSQL as chunks with embeddings. There were two ways to ask a question. A fast graph search went straight to Neo4j, and a deep mode retrieved chunks and graph context and had a model write a cited answer.
The first surprise came within hours. I'd started with OpenAI's text-embedding-3-small and switched to text-embedding-3-large almost immediately, which took the vectors from 1,536 dimensions to 3,072. Then I added HNSW indexes, replaced them with IVFFlat because HNSW wouldn't take vectors that wide, and later swapped IVFFlat back out for HNSW for the same reason. pgvector's HNSW and IVFFlat indexes both top out at 2,000 dimensions for the plain vector type, and it took a round of switching between them before I accepted it. So I made index creation catch the error and fall back to a sequential scan, with a commit note saying that was fine under 10,000 rows. I treated that fallback as temporary. It turned into the design. The app now creates no vector index at all, and every search is an exact scan. I tried approximate indexes again later, but normal retrieval never stopped using the exact scan, and those experiments have since been deleted.
Tap to enlarge, then pinch to zoom
The resolver merged two different people
The second surprise came on day two, and it changed how I think about the whole project. I was using fuzzy matching to decide when two mentions referred to the same entity, and one of the scores was a token-set ratio. It ignores the words two names don't share, so when every word of one name appears in the other, it returns 100. "Mary Ann Smith" and "Ann Smith" score 100, even when they're two different people. The resolver merged pairs like that.
Merging two people is far worse than missing a merge. Every answer that touches either person now draws on both people's records, and nothing in the answer tells you that happened. A missed merge just leaves two nodes where there should be one, and I can fix it whenever I notice.
My first fixes were reasonable patches. Person matching stopped using the token-set score. A first-name compatibility check blocked merges between clearly different first names. A single-word name could no longer absorb a longer one, so "Matthew" couldn't swallow "Matthew Smith". For pairs in a gray zone, between 70% and 85% similarity, an LLM tiebreaker got asked whether they were the same entity, and if that call failed, the pair stayed separate. Each fix closed the case in front of me and left the next one open.
The version that finally held up came from flipping the rule around. Similarity is allowed to suggest a merge, but only proof can make one, such as an exact canonical name or a binding inside the same document. Merges between existing entities go through me, and when I mark two entities as different, that decision sticks. The project page goes through how that works.
Tap to enlarge, then pinch to zoom
A JSON repair that hid truncated output
Also on day two, I hardened the structured-output handling, because models kept returning almost-JSON. One of the repairs counted unbalanced braces and brackets and closed them so the response would parse. It worked. A response that came back with a missing } got rescued instead of retried.
It also meant a response that ran out of output tokens halfway through a list of entities parsed cleanly as a shorter list. Nothing in the extractor looked at the model's finish reason, so a cut-off window and a complete one looked the same to the rest of the pipeline. I'd written a robustness fix that made one kind of failure invisible.
The current extractor treats truncation as its own error. It checks the finish reason, splits only the window that got cut off into two smaller overlapping ranges, and runs it again. If a window keeps truncating at the smallest split size, the whole document fails rather than going into the graph half-read. The brace-closing repair is gone.
Tap to enlarge, then pinch to zoom
The answers took longer than the graph
I expected extraction to be the hard part. It wasn't. Most of the work went into the answers.
The two query modes from the first version were too blunt. Some questions need a quick lookup, some need events in order, and some should only get an answer if the evidence is strong. That turned into four modes (quick, deep, timeline and strict), plus a Strands Agents planner, auditor and repair editor around the Python query engine. I kept one boundary firm while adding them. The agents get no database tools. The query engine owns retrieval, ranking and citations, so an agent can't go looking for its own sources or cite something the engine never retrieved. "Agentic RAG" turns into a vague blob quickly when every step is another model call with its own reach into the data, and I wanted to be able to trace every answer back to the sources the engine retrieved.
Tap to enlarge, then pinch to zoom
Then came the audit. One long stretch of work went almost entirely to it. Most of those commits were about citations, source selection and the audit that checks each claim against the OCR text before an answer is shown, and far fewer touched extraction. Every mode except quick runs that audit. Quick answers skip it and say so on screen. Small things kept turning out to matter. Timeline mode, for example, used a separate model call to generate its events, so a timeline could include events that weren't in the verified answer it came with. Timelines now come from the dated observations in the final verified answer, so the two can't disagree.
Strict mode is the one I'm happiest with, and it's intentionally boring. It's also the default. When the evidence is weak, it says so and gives a partial answer or none, instead of writing a confident paragraph that fills the gap with a guess. For personal records I'd much rather get an answer with its holes marked.
LiteLLM from the first afternoon
Routing every model call through my self-hosted LiteLLM proxy was a first-day decision. That afternoon I removed the Google SDK from the KG and pointed classification, extraction, embeddings and queries at LiteLLM's OpenAI-compatible API. The OCR worker is the exception, and it calls its providers directly.
The KG has its own LiteLLM virtual key, separate from the other services that use the proxy. That's attribution rather than a limit. The KG's requests and spend show up as their own line in the proxy's logs instead of being mixed into a shared provider key. That line can't separate indexing from queries, because both use the same key, but it does tell me what the KG costs as a whole. Changing the primary model is a configuration change, because the app reads the route name from its environment. The fallback to a GPT mini model after a rate limit or an unusable response lives in the KG's query code, and only there. Classification, extraction and the agents have no fallback model.
I'd start with the proof rule for identity. Every guard I added to the fuzzy resolver was a response to a specific wrong merge, and the rule I ended up with stops similarity from merging anything at all, which also covers the cases I hadn't hit yet. On personal records, a longer review queue is a fair price.
I'd treat every truncated or malformed model response as a failure from the start. Making a response parse is not the same as getting the complete answer, and a pipeline that repairs output into shape will hide the exact failures it most needs to report.
I'd build the evaluation set before tuning anything. For a long time I tested against questions from my own archive that nobody had labeled independently, which is a good way to convince yourself something works. The harness now runs against a synthetic corpus with known values and source spans, and some of its cases expect the system to decline to answer. I wish I'd had it from the start.
The code is split across Paperless-ngx, Paperless OCR Enhanced and Paperless Knowledge Graph. Enhanced OCR is optional, and the KG can read Paperless's base OCR directly.
The pipeline I haven't turned on
The repo has a second question pipeline that I haven't switched on. Instead of answering from retrieved chunks, it reads the original source documents, audits every observation it takes from them, and then checks the final answer against the original question. It's controlled by QUESTION_PIPELINE_ENABLED, which defaults to false.
On the synthetic evaluation it passed every case in a 48-case run across all four modes. The first real question from my own archive failed before a single audit call ran. The reader had kept 155 observations from 35 source-reading stages, and a hard ceiling of 80 units in the finalizer blocked every audit. That ceiling is gone now, but the fixed code hasn't been through a full run since, and there are still known gaps in how much of a large source the pipeline reads. It stays off until it passes a sealed holdout set and shows that it fixes questions the current pipeline gets wrong.
Tap to enlarge, then pinch to zoom