Skip to main content

Graph RAG

Beta Feature

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​

ParameterDescriptionRequiredExample
agentTypeMust be "graphRag"Yes"graphRag"
knowledgeGraphIdKnowledge Graph IDYes"7a0e6c74-7c62-4636-adbf-857340244e7d"
ontologyIdsOntology IDs to scope graph document retrieval to (max 50). When set, only documents tagged with any of these ontologies are returnedNo["9f8c1a2e-3b4d-4e5f-8a6b-7c8d9e0f1a2b"]
llmModelIdLLM model identifierYes"openai.gpt-5.6-luna"
systemPromptCustom instructions appended to the agent's built-in prompt (see below)No"You are a domain expert. Cite the source document for every claim."
inferenceConfigLLM inference parametersNo{"maxTokens": 4000, "temperature": 0.7}
hxqlQueryHxQL filter for Content Lake retrievalNo"SELECT * FROM SysContent"
hybridSearchEnable hybrid search (embeddings + full-text)Notrue
limitMaximum number of chunks to retrieveNo5
adjacentChunkRangeNumber of adjacent chunks to fetch around each result (0 = disabled)No1
adjacentChunkMergeMerge adjacent chunks into the parent chunk in document orderNotrue
guardrailsList 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.
tip

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:

ParameterDescriptionDefault
hxqlQueryHxQL query to filter Content Lake documentsConfig default
hybridSearchEnable hybrid search (embeddings + full-text)Config default
limitNumber of chunks to retrieveConfig default
adjacentChunkRangeNumber of adjacent chunks to fetch around each resultConfig default
adjacentChunkMergeMerge adjacent chunks into parent chunkConfig default
rerankerTopNNumber of results to keep after rerankingConfig 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?"
}
]
}'
tip

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".

Session-Based Memory

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:

nodeTypeFieldsDescription
Documentid, title, docType, summary, clDocId, documentIdA source document
TextChunkid, clEmbedId, chunkIndex, text, docId, documentIdA chunk of document text
GlobalEntityid, canonicalName, entityType, documentIdA resolved, canonical entity (e.g., an organization or person)
LocalEntityid, mentionText, entityType, sentiment, documentIdA single mention of an entity within a document
BusinessObjectid, name, objectType, description, documentIdA domain-specific business object (e.g., an invoice or contract)
MetadataKVid, key, value, valueType, documentIdA 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.

tip

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​

FeatureRAGGraph RAG
Semantic searchYesYes
Knowledge graph retrievalNoYes
Hallucination detectionConfigurableBuilt-in
Streaming supportYesYes
Session-based memoryYesYes

Best Practices​

  1. 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
  2. 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 systemPrompt for 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
  3. Retrieval Tuning

    • Use hxqlQuery to scope retrieval to relevant document sets
    • Adjust limit based on your use case (more chunks = more context but higher latency)
    • Use rerankerTopN to control how many chunks survive reranking
  4. Guardrails

    • For comprehensive information on discovering, configuring, and merging guardrails, see the Guardrails guide.