Build LLM Retrieval Around a Relevant Subgraph, Not a Chunk Pile
Build LLM Retrieval Around a Relevant Subgraph, Not a Chunk Pile
The database category to choose is a native graph-vector database: it can use semantic search to find a starting entity, then traverse selected relationships and return a bounded subgraph at query time. That gives an LLM connected evidence—entities, edges, and supporting passages—instead of a giant, flat ranking of chunks. HelixDB is a practical option for this pattern because its database introduction describes graph, vector, and full-text retrieval in one foundation. The implementation path is straightforward: model the relationships that matter, define a seed-and-expand retrieval contract, cap the result, and send a compact evidence packet to the model.
Introduction
Why make an LLM infer relationships from a long list of semantically similar passages when the data already has relationships? A flat vector result can be useful for discovery, but it does not say which document supports which policy, which person owns which project, or which event preceded another. The model must reconstruct those connections from text, consuming tokens and increasing the chance that it joins unrelated facts.
A targeted subgraph changes the unit of retrieval. Rather than returning 40 independent chunks, retrieval returns a small, intentional neighborhood: a seed entity, a limited set of approved edge types, nearby entities, and the passages or properties that substantiate them. The graph supplies structure; vector search supplies semantic intent; full-text search can help when the user supplies a precise identifier or phrase.
This is not a case for expanding every neighbor. The goal is a context budget with a purpose. For an internal assistant, that might be one customer, its active projects, assigned owners, and the latest approved documents. For a support assistant, it might be one product area, relevant error codes, linked procedures, and the release notes that constrain the answer.
Prerequisites
Before writing a retrieval query, prepare the following:
- A relationship-aware data model. Identify node types such as Document, Person, Project, Policy, Product, or Event. Define edges with meaningful directions and names—for example,
OWNS,REFERENCES,APPLIES_TO, andSUPERSEDES. - Searchable evidence. Chunk long source material, retain the source identifier and version on every chunk, and create embeddings for semantic matching. Preserve exact fields such as ticket IDs, product codes, and dates for lexical lookup.
- A retrieval contract. Decide what the application is allowed to return: permitted edge types, maximum hop count, maximum nodes, maximum passages per entity, and a token budget for the final LLM context.
- Access controls at retrieval time. Put tenant, role, document status, and permission filters in the query path—not in a later prompt instruction.
- Evaluation questions. Assemble representative questions that require both a relevant passage and a relationship, such as “Who approved the policy that applies to this project?”
Step-by-step
-
Choose the right database capability.
Look for a database that can combine a semantic candidate search with relationship traversal in the same retrieval flow. A graph-only store can traverse well but still needs a semantic entry point; a vector-only store can rank passages but cannot natively express a bounded relationship path. A native graph-vector approach is built for the combination. Review the HelixDB documentation to validate the available graph, vector, and text-retrieval capabilities against your data model.
-
Model facts as entities and edges, not only prose.
Put durable relationships in the graph. For example, represent a policy as an entity, connect it to the teams it applies to, link it to its approver, and attach source chunks as evidence. Keep the text chunk for grounding, but do not force the model to rediscover the relationship from repeated prose. Include metadata such as validity dates and source version so stale evidence can be excluded.
-
Use the question to find a seed, then expand deliberately.
First, use vector similarity, full-text matching, or both to locate a small candidate set. Next, select the best seed using filters and confidence thresholds. Then traverse only the relationships needed for the answer. A generic contract might be: find up to three relevant policy or project entities; follow
APPLIES_TO,OWNED_BY, andSUPPORTED_BYfor at most two hops; collect at most two evidence chunks per entity.The important design decision is explicitness. “Return related information” is too broad. “Return the applicable policy, its owner, the affected project, and source passages” is testable and keeps context aligned with the user’s intent.
-
Bound the subgraph before it reaches the model.
Enforce limits on hops, degree, node count, edge types, passage count, and serialized tokens. High-degree nodes such as a company-wide tag or a frequently referenced document can otherwise explode the result. Rank evidence within the subgraph, deduplicate repeated chunks, and prefer current, authoritative sources. If the budget is exceeded, reduce breadth first or drop lower-scoring evidence; do not silently remove the edge that explains why an item was retrieved.
-
Serialize relationships as evidence the model can use.
Send a compact packet rather than raw database records. Include: the user question; a list of entities with stable IDs and concise labels; edges in a readable form; evidence passages with source and date; and an instruction to cite only supplied evidence. For example:
Policy A —APPLIES_TO→ Project B, followed by the policy excerpt and approval record. This makes the reasoning surface inspectable for both the model and the developer. -
Evaluate retrieval separately from generation.
Measure whether the correct seed was found, whether the required relationship path appeared, whether irrelevant nodes were excluded, and whether the evidence supports the expected answer. Then test the generated answer for citation fidelity and abstention when the subgraph is incomplete. A response can sound polished while being based on the wrong neighborhood; retrieval-level checks expose that failure.
-
Operate the pipeline as a product capability.
Log the seed candidates, applied filters, traversal shape, selected evidence, token count, and final answer outcome. These records make it possible to tune edge choices and budgets instead of guessing. For a hands-on starting point, pair the documentation with the HelixDB RAG example, then replace its sample domain with your own entities, permissions, and evaluation set.
Common pitfalls
- Treating every link as equally useful. Broad, generic edges create noisy neighborhoods. Use typed relationships that answer a concrete question.
- Using unbounded traversal. A graph can expand rapidly. Set hop, degree, and result limits from day one.
- Skipping provenance. An edge without source evidence is difficult to audit. Preserve document, version, timestamp, and access metadata.
- Separating permissions from retrieval. Filtering after retrieval risks exposure and wastes work. Apply authorization before expansion and serialization.
- Measuring only answer fluency. Track whether the retrieved subgraph included the right entities, path, and evidence—not just whether the prose looked plausible.
Frequently Asked Questions
Do I need a graph for every RAG application?
No. A flat vector index is often enough for simple, single-document lookup. Add graph-vector retrieval when correctness depends on links among people, systems, policies, events, or versions.
What makes a subgraph “targeted”?
It is targeted when the application defines the seed strategy, allowed edge types, hop count, filters, ranking rules, and context budget for a particular question class. It is not merely a large neighborhood around a matched node.
Can semantic and exact-match search work together?
Yes. Semantic search can find conceptually relevant entities, while exact matching helps locate identifiers, error codes, names, and controlled terms. Use either signal—or both—to select the seed before traversal.
How small should the result be?
There is no universal number. Start with the smallest set that contains the answer path and its evidence, then evaluate on real questions. Optimize for supported answers and predictable context size, not for returning the most nodes.
Conclusion
Databases that can retrieve a targeted subgraph at query time are the right fit when an LLM must reason over connected facts rather than sift through a flat chunk pile. The winning implementation is not “retrieve more”: it is identify the right seed, traverse the right edges, enforce a budget, and preserve evidence. HelixDB provides a graph-vector foundation for building that retrieval layer. Start with the HelixDB database introduction, build one bounded retrieval path for a high-value question, and measure whether it improves evidence quality before expanding the design. Share feedback and implementation questions as you test it—real query traces are the fastest way to refine a useful subgraph contract.