
Retrieval-augmented generation (RAG) has become the de facto standard for grounding large language models (LLMs) in personal data. The standard architecture – segmenting documents, embedding them in a vector database, and obtaining top-k results via cosine similarity – is effective for unstructured semantic search.
However, for enterprise domains characterized by highly interconnected data (supply chain, financial compliance, fraud detection), vector-only RAG often fails. it catches Equality but misses structure. It tackles multi-hop reasoning questions like, "How will a delay in component X impact our Q3 delivery to client Y?" Because vector is not a store "Know" That component
This article explores the graph-enhanced RAG pattern. Based on our experience building high-throughput logging systems at Meta and private data infrastructures at Cogni, we will walk through a reference architecture that combines the semantic flexibility of vector search with the structural determinism of graph databases.
Problem: When vector search loses context
Vector databases excel at capturing meaning but sacrifice topology. When a document is fragmented and embedded, explicit relationships (hierarchy, dependencies, ownership) are often flattened or lost altogether.
Consider the supply chain risk scenario. Although this is a hypothetical example, it represents the exact class of structural problems we see consistently in enterprise data architectures:
- Structured Data: An SQL database defines that supplier A provides component
-
Unstructured Data: A news report stated, "Flooding in Thailand has halted production at Supplier A’s facility."
Searching a standard vector for "production risk" Will retrieve news reports. However, there is probably a lack of context linking that report to the output of Factory Y. LLM gets the news but can’t answer the important business question: "Which downstream factories are at risk?"
In production, this appears as a hallucination. LLM attempts to bridge the gap between news reports and factories but lacks explicit links, leaving it either inferring or regressing relationships. "I don’t know" Response even if data is present in the system.
Pattern: Hybrid Recovery
To solve this, we proceed from a "flat rug" to one "graph rag" architecture. It consists of a three-layer stack:
- intake (the "meta" Lesson): At Meta, working on the Shopify logging infrastructure, we learned that structure should be applied on ingestion. You cannot guarantee reliable analysis if you try to reconstruct the structure from the disorganized logs later. Similarly, in RAG, we have to extract entities (nodes) and relationships (edges) during ingestion. We can use LLM or Named Entity Recognition (NER) models to extract entities from text fragments and associate them with existing records in the graph.
-
storage: We use a graph database (such as Neo4j) to store the structural graph. Vector embeddings are stored as properties on specific nodes (for example, a RiskEvent node).
-
Recovery: We execute a hybrid query:
-
Vector Scan: Find entry points in a graph based on semantic similarity.
-
Graph Traversal: Cross-reference the relationships with those entry points to gather context.
-
reference implementation
Let’s create a simplified implementation of this supply chain risk analyzer using Python, Neo4j, and OpenAI.
1. Modeling the graph
We need a schema that connects our unstructured "risk events" for our structured "supply chain" Units.
2. Ingestion: Linking structure and semantics
In this step, we assume that the structural graph (supplier -> factory) already exists. We ingest a new unstructured "risk event" And link it to the graph.
3. Hybrid retrieval query
This is the main differentiator. Instead of just returning the top-k segments, we use Cypher to perform a vector search to find the event, and then traverse to find the downstream effect.
Output: Instead of a normal text fragment, the LLM receives a structured payload:
[{'issue': 'Severe flooding…', 'impacted_supplier': 'TechChip Inc', 'risk_to_factory': 'Assembly Plant Alpha'}]
This allows LLM to generate accurate answers: "Flooding puts assembly plant Alpha at Techchip Inc. in danger."
Production Lesson: Latency and Continuity
Taking this architecture from notebook to production requires handling trade-offs.
1. Lateness Tax
Graph traversals are more expensive than simple vector lookups. In my work on the product image experiment at Meta, we dealt with tight latency budgets, where every millisecond impacted the user experience. While the domain was different, the architectural lesson applies directly to graph RAGs: you can’t compute everything right away.
- Vector-only RAG: ~50-100ms recovery time.
-
Graph-Advanced RAG: ~200-500 ms recovery time (depending on hop depth).
Mitigation: We use semantic caching. If a user asks a query similar to the previous query (cosine similarity > 0.85), we serve the cached graph results. it reduces "do graph" For general questions.
2. the "stale edge" crisis
In a vector database, the data is independent. In graphs, data is dependent. If supplier A stops supplying to factory Y, but the edge in the graph remains, the RAG system will confidently assume a relationship that no longer exists.
Mitigation: Graph relationships must be time-to-live (TTL) or synced to the source of truth (ERP system) through change data capture (CDC) pipelines.
infrastructure decision framework
Should you adopt Graph RAG? Here is the framework we use at Cagney:
- Use vector-only RAG if:
-
The corpus is flat (for example, a chaotic wiki or Slack dump).
-
The questions are broad ("How do I reset my VPN?").
-
Latency <200ms is a tough requirement.
-
-
Use graph-advanced RAG if:
-
Domain is regulated (finance, healthcare).
-
"explainability" Required (you need to show the traversal path).
-
The answer depends on multi-hop relationships ("Which indirect subsidiaries are affected?").
-
conclusion
Graph-enhanced RAG is not a replacement for vector search, but a necessary evolution for complex domains. By treating your infrastructure as a knowledge graph, you provide the LLM with something it can’t confuse: the structural truth of your business.
Daulet Amirkhanov is a software engineer at Usebead.
<a href