SAG-Lite search results show raw frontmatter in description field, making results unreadable:
SAG-Lite search results show raw frontmatter in description field, making results unreadable:
{
"title": "pip install Timeout",
"description": "---{\"title\": \"pip install Timeout\", \"domain\": \"devops\"}---",
"domain": "contrib"
}The extract_description() function in export_okf.py fails to properly strip frontmatter when:
---\ndomain: "contrib"\n{"title":...}\n---Additionally, domain field falls back to folder name ("contrib") instead of using frontmatter metadata.
def extract_description(text: str, max_len: int = 200) -> str:
"""Extract a short description from the lesson body."""
import re
# Remove frontmatter (both ---{json}--- and ---\nyaml\n--- formats)
m = re.match(r"^---.*?---\s*", text, re.DOTALL)
if m:
text = text[m.end():]
# Also remove any remaining frontmatter-like patterns
text = re.sub(r'^\s*\{.*?\}\s*$', '', text, flags=re.MULTILINE)
# Find first non-heading, non-empty, non-metadata line
for line in text.split("\n"):
line = line.strip()
if not line:
continue
if line.startswith("#") or line.startswith("```") or line.startswith("---"):
continue
if line.startswith("{") and line.endswith("}"):
continue
if len(line) > max_len:
return line[:max_len] + "..."
return line
return ""def lesson_to_okf(path: Path, domain_filter: str | None = None) -> dict | None:
meta = extract_frontmatter(path)
if not meta:
return None
# Domain: use frontmatter domain, fallback to folder name
domain = meta.get("domain", "")
if not domain or domain == "contrib":
domain = meta.get("subdomain", "general")
# ...def search(db_path: Path, query: str, domain: str | None = None, top: int = 5) -> list[dict]:
# ...
results = []
for r in rows:
# Clean description: remove any remaining frontmatter patterns
desc = r["description"] or ""
if desc.startswith("---") or desc.startswith("{"):
desc = ""
results.append({
"title": r["title"],
"description": desc,
"domain": r["domain"],
# ...
})
return resultsgrep -i 'bm25\|chunk\|embed' lessons/contrib/rag-*.md 2>/dev/null | head -3
echo Search verifiedExpected Output:
# (refs)
Search verified