(schema: TSchema)
| 398 | * the LLM about both the query language syntax and the specific graph structure. |
| 399 | */ |
| 400 | export function generateSchemaGuide<TSchema extends GraphSchema>(schema: TSchema): string { |
| 401 | const sections: string[] = []; |
| 402 | |
| 403 | // Header |
| 404 | sections.push("# Graph Query Language Guide"); |
| 405 | sections.push(""); |
| 406 | sections.push( |
| 407 | "This graph database supports a declarative query language for traversing and querying graph data.", |
| 408 | ); |
| 409 | sections.push(""); |
| 410 | |
| 411 | // Schema Overview |
| 412 | sections.push("## Graph Schema"); |
| 413 | sections.push(""); |
| 414 | sections.push("### Vertex Types"); |
| 415 | sections.push(""); |
| 416 | |
| 417 | const vertexLabels = Object.keys(schema.vertices); |
| 418 | if (vertexLabels.length === 0) { |
| 419 | sections.push("No vertex types defined."); |
| 420 | } else { |
| 421 | for (const label of vertexLabels) { |
| 422 | const properties = schema.vertices[label]?.properties; |
| 423 | sections.push(`**${label}**`); |
| 424 | |
| 425 | if (properties && Object.keys(properties).length > 0) { |
| 426 | sections.push("Properties:"); |
| 427 | for (const [propName] of Object.entries(properties)) { |
| 428 | sections.push(` - \`${propName}\``); |
| 429 | } |
| 430 | } else { |
| 431 | sections.push(" No properties defined."); |
| 432 | } |
| 433 | sections.push(""); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | sections.push("### Edge Types"); |
| 438 | sections.push(""); |
| 439 | |
| 440 | const edgeLabels = Object.keys(schema.edges); |
| 441 | if (edgeLabels.length === 0) { |
| 442 | sections.push("No edge types defined."); |
| 443 | } else { |
| 444 | for (const label of edgeLabels) { |
| 445 | const properties = schema.edges[label]?.properties; |
| 446 | sections.push(`**${label}**`); |
| 447 | |
| 448 | if (properties && Object.keys(properties).length > 0) { |
| 449 | sections.push("Properties:"); |
| 450 | for (const [propName] of Object.entries(properties)) { |
| 451 | sections.push(` - \`${propName}\``); |
| 452 | } |
| 453 | } else { |
| 454 | sections.push(" No properties defined."); |
| 455 | } |
| 456 | sections.push(""); |
| 457 | } |
no test coverage detected