From d23b0b6b164dac795afb39453b0bcbb6cc42f69d Mon Sep 17 00:00:00 2001 From: RaymondVerhoef Date: Tue, 19 May 2026 08:40:52 +0200 Subject: [PATCH] feat: add learning_relevance field to topics and implement KnowledgeGraph UI with handbook synchronization capabilities --- pb_migrations/1780000001_updated_topics.js | 30 ++++++++++++++++++++++ src/components/admin/KnowledgeGraph.jsx | 11 +++++++- src/lib/db.js | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pb_migrations/1780000001_updated_topics.js diff --git a/pb_migrations/1780000001_updated_topics.js b/pb_migrations/1780000001_updated_topics.js new file mode 100644 index 0000000..7208b91 --- /dev/null +++ b/pb_migrations/1780000001_updated_topics.js @@ -0,0 +1,30 @@ +/// +migrate((app) => { + const collection = app.findCollectionByNameOrId("pbc_2800040823") + + // add field + collection.fields.addAt(4, new Field({ + "autogeneratePattern": "", + "help": "", + "hidden": false, + "id": "text_learning_relevance", + "max": 0, + "min": 0, + "name": "learning_relevance", + "pattern": "", + "presentable": false, + "primaryKey": false, + "required": false, + "system": false, + "type": "text" + })) + + return app.save(collection) +}, (app) => { + const collection = app.findCollectionByNameOrId("pbc_2800040823") + + // remove field + collection.fields.removeById("text_learning_relevance") + + return app.save(collection) +}) diff --git a/src/components/admin/KnowledgeGraph.jsx b/src/components/admin/KnowledgeGraph.jsx index 543fae3..fd97326 100644 --- a/src/components/admin/KnowledgeGraph.jsx +++ b/src/components/admin/KnowledgeGraph.jsx @@ -299,8 +299,17 @@ Rules: 3. Identify missing logical relations (depends_on, part_of, related_to) if two topics are conceptually linked but missing a relation. 4. Return ONLY a valid JSON object describing the ACTIONS to take. Do not return the entire graph. Do not wrap in markdown blocks.`; + // Send a compact representation to minimize token usage and avoid rate limits. + // The AI only needs id, label, and type to identify duplicates/merges. + const compactTopics = currentTopics.map(({ id, label, type }) => ({ id, label, type })); + const compactRelations = currentRelations.map(r => ({ + source: r.source?.id || r.source, + target: r.target?.id || r.target, + type: r.type + })); + const userPrompt = `Here is the current knowledge graph: -${JSON.stringify({ topics: currentTopics, relations: currentRelations }, null, 2)} +${JSON.stringify({ topics: compactTopics, relations: compactRelations })} Analyze this graph and return ONLY the optimized JSON object with this EXACT structure: { diff --git a/src/lib/db.js b/src/lib/db.js index 92ceff6..ea9cfb0 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -14,6 +14,7 @@ export async function saveTopics(topics) { label: t.label, type: t.type, description: t.description, + learning_relevance: t.learning_relevance || 'standard', }, { requestKey: null }))); }