When the GraphReasoner’s confidence falls below 0.8, the RAG pipeline retrieves compliance context from Memgraph and injects it into the LLM prompt. This grounds the LLM’s analysis in specific regulatory articles rather than relying on general knowledge.
The retriever executes four Cypher queries against Memgraph:
Article Context Query
Traverses: RiskFactor → (TRIGGERS) → Article → (GOVERNED_BY) ← Category → (HAS_CATEGORY) ← FrameworkReturns articles with their framework context, ordered by PageRank (most authoritative first).
Mitigation Context Query
Traverses: RiskFactor → (MITIGATED_BY) → MitigationReturns mitigations ordered by coverage count (mitigations that address the most risk factors first).
Violation Article Text Query
Direct lookup by article ID for articles already referenced in violations.
Cross-Framework Context Query
Multi-framework impact analysis — how many frameworks are affected by the detected risk factors. Events crossing 3+ frameworks receive severity boost.
The format_rag_context() function produces markdown injected into the LLM prompt:
Copy
Ask AI
## Compliance Context (from knowledge graph)### Applicable Risk Factors- **Data Exfiltration** (rf:data_exfiltration): Unauthorized transfer of data outside organizational boundaries- **Bulk Data Access** (rf:bulk_data_access): Accessing large volumes of data in a single operation### Relevant Compliance Articles- **GDPR Art. 5(1)(c)** [GDPR]: Data shall be adequate, relevant and limited to what is necessary in relation to the purposes for which they are processed.- **SOC2 CC6.1** [SOC2]: The entity implements logical access security software, infrastructure, and architectures over protected information assets.### Recommended Mitigations- Restrict bulk exports to internal resources or require approval- Implement data loss prevention (DLP) controls on outbound transfers### Cross-Framework Impact- **3 frameworks affected**: GDPR, SOC2, ISO27001- This indicates a systemic compliance gap, not an isolated issue
This mapping bridges the forward-chaining engine (which knows rule names) with the Memgraph ontology (which knows risk factor IDs), enabling graph traversal for article retrieval.
The RAG pipeline gracefully degrades when Memgraph is unavailable — it returns an empty RAGContext and the LLM operates without compliance context grounding.