fix(graph): route wiki/<flat>.md to Type=knowledge, not Type=hall with filename-as-wing
classifyByPath had a hole: paths like wiki/index.md or wiki/<slug>.md (direct children of wiki/, no subdirectory) hit the default branch and wrote Wing=parts[1] — which IS the filename, not a wing. Symptom in brain_entities: rows like (slug=index, wing=index.md) and (slug=autobe-..., wing=autobe-evaluation-pattern-....md). Fix: when len(parts) < 3 (no subdirectory at all), fall through to Type=knowledge and let frontmatter set wing/hall if present. Add brain/eval/ artifacts at the same time: - qa-2026-05.md — 20 hand-authored Q→expected-slug pairs covering the homelab knowledge corpus across mcp, dex, gitops, postgres, go, models, methodology - score.py — calls brain_query for each pair, scores top-1 + top-3, emits per-question detail. BRAIN_MCP_TOKEN via env. Pre-fix baseline against the live brain: top-1 = 20% (4/20), top-3 = 65% (13/20). Six hard misses where the expected slug doesn't even land in the top-5. Used to gate the phase 2 DIKW redesign (infra#62 follow-up): if phase 1 fixes (this parser fix + 20 backlink authoring on top orphans) lift top-1 by <10 absolute points, structure is the bottleneck and the tier redesign is justified.
This commit is contained in:
@@ -83,12 +83,23 @@ func slugFromPath(docPath string) string {
|
||||
// classifyByPath fills Type / Wing / Hall from the path layout when the
|
||||
// doc lives under brain/wiki/. Layout: wiki/<wing>/<hall>/<slug>.md
|
||||
// or wiki/<bucket>/<slug>.md for the legacy concept/entity/source dirs.
|
||||
//
|
||||
// Files directly under wiki/ (no subdirectory — e.g. wiki/index.md) used
|
||||
// to incorrectly land Type="hall" Wing="index.md" because the path's
|
||||
// second segment was the file itself. Now they fall through to Type
|
||||
// "knowledge" and leave wing/hall to frontmatter.
|
||||
func classifyByPath(e *Entity, docPath string) {
|
||||
parts := strings.Split(docPath, "/")
|
||||
if len(parts) < 2 || parts[0] != "wiki" {
|
||||
e.Type = "knowledge"
|
||||
return
|
||||
}
|
||||
if len(parts) < 3 {
|
||||
// wiki/<slug>.md — no subdirectory. Treat as plain knowledge
|
||||
// and let frontmatter set wing/hall if they're present.
|
||||
e.Type = "knowledge"
|
||||
return
|
||||
}
|
||||
switch parts[1] {
|
||||
case "concepts":
|
||||
e.Type = "concept"
|
||||
|
||||
@@ -104,3 +104,31 @@ func TestExtract_LineNumbersAre1Indexed(t *testing.T) {
|
||||
require.Len(t, edges, 1)
|
||||
assert.Equal(t, 2, edges[0].SrcLine)
|
||||
}
|
||||
|
||||
// Files directly under wiki/ (no subdirectory) used to land
|
||||
// Type="hall" Wing="<filename>.md" because the path's second segment
|
||||
// was the file itself. The fix routes them to Type="knowledge" with
|
||||
// empty Wing/Hall and lets frontmatter set them if present.
|
||||
func TestExtract_WikiRootFileIsKnowledgeNotHall(t *testing.T) {
|
||||
content := []byte("# Index\n\n- [[foo]]\n")
|
||||
ent, _, ok := Extract("wiki/index.md", content)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "index", ent.Slug)
|
||||
assert.Equal(t, "knowledge", ent.Type)
|
||||
assert.Empty(t, ent.Wing)
|
||||
assert.Empty(t, ent.Hall)
|
||||
}
|
||||
|
||||
func TestExtract_WikiRootFileWithFrontmatterWingHall(t *testing.T) {
|
||||
content := []byte(`---
|
||||
wing: homelab
|
||||
hall: facts
|
||||
---
|
||||
# Some root note
|
||||
`)
|
||||
ent, _, ok := Extract("wiki/some-note.md", content)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "knowledge", ent.Type)
|
||||
assert.Equal(t, "homelab", ent.Wing)
|
||||
assert.Equal(t, "facts", ent.Hall)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user