What I learned building a system that combines semantic retrieval with a knowledge graph, and why the guardrails became as important as the retrieval itself.
- 54Schemes
- 2Retrieval layers
- 3Guardrail layers
- 30/30Tests passed
01 · The question
Why wasn’t vector search enough?
FAISS gave the system semantic search: a question could still find relevant scheme information even when the user’s wording differed from the source wording. But the data also contained relationships that were naturally structured.
Schemes belong to departments, target beneficiaries, have benefit types, are sponsored by organisations, support crops and belong to categories. Those are relationships, not just similar pieces of text.
That led to the central experiment: keep semantic retrieval, but add a graph representation that could retrieve through explicit relationships as well.
Semantic similarity answers “what looks relevant?”. A knowledge graph can also answer “what is explicitly connected?”.
02 · The architecture
Two retrieval paths. One grounded answer.
- QuestionA user asks about a scheme, crop, beneficiary or category.
- Input guardrailOut-of-domain, empty and prompt-injection-style inputs are stopped before retrieval.
- FAISS + Neo4jSemantic retrieval and structured graph retrieval contribute complementary evidence.
- Evidence checksRetrieval and evidence-support guardrails check whether the available context can support an answer.
- Grounded generationThe final answer is generated from supported context rather than unrestricted model knowledge.
03 · The graph
Give the relationships a first-class role.
The Neo4j layer connected each scheme to structured entities such as department, beneficiary, benefit type, sponsor, crop and category. Retrieval could therefore use explicit domain relationships alongside semantic similarity.
- Scheme → BELONGS_TO → Department
- Scheme → TARGETS → Beneficiary
- Scheme → HAS_BENEFIT_TYPE → Benefit type
- Scheme → SPONSORED_BY → Sponsor
- Scheme → SUPPORTS_CROP → Crop
- Scheme → HAS_CATEGORY → Category
04 · The important part
Retrieval quality was not enough.
A retrieval system can still return weak evidence. The build therefore added three control points: an input guardrail, a retrieval guardrail and an evidence-support guardrail.
The application was designed to stop when the available official data could not support the requested answer. Missing information was surfaced as unavailable rather than filled in by the model.
05 · Evaluation
Test the behaviour, not just the happy path.
The final suite covered input controls, retrieval controls, evidence support, hybrid retrieval and final-answer behaviour. All 30 defined tests passed.
- Input guardrails10 / 10
- Retrieval guardrails8 / 8
- Evidence support4 / 4
- Hybrid retrieval4 / 4
- Final answers4 / 4
06 · Use it yourself
Deciding whether you need a graph at all.
Start with the simplest retrieval that could work, and add a part only when a measured failure asks for it.
- Write the questions firstCollect twenty real questions and mark, for each, which passages should come back. Without this you cannot tell whether a change helped.
- Try keyword plus vectorsMost failures of plain vector search are exact names, codes and numbers. Adding keyword search fixes many of them at little cost.
- Look at the missesIf the misses are questions about how things relate (which of these depends on that, what connects A to B), a graph earns its place. If they are about wording, it will not help.
- Keep it explainableWhatever you add, make it possible to show why a passage was returned. A result you cannot explain is a result you cannot fix.
What I took away
- Similarity and structure solve different parts of the retrieval problem.
- A good answer begins with deciding whether the available evidence is good enough to answer at all.
- Evaluation became part of the build itself, rather than something added after the interface looked complete.