Problem
The knowledge graph (src/features/graph/) and the editor (src/features/editor/) are completely disconnected from the AI harness. Notes are never analyzed for entity extraction, and there is no automatic node/edge creation based on note content. src/lib/nlp.ts exists but only performs basic tokenization — no named entity recognition (NER) or relationship extraction.
Impact
- Knowledge graph must be built entirely by hand, making it underutilized
- Related notes/concepts are not automatically connected
- No way to discover implicit relationships in the knowledge base
Proposed Implementation
1. LLM-powered entity extraction prompt
// src/lib/ai/entity-extractor.ts
export const ENTITY_EXTRACTION_PROMPT = `
Analyze the following note and extract:
1. Named entities (people, organizations, technologies, concepts, places)
2. Relationships between entities
Respond ONLY with valid JSON in this exact schema:
{
"entities": [
{ "name": string, "type": "person" | "org" | "tech" | "concept" | "place" | "other", "description": string }
],
"relationships": [
{ "from": string, "to": string, "label": string }
]
}
Note content:
{{CONTENT}}
`;
export async function extractEntities(
content: string,
provider: ILLMProvider,
model: string
): Promise<EntityExtractionResult> {
const prompt = ENTITY_EXTRACTION_PROMPT.replace('{{CONTENT}}', content.slice(0, 2000));
const response = await provider.chat(
[{ role: 'user', content: prompt }],
{ model, temperature: 0, maxTokens: 1000 }
);
return JSON.parse(response.content);
}
2. Entity suggestion UI
After saving a note, show a dismissible notification:
✨ AI found 3 entities and 2 relationships in this note.
[Add to Graph] [Review] [Dismiss]
The "Review" dialog shows:
- List of extracted entities with checkboxes
- List of proposed edges with checkboxes
- "Add Selected to Graph" button
3. Graph integration service
// src/lib/ai/graph-linker.ts
export async function applyEntitiesToGraph(
result: EntityExtractionResult,
graphStore: GraphStore,
selectedEntities: string[],
selectedRelationships: string[]
): Promise<void> {
// Add nodes for selected entities
for (const entity of result.entities.filter(e => selectedEntities.includes(e.name))) {
if (!graphStore.hasNode(entity.name)) {
graphStore.addNode({
id: crypto.randomUUID(),
label: entity.name,
type: entity.type,
description: entity.description,
});
}
}
// Add edges for selected relationships
for (const rel of result.relationships.filter(r => selectedRelationships.includes(`${r.from}->${r.to}`))) {
const fromNode = graphStore.findNodeByLabel(rel.from);
const toNode = graphStore.findNodeByLabel(rel.to);
if (fromNode && toNode) {
graphStore.addEdge({ from: fromNode.id, to: toNode.id, label: rel.label });
}
}
}
4. Note-to-graph link
When a graph node is created from a note, store noteId in node metadata so clicking the node opens the source note.
5. Trigger points
- Manual trigger: "Extract entities" button in note editor toolbar
- Auto-trigger (optional, configurable): Run after note save with debounce of 3 seconds
- Batch mode: "Analyze all notes" action in graph sidebar
Acceptance Criteria
Problem
The knowledge graph (
src/features/graph/) and the editor (src/features/editor/) are completely disconnected from the AI harness. Notes are never analyzed for entity extraction, and there is no automatic node/edge creation based on note content.src/lib/nlp.tsexists but only performs basic tokenization — no named entity recognition (NER) or relationship extraction.Impact
Proposed Implementation
1. LLM-powered entity extraction prompt
2. Entity suggestion UI
After saving a note, show a dismissible notification:
The "Review" dialog shows:
3. Graph integration service
4. Note-to-graph link
When a graph node is created from a note, store
noteIdin node metadata so clicking the node opens the source note.5. Trigger points
Acceptance Criteria
extractEntities()implemented with structured LLM promptnoteIdbacklink