Charlotte, NC
ProjectsJune 1, 2025

Paperless Knowledge Graph

Tap to enlarge, then pinch to zoom
Paperless-ngx keeps my scanned documents, their OCR text and their tags in one place, and its keyword search will find every document that contains a word. It can't tell me what my current insurance premium is. That answer lives on the newest declarations page, not on every page that mentions a premium, and someone has to read the number in context and check the date. Most of the questions I have about my own paperwork look like that. They span several documents, they depend on dates, and keyword search hands back a list and leaves the reading to me. Paperless Knowledge Graph does the reading. It classifies each document, pulls entities and relationships into Neo4j, keeps chunked text and embeddings in PostgreSQL with pgvector, and answers plain-language questions with citations. In every mode but the quick one, a source audit checks each claim against the OCR text of the document it cites before the answer reaches the screen. As of writing, the archive holds just over a thousand documents, and the graph has about 7,300 nodes, 14,700 relationships and 7,500 searchable text chunks. The code is on GitHub. I wrote about how I built the first version in Building a Personal Knowledge Graph, and this page covers how it works now. Every document starts with a classification call that puts it in one of nine types, such as medical and lab results, invoices and statements, contracts, insurance, property and tax. The type picks the metadata prompt for the first extraction pass. An insurance policy and a lab report have different things worth pulling out, so they get asked different questions. Extraction reads the document in 12,000-character windows that overlap by 800 characters, and each window goes through five passes. The first pulls type-specific metadata such as dates, amounts and identifiers. The other four work in pairs. One pass proposes entities and the next reviews them against the text and settles their types. Then the same propose-and-check sequence runs for relationships between the entities that survived. When the model proposes an entity, it has to quote the part of the window that supports it. The extractor searches the window for that quote, allowing only differences in whitespace, and drops the entity if the quote isn't there or doesn't contain the entity's name. A model can still misread a document. It can't add an entity that the text never mentions. Long documents don't get cut off. If the model's output comes back truncated, the extractor splits just that window into smaller overlapping ranges and runs all five passes on each one. Every pass gets three attempts. A document only counts as indexed once every window has finished, and if truncation keeps happening at the smallest split size, the document fails instead of going into the graph half-read. All of this depends on the OCR text Paperless already has. Documents where Tesseract struggles can go through Paperless OCR Enhanced first, which writes better text back to Paperless before the graph reads it. A personal archive is full of near-duplicates. The same bank shows up under its full legal name on a statement and a short name on a card. Two different accounts at that bank share almost every word in their names. Fuzzy matching gets the first case right and the second one wrong, and the wrong merge is the expensive mistake. It mixes two records into every answer that touches either of them. A missed merge costs me one extra pair in the review queue. So the resolver follows one rule, written into its module docstring: proof selects, similarity only suggests. A new mention links to an existing entity only through a canonical name, a verified alias or a binding inside the same document. Name similarity can put a pair in the review queue, but it can't link anything. Merging two existing entities takes a person, and so does splitting them. When I mark a pair as different, that decision is kept as a veto, and no later run can merge them. The entity steward does the legwork on that queue. It runs every six hours and again after each sync, works through the candidate pairs, and writes merge and split suggestions for me to accept or reject. It never merges anything on its own. Neo4j 5 with APOC holds the entities and relationships. PostgreSQL holds the chunked document text, entity embeddings and 3072-dimension document embeddings from an OpenAI large embedding model, with pgvector for similarity and pg_trgm for trigram keyword search. Vector search is an exact cosine scan over every chunk, with no approximate index. pgvector's HNSW and IVFFlat indexes only take the plain vector type up to 2,000 dimensions, so the HNSW indexes I tried were built over the embeddings cast to half precision, halfvec. Using them was always an explicit option, they reranked their candidates against the full-precision vectors, and normal retrieval never stopped using the exact scan. I removed them along with other finished experiments, and the app now drops them on startup. Redis caches query, vector and graph results. The query cache key includes both the query model and the planner model, so switching either one never serves an answer cached under the old model. Searching for an entity in the graph explorer goes straight to Neo4j and comes back in a fraction of a second. A plain-language question takes more work, and the mode decides how much. Quick is a single retrieval pass with no source audit, enough for a simple lookup, and its answers are labelled unaudited. Deep plans up to six searches and writes an audited answer. Timeline pulls the dated events out of a verified answer and sorts them, each linked to its source. Strict is the default and the one I use when a wrong number costs me something, such as medical, legal, tax, insurance and financial questions. It searches wider, up to eight searches including one for source quality, and reads the top documents in full. Retrieval runs pgvector similarity, trigram keyword search and a graph traversal together, and the traversal expands three hops out from the entities it finds. Each one finds things the other two miss. Similarity finds a passage that says the same thing in different words, keyword search finds the exact policy or account number, and the graph brings in related records that never use the question's words at all. After a first draft, a gap review can ask for a few follow-up searches, and their results join the context before the final draft. Strands Agents runs the four steps that need judgment: the query planner, the answer auditor, the repair editor and the entity reviewer. The Python query engine owns retrieval, ranking and citations. The agents get no tools, so none of them can query a database or cite a source the engine didn't retrieve. Every model call goes through my self-hosted LiteLLM proxy. A Gemini Flash model handles classification, extraction, planning, audits and answers, and a GPT mini model takes over the query engine's own calls after rate limits or errors. I keep both current as new models release. Swapping a model means changing a route name, and LiteLLM records what each call costs. The model's draft is only a candidate. The source audit splits it into answer units and checks them against the original OCR text in batches of four. For each claim it checks whether the source supports the subject, the predicate, the record's role, any conditions, the time period and any comparison, and the claim comes out supported, unsupported, missing or conflicting. Citations get the same treatment, and the app renders a document link only after the claim's references validate. Checking six things per claim is deliberate. A number can be copied correctly and still be wrong. It can belong to last year's policy, or to a different account, or come from a quote instead of the bill. A check that only asks whether the number appears in the source would pass all three. An answer gets at most one repair. If some claims still fail after that, the app can re-audit just the supported units as a new answer. That's a verified partial answer. It contains only claims that passed, and it says how many claims it left out and that the answer is incomplete. If the audit fails, finds a conflict, runs out of time or sees a source change mid-run, the app withholds the answer. It never caches a partial answer as a complete one. The evaluation harness runs against a synthetic corpus with known values, units and source spans, and some of its cases expect the system to abstain. No case can pass on the system's self-reported confidence. My first test questions came from my own archive and were never labeled independently, and six of them could pass on keyword matches without citing a single source. They're smoke checks now, and they require real source IDs. The harness reports wrong answers and abstentions side by side, because a system that withholds most of its answers never says anything wrong and still isn't useful. The Next.js 16 frontend is how I use all of this day to day. The query page streams progress while an answer is built, keeps saved conversations, has a model picker, and can show the trace behind an answer, from the plan and the evidence through the audit and the claim ledger. When an answer looks wrong, the trace shows whether retrieval missed the document or the audit dropped the claim. Each document's page shows the facts the extractor pulled out, its chunks and its processing status, with a way to flag a bad extraction. Around those sit a graph explorer that opens in 2D and has a 3D mode, topic hubs for insurance, taxes, medical records, vehicles and the home, the entity review queue with the steward's suggestions, and a live log viewer.
  • Paperless-ngx for document storage, base OCR and tags
  • Gemini Flash through LiteLLM, with a GPT mini model as the query fallback and an OpenAI large embedding model for embeddings, kept current as models release
  • Strands Agents for query planning, source audits, answer repair and entity review suggestions
  • Neo4j 5 with APOC for entities, relationships and multi-hop traversal
  • PostgreSQL with pgvector and pg_trgm for exact vector search and trigram keyword search
  • FastAPI on Python 3.12 for the backend
  • Next.js 16 and React 19 with shadcn/ui and react-force-graph for the frontend
  • Redis for query, vector and graph caches
  • Kubernetes with Flux for the running deployment, and Docker Compose for local development
Paperless stays the source of truth, and the graph and search indexes can be rebuilt from it. A sync runs every hour and processes only new and changed documents. If a reindex or another task is still running when the hour comes around, the scheduled sync skips that turn instead of starting a second job on top of it. Documents tagged needs-review in Paperless stay out of the graph until I clear the tag. Each document's ingestion fingerprint includes the extraction model and the source policy version. When I change the extraction model, the next sync rebuilds the affected documents without a full reindex. When I do run a full reindex, it replaces documents one at a time, and queries keep working while it runs. An answer that cites a document still being rebuilt says the index changed and waits for the repair, instead of citing half-written data. Whether the sync actually kept up is a separate question, and the freshness check answers it with exact document IDs instead of counts. Counts can match while the stores disagree. If the graph is missing one document and still holds another that Paperless no longer has, both sides report the same total. /freshness compares the ID sets in Paperless, Neo4j, pgvector and the processing hashes and reports what's missing or extra in each store, and /freshness/repair reindexes only the IDs that drifted. Freshness can tell me the graph matches Paperless. It can't tell me Paperless has everything. If this year's declarations page hasn't been scanned yet, the newest premium in the archive is last year's, and every check above will pass. So when an answer reports a latest value, like a premium or a balance, it says that's the newest record it found. It doesn't claim the value is still current or that the archive is complete.

Related projects

Solomon Thrift Store Pricing

A phone-first pricing app for a ministry thrift store, grounded in completed sales and manager review, and simplified after a backtest on real staff prices.

Tracecheck

Evidence-backed code review for AI coding agents, with exact source references, independent Jev judgments, and explicit limits on what a review can prove.

Obsidian Vault RAG

Open-source retrieval for Obsidian vaults, with local search, a shared MCP service, project-scoped profiles, and source-checked citations for AI agents.

Rollo Label Printer

Personal label-printing tool that finds the real shipping label inside messy return PDFs and images, normalizes it to 4x6, and prints through direct IPP.

Garmin MCP Server

Open-source MCP server that exposes 34 Garmin Connect health and fitness tools to any AI assistant, with parallel fetching and Docker support.

blakemccarn.dev

Portfolio and blog built with Next.js 16, deployed to AWS via SST v4 with Cloudflare DNS, staging environments, and full IaC.

Charlotte Wire & Cable

Full-stack business website for a specialty wire distributor: searchable catalog, admin dashboard, and serverless AWS infrastructure via SST.

Paperless OCR Enhanced

Open-source Paperless-ngx companion service that uses LLM vision models to repair weak OCR and improve downstream document search.

RapidEPR

I founded RapidEPR, an AI tool that writes military evaluations and award citations for five services, and grew it from a personal project to over 500,000 users.