Aside from adding LLMS.txt and files to your documentation website and using Retrieval Augmented Generation (RAG), you can add Knowledge Graphs.
A Knowledge Graph is a structured representation of information as entities (nodes) and relationships (edges) — like a network of facts about your system, APIs, concepts, and how they connect. The dataset is usually stored in a graph database. However, for simple use cases, you can represent a small knowledge graph as a local file, e.g., JSON-LD, RDF, Turtle, or CSV format, and keep it in your site’s repo for indexing or LLM/RAG purposes.
Auto-generate a Knowledge Graph
- Use LLMs to extract entities and relationships from your docs (e.g., APIs, modules, error codes, dependencies).
- Tools like LangChain’s KG Retriever or Haystack’s KG pipelines help integrate this.
Formats
- RDF / Turtle (for Semantic Web)
- JSON-LD (for structured data, LLM-readable)
- CSV triples (
subject, predicate, object) - GraphML or Neo4j format (for databases)
Place a knowledge-graph.jsonld or knowledge-graph.csv file in the root directory of your Documentation website or a hidden /llm/ directory.
For scalable use, load it into a graph database (e.g., Neo4j, Weaviate, TerminusDB) that can be queried at retrieval time.
About the JSON-LD Format
In JSON-LD, the : separates a prefix from a term, like this:
"name": "product:name"This means:
productis a prefix that maps to a URL base (defined in the"@context")nameis the actual property
So "product:name" becomes https://example.com/product#name (fully qualified), see example below.
Info
JSON-LD keywords:
@contextdefines the mapping between prefixes and full URIs@typedefines what type of thing the object is (like a class in RDF)@idcan optionally define a globally unique ID for an entity
Example API Reference (JSON-LD format)
Create a file: knowledge-graph.jsonld
Put it in your project root or docs/llm/ folder.
The following example represents:
LoginEndpointcallsJWTServiceand returns anAccessTokenJWTServiceis used byLoginEndpoint
{
"@context": {
"api": "https://example.com/api#",
"name": "api:name",
"type": "@type",
"calls": "api:calls",
"returns": "api:returns",
"usedBy": "api:usedBy"
},
"@graph": [
{
"name": "LoginEndpoint",
"type": "api:Endpoint",
"calls": "JWTService",
"returns": "AccessToken"
},
{
"name": "JWTService",
"type": "api:Service",
"usedBy": "LoginEndpoint"
},
{
"name": "AccessToken",
"type": "api:DataObject"
}
]
}Example Product Website (JSON-LD format)
Typical entities on product websites:
- Product components: Dashboard, Analytics, Notification System
- User roles: Admin, Viewer, Contributor
- Features: Real-time reports, Dark mode, Email alerts
- Integrations: Slack, Stripe, Zapier
- Plans: Free, Pro, Enterprise
- Pages:
home,pricing,getting-started,troubleshooting
Typical relationships on product websites:
offersFeaturerequiresusedByhasIntegrationrelevantForavailableInPlan
Create a file: product-kg.jsonld
If a user asks: “What integrations are available in the Pro plan?”, the LLM can:
- Look up components in the
ProPlan - Get their
offersFeature - Check if those features have
hasIntegrationlinks
{
"@context": {
"product": "https://example.com/product#",
"name": "product:name",
"type": "@type",
"offersFeature": "product:offersFeature",
"hasIntegration": "product:hasIntegration",
"availableInPlan": "product:availableInPlan",
"relevantFor": "product:relevantFor"
},
"@graph": [
{
"name": "AnalyticsDashboard",
"type": "product:Component",
"offersFeature": ["RealTimeReports", "EmailAlerts"],
"availableInPlan": ["ProPlan", "EnterprisePlan"]
},
{
"name": "RealTimeReports",
"type": "product:Feature",
"relevantFor": "Admin"
},
{
"name": "EmailAlerts",
"type": "product:Feature",
"hasIntegration": "Slack"
},
{
"name": "Slack",
"type": "product:Integration"
},
{
"name": "ProPlan",
"type": "product:Plan"
},
{
"name": "EnterprisePlan",
"type": "product:Plan"
},
{
"name": "Admin",
"type": "product:UserRole"
}
]
}