The problem
Every Claude Code session I run gets summarized into an Obsidian vault: bugs, decisions, patterns and project logs, written automatically after each session ends. By October 2026 the vault held 638 notes, and my coding agents searched it the only way they could, with grep.
Grep fails in three ways on a vault like this. It misses a question asked in different words, and it misses every Indonesian question about an English note, which is most of mine. It never follows the links between notes, even though the links are where the context lives. And when nothing relevant comes back, the agent answers anyway, which is exactly where hallucinations start.
vaultgate retrieves by meaning and by keyword, follows the vault's own wikilinks, and refuses to answer from weak evidence. It started as my final project for the AI Super Class certification (LLM track) and now runs on my home server, where my agents call it through an MCP tool.
How a question moves through it
Every candidate carries its score at every stage, plus the reason it was dropped, so the CLI, the API, the Streamlit inspector and the evaluation all read the same trace.
Hybrid search with one model
BAAI/bge-m3 produces a dense vector (1024 dimensions) and a sparse lexical vector from the same pass. Both go into one Qdrant collection as named vectors. Dense search catches the Indonesian question about an English note; sparse search catches the exact error string or the function name.
I fuse the two lists client-side with Reciprocal Rank Fusion instead of using Qdrant's server-side fusion, so the trace keeps each candidate's dense and sparse rank. That choice caught a bug for free: Qdrant counts ranks from 0, so its "k=60" is the textbook k=59. A parity test against my own implementation flagged the one-off difference.
Chunks split on headings, between 200 and 1,800 characters. The upper bound is not arbitrary: 20 chunks at that size stay under the ~30 KB request size where the gate model switches to a slower long-context mode.
Following the vault's own links
The indexer saves every [[wikilink]] as a directed NetworkX graph. After hybrid search, the top 5 notes become seeds: their linked and backlinking notes (up to 5 per seed) join the candidate list, each contributing only its chunk closest to the query. I chose this over Microsoft-style GraphRAG on purpose. The vault already has a hand-made graph, so there is no need to ask an LLM to extract one.
A gate that decides in code
The gate is jev-1.14, a model that answers typed yes/no questions with calibrated probabilities, called through OpenRouter's Decisions API. It runs in two steps:
- For every chunk: "Does this passage help answer the question?" A chunk stays if P(yes) is at least 0.2.
- Once, over the context that would be sent: "Is this enough to answer?" The system answers if P(sufficient) is at least 0.5.
If the evidence is not sufficient, the pipeline retries once with no filters and a wider search. If it still fails, it abstains with a fixed message, and the generator is never called.
def run(self, query: str, filters: dict | None = None) -> Trace:
"""First attempt as asked; on abstain, retry without filters and with a larger top_k."""
trace = Trace(query=query, gate_name=self.gate.name, use_graph=self.use_graph)
embedding = self.embedder.encode([query])[0]
top_k = self.settings["top_k"]
for number in range(self.settings["max_retries"] + 1):
if number:
top_k, filters = self.settings["retry_top_k"], None
attempt, context = self.attempt(query, embedding, top_k, filters)
trace.attempts.append(attempt)
if attempt.gate.sufficient:
trace.status, trace.context = "answer", context
break
return trace
Jev is a proprietary alpha API, so all of it lives in one file behind a shared gate interface. A self-hosted bge-reranker-v2-m3 with a threshold and a pass-through gate implement the same interface, which is also what made the comparison below possible.
Evaluation
I built a 75-question golden set from a sanitized 88-note subset of the vault, in four categories: keyword, semantic (Indonesian questions about English notes), multi-hop, and unanswerable. An AI drafted the questions; I reviewed and corrected every one, and a script checks that each gold note exists and each evidence quote appears verbatim.
The split is fixed: 15 dev questions for tuning thresholds, 60 test questions run once per variant after tuning. Every variant uses the same generator (qwen3.6-35b-a3b, temperature 0), the same prompt, and the same 12,000-character context budget. A judge from a different model family (deepseek-v4.1-flash) grades correctness and faithfulness.
| Variant | Recall@5 | MRR | Correct | False abstain | p50 latency |
|---|---|---|---|---|---|
| No retrieval | – | – | 25% | 98% | 0.9 s |
| grep baseline | 0.72 | 0.57 | 68% | 43% | 1.7 s |
| Hybrid | 0.85 | 0.65 | 87% | 11% | 1.8 s |
| Hybrid + bge gate | 0.93 | 0.83 | 78% | 17% | 8.0 s |
| Hybrid + Jev gate | 0.97 | 0.89 | 97% | 4% | 3.2 s |
| Hybrid + graph + Jev gate | 0.97 | 0.92 | 95% | 4% | 3.4 s |
The judge rated every answer from the gated variants as faithful to its sources, against 98% for plain hybrid and 92% for grep.
Correct answers by question type:
| Variant | Keyword | Semantic | Multi-hop | Unanswerable |
|---|---|---|---|---|
| grep baseline | 87% | 31% | 60% | 100% |
| Hybrid | 93% | 62% | 93% | 100% |
| Hybrid + Jev gate | 100% | 88% | 100% | 100% |
| Hybrid + graph + Jev gate | 100% | 88% | 93% | 100% |
The whole test run cost $0.20 for the systems and $0.10 for the judge.
What the numbers say, including the parts that didn't work
Hybrid beats grep by 19 points, and almost all of that gain is on semantic questions (62% against 31%), where keywords simply don't match across languages.
The Jev gate adds another 10 points over plain hybrid. The gain comes from ranking more than from blocking: Recall@5 rises from 0.85 to 0.97, so the 12k context holds the right chunks instead of whatever RRF ranked first.
Graph expansion did not change correctness on this vault: 95% against 97% is one question. The project notes already summarize the notes they link to, so hybrid search usually finds the answer without the graph, and in the one loss the extra graph chunks pushed the right chunk out of the context budget. The graph still earned its place in two ways. MRR rose from 0.89 to 0.92, and when a folder filter narrows the search, the graph is the only path to the evidence: in one demo query it answers on the first attempt (sufficiency 0.96) through a linked note that the filter had excluded.
The bge reranker was a weak gate here. It has no sufficiency signal, so it answered 3 unanswerable questions and wrongly abstained on 17% of answerable ones, four times Jev's rate.
Running it
The API, the inspector, Qdrant and an hourly indexer run as four Docker Compose services on my home server, as a non-root user, with the vault mounted read-only and CPU-only PyTorch to skip 3 GB of CUDA libraries the server can't use. A Jev-gated answer takes about 2.7 seconds end to end there. The MCP tool search_vault is a thin HTTP client to that API: it returns gated passages with note paths, or an abstain, and the calling agent writes the answer.
What I learned
- A broken index can look healthy. When I copied the Hugging Face cache to the server, I copied only the model folders. Their files are symlinks into a shared blobs folder, so the links dangled. The API crashed, which was easy to spot. The indexer was worse: it ran, built an index with empty sparse ranks and nonsense dense order, and its manifest still matched, so it never rebuilt itself. Now I check copies with
find -xtype land force a rebuild after any model change. - Reasoning models bill silently. Qwen3.6 thinks by default on OpenRouter, and in the smoke test the thinking tokens used up the whole output budget and returned empty answers. Reasoning is off in the config now.
- Write the result you got, not the one you planned. I expected the graph to be the headline. The README and the slides say it changed one question, because that is what happened.