A fixed budget for answering: which chunk caused this?
When a RAG system says something false, you want to know which retrieved passage it came from, if any. VectorLens answers that on your own machine, with two lines of code and a fixed budget per answer. It is built like an emergency room: a quick check for everyone, a closer look only for the cases that need it.
- 7
- masked calls per attribution
- ~50 ms
- for fully grounded responses
- 0.4
- similarity screen threshold
- 5 × 5
- LLM providers × vector databases
Which source said that?
Picture a teacher grading an essay with a bibliography. The essay reads well, but one sentence is wrong. Did the student misread a source, pick the wrong source, or make it up? Each answer calls for a different fix, and you cannot choose one until you know which source the sentence came from.
A retrieval-augmented generation system is that student. It retrieves passages, then writes an answer, and it can fail in two different ways. Retrieval failure means the right passage was never found. Generation failure means the right passage was found and the model ignored it or invented something anyway. Tuning embeddings will not fix a generation failure, and rewriting prompts will not fix a retrieval failure. Without knowing which one you have, you are guessing.
The question I wanted a tool to answer is simple: could a person have written this sentence from only these passages? VectorLens answers it sentence by sentence and shows which retrieved chunk shaped each one.
Three rules before any code
I set the rules before building, because the tools that existed broke them. First, local-first: prompts, passages and answers never leave the machine. Sending proprietary data to a hosted dashboard just to debug it can mean a compliance meeting before you are allowed to look.
Second, zero instrumentation. Two lines, import vectorlens and vectorlens.serve(), and the existing pipeline runs unchanged. VectorLens intercepts calls at the network layer, so it works across five LLM providers and five vector-database clients without wrappers. Third, never break the thing being debugged. Instrumentation failures are caught and logged, and if attribution falls behind, new work is dropped rather than blocking the model call.
Triage first
Napoleon's surgeon Dominique-Jean Larrey is often credited with modern triage: sorting the wounded by how urgently they needed care, not by rank, and treating the worst first. VectorLens triages sentences the same way.
The response is split into sentences. Each sentence and each retrieved chunk are embedded with all-MiniLM-L6-v2, then compared by cosine similarity. A sentence whose best chunk similarity falls below 0.4 is flagged for a closer look.
That threshold is a quick check, not a diagnosis, and it is not proof of hallucination. Its job is to let the healthy cases go home: fully grounded responses come back in roughly 50 ms without paying for a deeper explanation.
Make attribution bounded
For the flagged sentences, the API-model path plays Jenga with the evidence. It uses LIME-style perturbations: hide some of the retrieved chunks, ask the model again, and see whether the sentence survives. The chunks whose removal makes it collapse are the ones holding it up.
The important design choice is the budget. Attribution always costs seven masked calls, instead of one call per retrieved chunk, so the cost of an explanation stays predictable as retrieval grows. For local Hugging Face models, VectorLens also supports attention rollout. The two are different mechanisms serving the same question: which chunk most shaped this sentence?
Model calls needed to attribute one sentence
The zero-config tool that hung on zero
The most instructive bugs were in the first minute of use. A fresh install, with the server reachable but no sessions recorded yet, sat on Loading sessions forever. The success path never cleared the loading flag, so a new user never reached the screen that tells them to run a pipeline. For a tool whose whole pitch is zero setup, that was the worst possible place for a bug, and the fix was one line.
Continuous integration had a matching story. The test check had been red for months while 122 tests passed and 8 failed. The cause turned out to be one missing test dependency: the async tests needed a plugin that the CI install line never added. Both bugs lived exactly where a newcomer would land first.
What it can and cannot tell you
Attribution is evidence about a model run, not a guarantee that a retrieved source is true or sufficient. Similarity can miss paraphrase, perturbations can be approximate, and a grounded sentence can still be misleading in context.
That is why the tool works best in the loop with an engineer: screen cheaply, inspect the uncertain sentences, trace their inputs, then fix retrieval, prompting or source quality where the trace points.