SDK · Playground
Pick a recipe, hit Run to see the simulated output, or Open in StackBlitz to get a live Node.js environment with @unified-product-graph/sdk pre-installed and the recipe ready to edit and run.
Cookbook · AI integration
Search for relevant nodes, pull a one-hop neighbourhood, build a typed context block, hand to Claude.
Code
import Anthropic from '@anthropic-ai/sdk'
import { UPGClient } from '@unified-product-graph/sdk'
const upg = new UPGClient({ file: './product.upg' })
const anthropic = new Anthropic()
export async function answerWithGraph(question: string) {
// 1. Find relevant nodes.
const hits = await upg.search(question, { limit: 8 })
// 2. Pull a one-hop neighbourhood for each hit.
const context = await Promise.all(
hits.map(async h => ({
node: h.node,
outgoing: await upg.edges.list({ source: h.node.id }),
incoming: await upg.edges.list({ target: h.node.id }),
})),
)
// 3. Render as a typed context block.
const contextBlock = context.map(c => [
`${c.node.type}: ${c.node.title}`,
` out: ${c.outgoing.map(e => e.type).join(', ') || '-'}`,
` in: ${c.incoming.map(e => e.type).join(', ') || '-'}`,
].join('\n')).join('\n\n')
// 4. Ask Claude.
const reply = await anthropic.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{
role: 'user',
content: `Product graph context:\n${contextBlock}\n\nQuestion: ${question}`,
}],
})
return reply.content[0].type === 'text' ? reply.content[0].text : ''
}
console.log(await answerWithGraph(
'Which features address busy-parent jobs?',
))Output
// click ▶ Run to see what this snippet would print locally