"""Loader for the shared fixture corpus — seeds and tests draw from it. The corpus is product content (German knowledge documents of the fictional SME "Nordwind Maschinenbau GmbH"). PyYAML is available through uvicorn[standard]; it becomes a declared dependency with the template import in M6. """ from dataclasses import dataclass, field from pathlib import Path from typing import Any import yaml FIXTURES_DIR = Path(__file__).resolve().parent CORPUS_DIR = FIXTURES_DIR / "corpus" @dataclass class CorpusDoc: slug: str title: str department: str visibility: str content_md: str grants: list[str] = field(default_factory=list) def load_corpus() -> list[CorpusDoc]: docs: list[CorpusDoc] = [] for path in sorted(CORPUS_DIR.glob("*.md")): text = path.read_text() if not text.startswith("---\n"): raise ValueError(f"corpus file without frontmatter: {path.name}") _, frontmatter, body = text.split("---\n", 2) meta = yaml.safe_load(frontmatter) docs.append( CorpusDoc( slug=meta["id"], title=meta["title"], department=meta["department"], visibility=meta["visibility"], grants=list(meta.get("grants", [])), content_md=body.strip() + "\n", ) ) return docs def load_golden_queries() -> list[dict[str, Any]]: return yaml.safe_load((FIXTURES_DIR / "golden_queries.yaml").read_text()) def load_conversation_snippets() -> list[dict[str, Any]]: """Short chats whose LAST message is a topic-losing follow-up, with the corpus slug the conversation is really about — for comparing topic-summary retrieval against retrieval over the raw last message.""" return yaml.safe_load((FIXTURES_DIR / "conversation_snippets.yaml").read_text())