Graph RAG
Graph RAG is currently in beta. Functionality, endpoints, and behavior may change in future releases.
Overview
Graph RAG extends traditional RAG by combining semantic search with knowledge graph retrieval, giving the agent access to both unstructured document content and structured entity/relationship data when generating responses. Under the hood, Graph RAG is powered by the Enterprise Context Engine (ECE).
The agent includes built-in hallucination detection that automatically validates responses against retrieved context and retries when hallucinations are detected.
Configuration
Create a Graph RAG agent:
{
"name": "KnowledgeAssistant",
"description": "Assistant with knowledge graph and document retrieval",
"agentType": "graphRag",
"notes": "Uses ECE for enriched answers with semantic and graph context",
"config": {
"llmModelId": "openai.gpt-5.6-luna",
"knowledgeGraphId": "7a0e6c74-7c62-4636-adbf-857340244e7d",
"ontologyIds": ["9f8c1a2e-3b4d-4e5f-8a6b-7c8d9e0f1a2b"],
"systemPrompt": "You are a domain expert. Cite the source document for every claim. If the retrieved evidence does not answer the question, say so clearly instead of guessing.",
"inferenceConfig": {
"maxTokens": 4000,
"temperature": 0.7
},
"hxqlQuery": "SELECT * FROM SysContent",
"hybridSearch": true,
"limit": 5,
"adjacentChunkRange": 1,
"adjacentChunkMerge": true,
"guardrails": ["HAIP-Profanity", "HAIP-Insults-High"]
}
}
Configuration Parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
agentType | Must be "graphRag" | Yes | "graphRag" |
knowledgeGraphId | Knowledge Graph ID | Yes | "7a0e6c74-7c62-4636-adbf-857340244e7d" |
ontologyIds | Ontology IDs to scope graph document retrieval to (max 50). When set, only documents tagged with any of these ontologies are returned | No | ["9f8c1a2e-3b4d-4e5f-8a6b-7c8d9e0f1a2b"] |
llmModelId | LLM model identifier | Yes | "openai.gpt-5.6-luna" |
systemPrompt | Custom instructions appended to the agent's built-in prompt (see below) | No | "You are a domain expert. Cite the source document for every claim." |
inferenceConfig | LLM inference parameters | No | {"maxTokens": 4000, "temperature": 0.7} |
hxqlQuery | HxQL filter for Content Lake retrieval | No | "SELECT * FROM SysContent" |
hybridSearch | Enable hybrid search (embeddings + full-text) | No | true |
limit | Maximum number of chunks to retrieve | No | 5 |
adjacentChunkRange | Number of adjacent chunks to fetch around each result (0 = disabled) | No | 1 |
adjacentChunkMerge | Merge adjacent chunks into the parent chunk in document order | No | true |
guardrails | List of guardrail names or parameterized guardrails (see Guardrails guide) | No | ["HAIP-Profanity"] |
System Prompt (Custom Instructions)
Graph RAG is a ReAct-style agent: it autonomously decides which search and graph-navigation tools to call based on the natural-language question in messages, rather than running a fixed retrieve-then-synthesize pipeline. There is no template it fills in with retrieved context.
When systemPrompt is provided, it is appended as a "CUSTOM INSTRUCTIONS" section after the agent's built-in prompt — it does not replace anything. When omitted, the agent uses only its built-in prompt (tool usage guidance, graph schema/stats/samples, and answering rules).
{context_str} and {query_str} have no special meaning for Graph RAG. Do not use them in a Graph RAG systemPrompt — they will appear literally, unfilled, in the final prompt sent to the model, since nothing substitutes them.
Example custom instructions:
You are a domain expert. Cite the source document for every claim.
If the retrieved evidence does not answer the question, say so clearly
instead of guessing.
Graph RAG appends systemPrompt rather than replacing it. Unlike the RAG agent, it does not rewrite {context_str}/{query_str} — leave them out entirely. See the RAG agent's System Prompt Compatibility for how rag agents handle those placeholders.
Retrieval Parameters
These can be passed at invocation time to override agent defaults:
| Parameter | Description | Default |
|---|---|---|
hxqlQuery | HxQL query to filter Content Lake documents | Config default |
hybridSearch | Enable hybrid search (embeddings + full-text) | Config default |
limit | Number of chunks to retrieve | Config default |
adjacentChunkRange | Number of adjacent chunks to fetch around each result | Config default |
adjacentChunkMerge | Merge adjacent chunks into parent chunk | Config default |
rerankerTopN | Number of results to keep after reranking | Config default |
Invocation
Non-Streaming
curl -X POST "/v1/agents/{agent_id}/versions/latest/invoke" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": "What entities are related to Project Alpha?"
}
]
}'
Invocation with Retrieval Overrides
curl -X POST "/v1/agents/{agent_id}/versions/latest/invoke" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": "Summarize the HR onboarding process"
}
],
"hxqlQuery": "SELECT * FROM SysContent WHERE department = '\''HR'\''",
"hybridSearch": true,
"limit": 10,
"adjacentChunkRange": 2
}'
Streaming
curl -N -X POST "/v1/agents/{agent_id}/versions/latest/invoke-stream" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": "What entities are related to Project Alpha?"
}
]
}'
Responses come in chunks: newline-delimited JSON objects, each a valid JSON object on its own (response.output_text.delta chunks carry the delta text). The concatenation of all chunks forms the complete answer text, same wire format as Tool Agent streaming.
Multi-Turn Conversation
Graph RAG agents support multi-turn conversations by passing previous messages in the messages array. The last message must always have role: "user".
Graph RAG agents support optional session-based short-term memory. Add an X-Session-ID header with a consistent UUID to maintain conversation context across multiple invocations. The platform does not auto-generate session IDs — you must generate and manage them yourself (any valid UUID).
curl -X POST "/v1/agents/{agent_id}/versions/latest/invoke" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "X-Session-ID: 550e8400-e29b-41d4-a716-446655440000" \
-d '{
"messages": [
{
"role": "user",
"content": "What entities are related to Project Alpha?"
},
{
"role": "assistant",
"content": "Project Alpha is related to..."
},
{
"role": "user",
"content": "Which of those are in the finance department?"
}
]
}'
Response Format
The response includes both the generated answer and source information from both retrieval sources:
{
"object": "response",
"model": "anthropic.claude-haiku-5-5",
"createdAt": 1709654321,
"output": [
{
"type": "message",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Based on the retrieved documents and knowledge graph..."
}
]
}
],
"customOutputs": {
"sourceNodes": [
{
"docId": "doc-123",
"chunkId": "chunk-456",
"score": 0.95,
"text": "Relevant document excerpt..."
},
{
"docId": "entity-789",
"chunkId": null,
"score": null,
"text": "Knowledge graph entity data..."
}
],
"knowledgeGraphNodes": [
{
"nodeType": "Document",
"id": "0x1",
"title": "Vendor Agreement - Acme Corp",
"docType": "contract",
"summary": "Master services agreement between Acme Corp and...",
"clDocId": "6e4a7f58-13f1-4d3f-83b9-ec86c5b7df60",
"documentId": "6e4a7f58-13f1-4d3f-83b9-ec86c5b7df60"
},
{
"nodeType": "GlobalEntity",
"id": "0x2",
"canonicalName": "Acme Corp",
"entityType": "ORG",
"documentId": "6e4a7f58-13f1-4d3f-83b9-ec86c5b7df60"
}
]
}
}
The sourceNodes array contains entries from both semantic search and knowledge graph sources. The knowledgeGraphNodes array contains typed entities resolved directly from the Knowledge Graph — see Knowledge Graph Nodes below.
Knowledge Graph Nodes
Each entry in knowledgeGraphNodes is one of six typed node shapes, discriminated by the nodeType field:
nodeType | Fields | Description |
|---|---|---|
Document | id, title, docType, summary, clDocId, documentId | A source document |
TextChunk | id, clEmbedId, chunkIndex, text, docId, documentId | A chunk of document text |
GlobalEntity | id, canonicalName, entityType, documentId | A resolved, canonical entity (e.g., an organization or person) |
LocalEntity | id, mentionText, entityType, sentiment, documentId | A single mention of an entity within a document |
BusinessObject | id, name, objectType, description, documentId | A domain-specific business object (e.g., an invoice or contract) |
MetadataKV | id, key, value, valueType, documentId | A metadata key-value pair extracted from a document |
documentId is present on every node type — it identifies the document a node belongs to (or, for Document nodes, the document itself), so you can correlate nodes across a response without a separate lookup. It may be null for nodes resolved from older Knowledge Graph data that hasn't been reprocessed.
Document nodes also carry a clDocId field, kept for backward compatibility. For new integrations, prefer documentId.
Hallucination Detection
Graph RAG includes automatic hallucination detection:
- The generated answer is validated against the retrieved context
- If the answer contains information not supported by the context, it is flagged as hallucinated
- The agent retries answer generation (default: up to 2 retries)
- If retries are exhausted, the last generated answer is returned
This ensures responses stay grounded in the actual retrieved data rather than relying on the LLM's training knowledge.
Differences from Standard RAG
| Feature | RAG | Graph RAG |
|---|---|---|
| Semantic search | Yes | Yes |
| Knowledge graph retrieval | No | Yes |
| Hallucination detection | Configurable | Built-in |
| Streaming support | Yes | Yes |
| Session-based memory | Yes | Yes |
Best Practices
-
Data Preparation
- Ensure your content is ingested into Content Lake with relevant entities and relationships
- Graph RAG uses ECE to provide structured context that complements unstructured document search
-
System Prompt Design
- Do not include
{context_str}or{query_str}— they have no special meaning for Graph RAG and will appear literally, unfilled, in the prompt - Use
systemPromptfor custom instructions only (tone, citation format, domain framing); it is appended to, not a replacement for, the built-in agentic prompt - Instruct the LLM to answer only from tool results, and to state clearly when those results don't contain enough information to answer
- Do not include
-
Retrieval Tuning
- Use
hxqlQueryto scope retrieval to relevant document sets - Adjust
limitbased on your use case (more chunks = more context but higher latency) - Use
rerankerTopNto control how many chunks survive reranking
- Use
-
Guardrails
- For comprehensive information on discovering, configuring, and merging guardrails, see the Guardrails guide.