# Wiki — Knowledge Base

> Documentation your AI agent can search semantically

Hierarchical Markdown pages with a WYSIWYG editor, image uploads to MinIO, and semantic search via pgvector + OpenAI embeddings. A wiki designed for humans and AI agents alike.

## Features

- **Page hierarchy**: Page tree with parent/child relationships. Breadcrumbs for navigation. Child pages displayed on parent page.
- **WYSIWYG editor (EasyMDE)**: Markdown with live preview, formatting, and drag & drop image insertion. Dark theme matching the UI.
- **Image uploads to MinIO**: Images stored in object storage (MinIO). Path: {slug}/attachments/{filename}. Served directly.
- **Semantic search (RAG)**: pgvector with HNSW index + OpenAI text-embedding-3-small. Ask in natural language — system finds best matching fragments.
- **Chunking with overlap**: Pages split into ~500 token chunks with overlap. Tokenization via tiktoken. Each chunk has its own embedding.
- **Author tracking**: Who created the page, who last edited. Full change transparency.
- **Graceful degradation**: No OpenAI key? Wiki works normally — semantic search is simply disabled.
- **Markdown rendering**: render_markdown_html() with Tailwind prose prose-invert. Same renderer used in Scrum tickets and comments.

## How it works

1. **Create a root page**: E.g., "System Architecture". Use the EasyMDE editor to write in Markdown.
2. **Add child pages**: Create children, e.g., "Database Design" under "Architecture". Tree builds automatically.
3. **Insert images**: Drag images into the editor — they auto-upload to MinIO and insert as Markdown.
4. **Search semantically**: Type a question in the search field — system finds best matching page fragments based on meaning, not just keywords.
5. **AI searches wiki via MCP**: Your AI agent can read any page and search semantically — as if it were a team member.

## AI and MCP

Wiki is the heart of Monolynx's AI-first approach. Your AI agent searches documentation, manages attachments and project files — 12 MCP tools.

- `list_wiki_pages`: Full hierarchy tree with parent_id and depth
- `get_wiki_page`: Page content + breadcrumbs for navigation
- `create_wiki_page`: New page with optional parent_id (child page)
- `update_wiki_page`: Edit content, title, position
- `delete_wiki_page`: Cascading delete (page + children)
- `search_wiki`: Semantic RAG search (if embeddings are active)
- `add_wiki_page_attachment`: Add attachment to wiki page (base64)
- `get_wiki_attachment`: Get wiki page attachment content (base64)
- `add_wiki_file`: Add global file to wiki repository
- `get_wiki_file`: Get global file content (base64)
- `update_wiki_file`: Update file description or name
- `list_wiki_files`: List global files in wiki repository

## Technical details

- **Embeddings**: OpenAI text-embedding-3-small (1536 dimensions). Chunking via tiktoken (gpt-4o model), ~500 tokens with overlap.
- **Search**: pgvector with HNSW index, cosine similarity. Results sorted by relevance with snippet preview.
- **Content storage**: Markdown in MinIO ({slug}/pages/{page_id}.md). Metadata (title, hierarchy, position) in PostgreSQL.
- **Graceful degradation**: OPENAI_API_KEY='' disables embeddings. Wiki works without semantic search.
