Overview
The Graph API provides endpoints to visualize and interact with the underlying knowledge graph structure. This is useful for understanding document relationships and debugging your RAG implementation.
Graph endpoints are primarily for internal use and visualization. They expose
the Neo4j graph structure.
Get Graph Data
Retrieve all nodes and relationships for a chat:
GET /graph_data/{chat_id}
Basic Example
curl -X GET https://api.trainlyai.com/graph_data/chat_abc123 \
-H "Authorization: Bearer your_api_key"
Response:
{
"nodes" : [
{
"id" : "123" ,
"labels" : [ "Document" ],
"properties" : {
"id" : "doc_abc123" ,
"filename" : "research.pdf" ,
"chatId" : "chat_abc123" ,
"uploadDate" : 1609459200000 ,
"sizeBytes" : 524288
}
},
{
"id" : "124" ,
"labels" : [ "Chunk" ],
"properties" : {
"id" : "doc_abc123-0" ,
"text" : "Introduction: This research explores..." ,
"chatId" : "chat_abc123"
}
}
],
"relationships" : [
{
"id" : "456" ,
"source" : "123" ,
"target" : "124" ,
"type" : "HAS_CHUNK" ,
"properties" : {
"order" : 0
}
},
{
"id" : "457" ,
"source" : "124" ,
"target" : "125" ,
"type" : "EXPLAINS" ,
"properties" : {
"confidence" : 0.92 ,
"ai_generated" : true
}
}
]
}
Relationship Types
Trainly creates various relationship types automatically:
Direction : Document → ChunkLinks documents to their text chunks.
Direction : Chunk → ChunkSequential relationship preserving document order.
Direction : Chunk → ChunkAI-generated: One chunk explains concepts in another.
Direction : Chunk → ChunkAI-generated: One chunk provides evidence for another.
Node Operations
Get Node Details
GET /node_details/{node_id}
Update Node
PUT /update_node/{node_id}
Delete Node
DELETE /delete_node/{node_id}
Relationship Operations
Create Relationship
POST /create_relationship
Update Relationship
PUT /update_relationship/{relationship_id}
Delete Relationship
DELETE /delete_relationship/{relationship_id}
Visualization Examples
D3.js Force Graph
async function renderGraph ( chatId ) {
const response = await fetch (
`https://api.trainlyai.com/graph_data/ ${ chatId } ` ,
);
const data = await response . json ();
// Create D3 force simulation
const simulation = d3
. forceSimulation ( data . nodes )
. force ( "link" , d3 . forceLink ( data . relationships ))
. force ( "charge" , d3 . forceManyBody ())
. force ( "center" , d3 . forceCenter ());
// Render visualization...
}
See the complete endpoint documentation for detailed examples.