(schema: TSchema)
| 808 | * in system prompts or context windows with token limits. |
| 809 | */ |
| 810 | export function generateCompactSchemaGuide<TSchema extends GraphSchema>(schema: TSchema): string { |
| 811 | const sections: string[] = []; |
| 812 | |
| 813 | sections.push("# Graph Query Language"); |
| 814 | sections.push(""); |
| 815 | |
| 816 | // Compact Schema |
| 817 | sections.push("**Schema:**"); |
| 818 | const vertexLabels = Object.keys(schema.vertices); |
| 819 | const edgeLabels = Object.keys(schema.edges); |
| 820 | |
| 821 | if (vertexLabels.length > 0) { |
| 822 | sections.push(`Vertices: ${vertexLabels.join(", ")}`); |
| 823 | for (const label of vertexLabels) { |
| 824 | const props = schema.vertices[label]?.properties; |
| 825 | if (props && Object.keys(props).length > 0) { |
| 826 | const propList = Object.keys(props).join(", "); |
| 827 | sections.push(` ${label}: {${propList}}`); |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | if (edgeLabels.length > 0) { |
| 833 | sections.push(`Edges: ${edgeLabels.join(", ")}`); |
| 834 | } |
| 835 | sections.push(""); |
| 836 | |
| 837 | // Compact Syntax |
| 838 | sections.push("**Syntax:**"); |
| 839 | sections.push("```"); |
| 840 | sections.push("MATCH (v:Label)-[:edge]->(v2:Label2)"); |
| 841 | sections.push("WHERE v.property > value"); |
| 842 | sections.push("RETURN v [DISTINCT] [ORDER BY v.prop] [LIMIT n]"); |
| 843 | sections.push("```"); |
| 844 | sections.push(""); |
| 845 | sections.push( |
| 846 | "**Note:** IDs use format `<EntityName>:<uuid>` (e.g., `User:12345678-1234-1234-1234-123456789abc`)", |
| 847 | ); |
| 848 | sections.push(""); |
| 849 | |
| 850 | // One complete example |
| 851 | if (vertexLabels.length >= 2 && edgeLabels.length > 0) { |
| 852 | const v1 = vertexLabels[0]; |
| 853 | const v2 = vertexLabels[1]; |
| 854 | const edge = edgeLabels[0]; |
| 855 | sections.push("**Examples:**"); |
| 856 | sections.push("```"); |
| 857 | sections.push(`// Query by ID`); |
| 858 | sections.push( |
| 859 | `MATCH (a:${v1}) WHERE a.@id = "${v1}:12345678-1234-1234-1234-123456789abc" RETURN a`, |
| 860 | ); |
| 861 | sections.push(""); |
| 862 | sections.push(`// Traverse relationships`); |
| 863 | sections.push(`MATCH (a:${v1})-[:${edge}]->(b:${v2}) RETURN b LIMIT 10`); |
| 864 | sections.push("```"); |
| 865 | } |
| 866 | |
| 867 | return sections.join("\n"); |
no test coverage detected