The API is in limited early release and is only available to some private beta usersBecause the API is an early release, current users should expect occasional breaking changes.
In this tutorial, you will use Knowledge Graph to query prerequisite standards for a given standard, enabling differentiated content or product experiences.
Before you begin
There are a couple of things you need to know about the dataset:
- Our current learning progressions dataset, from Student Achievement Partners (SAP), map Common Core State Standards for Mathematics into logical sequences.
- The sequences do not name definitive pre-reqs. Meaning, it is not necessarily true that students must master an earlier standard before they will be ready for the standards it supports. Instead, the relationships indicate what might be helpful in a given circumstance.
To learn more about these entities, read the data references for Academic Standards and Learning Progressions.
What you’ll do
- Navigating learning progressions relationships
- Unpacking standards into learning components
- Inserting Knowledge Graph data into LLM context for content generation
What you’ll need
- A Learning Commons Platform account
- An API key generated in the platform
- Your base URL from the Learning Commons Platform
- Node or Python for running code examples
- OpenAI API key for generating practice questions
- OpenAI SDK installed (
pip install openai for Python or npm install openai for JavaScript)
STEP 1: Set up environment variables
- Set up your environment variables for your API key, base URL, and OpenAI.
# .env
# Knowledge Graph API credentials - get these from the Learning Commons Portal
API_KEY=your_api_key_here
BASE_URL=https://api.learningcommons.org/knowledge-graph/v0
# OpenAI API key for generating practice questions
OPENAI_API_KEY=your_openai_api_key_here
STEP 2: Get prerequisite standards for 6.NS.B.4
- Use the
/academic-standards/search endpoint to find the standard, then use the /prerequisites endpoint to get its prerequisites:
# Step 1: Find the target standard by statement code
curl -X GET \
-H "x-api-key: YOUR_API_KEY" \
"https://api.learningcommons.org/knowledge-graph/v0/academic-standards/search?statementCode=6.NS.B.4&jurisdiction=Multi-State"
# Step 2: Get prerequisites using the caseIdentifierUUID from Step 1
curl -X GET \
-H "x-api-key: YOUR_API_KEY" \
"https://api.learningcommons.org/knowledge-graph/v0/academic-standards/YOUR_UUID/prerequisites"
The data for the specific standard should look like this:
[
{
"caseIdentifierUUID": "6b9ed00e-d7cc-11e8-824f-0242ac160002",
"statementCode": "4.OA.B.4",
"standardDescription": "A buildsTowards relationship indicates that proficiency in one entity supports the likelihood of success in another, capturing a directional progression without requiring strict prerequisite order."
},
// ...
]
- Find the learning components that support the prerequisite standards that we just found using the
/learning-components endpoint for each prerequisite standard:
# Get learning components for a prerequisite standard
# Replace PREREQ_UUID with each prerequisite's caseIdentifierUUID
curl -X GET \
-H "x-api-key: YOUR_API_KEY" \
"https://api.learningcommons.org/knowledge-graph/v0/academic-standards/PREREQ_UUID/learning-components"
The learning components and prerequisite standards data should look like this:
[
{
"caseIdentifierUUID": "6b9d5f43-d7cc-11e8-824f-0242ac160002",
"statementCode": "5.OA.A.2",
"standardDescription": "A buildsTowards relationship indicates that proficiency in one entity supports the likelihood of success in another, capturing a directional progression without requiring strict prerequisite order.",
"learningComponentDescription": "Write simple expressions of two or more steps and with grouping symbols that record calculations with numbers"
},
// ...
]
The prerequisiteLearningComponents array is ready to be used for generating practice questions in Step 3.
STEP 3: Generate practice problems
Now that you’ve identified learning components and prerequisite standards, you can use those for downstream applications, such as generating practice problems. But, remember the caveats discussed above and use your judgement to create appropriate learning experiences.
- Create clean JSON to package the data, making it easily parsable by the LLM and preserving the data’s relationship structure.
function packageContextData(targetStandard, prerequisiteLearningComponents) {
/* Package the standards and learning components data for text generation
* This creates a structured context that can be used for generating practice questions
*/
const standardsMap = new Map();
// Group learning components by standard for context
for (const row of prerequisiteLearningComponents) {
if (!standardsMap.has(row.caseIdentifierUUID)) {
standardsMap.set(row.caseIdentifierUUID, {
statementCode: row.statementCode,
description: row.standardDescription || '(no statement)',
supportingLearningComponents: []
});
}
standardsMap.get(row.caseIdentifierUUID).supportingLearningComponents.push({
description: row.learningComponentDescription || '(no description)'
});
}
const fullStandardsContext = {
targetStandard: {
statementCode: targetStandard.statementCode,
description: targetStandard.description || '(no statement)'
},
prereqStandards: Array.from(standardsMap.values())
};
return fullStandardsContext;
}
- Use that JSON in a prompt so the LLM has full context of what to create practice problems for.
const OpenAI = require('openai');
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const OPENAI_MODEL = 'gpt-4';
const OPENAI_TEMPERATURE = 0.7;
async function generatePractice(fullStandardsContext) {
console.log(`🔄 Generating practice questions for ${fullStandardsContext.targetStandard.statementCode}...`);
try {
// Build prompt inline
let prerequisiteText = '';
for (const prereq of fullStandardsContext.prereqStandards) {
prerequisiteText += `- ${prereq.statementCode}: ${prereq.description}\n`;
prerequisiteText += ' Supporting Learning Components:\n';
for (const lc of prereq.supportingLearningComponents) {
prerequisiteText += ` • ${lc.description}\n`;
}
}
const prompt = `You are a math tutor helping middle school students. Based on the following information, generate 3 practice questions for the target standard. Questions should help reinforce the key concept and build on prerequisite knowledge.
Target Standard:
- ${fullStandardsContext.targetStandard.statementCode}: ${fullStandardsContext.targetStandard.description}
Prerequisite Standards & Supporting Learning Components:
${prerequisiteText}`;
const response = await openai.chat.completions.create({
model: OPENAI_MODEL,
messages: [
{ role: 'system', content: 'You are an expert middle school math tutor.' },
{ role: 'user', content: prompt }
],
temperature: OPENAI_TEMPERATURE
});
const practiceQuestions = response.choices[0].message.content.trim();
console.log(`✅ Generated practice questions:\n`);
console.log(practiceQuestions);
return {
aiGenerated: practiceQuestions,
targetStandard: fullStandardsContext.targetStandard.statementCode,
prerequisiteCount: fullStandardsContext.prereqStandards.length
};
} catch (err) {
console.error('❌ Error generating practice questions:', err.message);
throw err;
}
}
The resulting generated problems should look something like this:
Question 1:
Find the greatest common factor of 36 and 90. Then use the distributive property to express the sum of these two numbers as a multiple of a sum of two whole numbers with no common factor.
Question 2:
Write the expression "add 12 and 15, then multiply by 3" as an algebraic expression. After that, recognize that this expression is three times as large as 12 + 15, without having to calculate the indicated sum or product.
Question 3:
Determine whether the number 72 is a multiple of the digit 8. Find all factor pairs of 72. Recognize that 72 is a multiple of each of its factors and determine whether 72 is a prime or a composite number.
Everything here was scoped to a single standard for clarity, but the same steps work across grade levels, subject areas, or even larger parts of the dataset. As you continue to experiment, try extending the queries to include lessons, assessments, or instructional routines to create more comprehensive learning experiences.