Phase 11 — Knowledge Brain
The business's private knowledge base — FAQs, SOPs, pricing, policies, and promotions — that gets injected into every AI call so the AI always has accurate, up-to-date business information.
What It Does
Tenants build a structured knowledge base for their business. When a call comes in, KaiVox searches the knowledge base for relevant items and injects up to 8 of them (max 3000 chars) into the AI system prompt. The AI then uses this to answer caller questions accurately without hallucinating. Tenants can add items manually, scrape their website, or upload files.
Knowledge Categories
| Category | Use Case | Example |
|---|---|---|
faq | Frequently asked caller questions | "Do you accept walk-ins?" → "Yes, we accept walk-ins Mon-Fri before 5pm." |
pricing | Service prices, consultation fees | "Consultation: ₹500, Ultrasound: ₹800" |
sop | Standard operating procedures for staff/AI | "If caller reports chest pain, immediately escalate to emergency." |
policy | Business policies (cancellation, payment, etc.) | "Cancellations must be made 2 hours in advance." |
promotion | Current offers and promotions | "20% off all dental cleanings in January." |
general | Business info, location, parking, etc. | "Free parking available at basement level." |
Key Routes
| URL | Description |
|---|---|
GET /knowledge | Knowledge Brain dashboard with stats, category filter, search |
POST /knowledge | Create new knowledge item |
PUT /knowledge/{id} | Update item (inline edit) |
DELETE /knowledge/{id} | Delete item |
POST /knowledge/{id}/toggle | Toggle active/inactive |
POST /knowledge/scrape-url | Scrape a URL and pre-fill the Add modal |
POST /knowledge/upload-file | Upload .txt/.md/.csv/.pdf and extract content |
GET /knowledge/ai-preview | Show exact text that would be injected into AI with char/token count |
Key Files
| Type | Path |
|---|---|
| Service | app/Services/KnowledgeService.php — buildAiContext(), keyword search |
| Controller | app/Http/Controllers/KnowledgeController.php |
| Model | app/Models/KnowledgeItem.php |
| Table | knowledge_items — tenant_id, category, title, content, priority, is_active, source (manual/scraped/uploaded) |
| Index | FULLTEXT MySQL index on knowledge_items.title + content for call-time keyword search |
| View | resources/views/knowledge/index.blade.php |
How AI Injection Works
Call comes in for tenant
↓
KnowledgeService::buildAiContext($tenant, $callerSpeech)
↓
1. FULLTEXT search: match knowledge_items against caller's words
2. Fallback: return highest-priority active items if no FULLTEXT match
3. Select up to 8 items, sorted by priority DESC
4. Truncate total to 3000 characters
5. Format as structured text block
↓
Injected into ConversationEngine system prompt as "KNOWLEDGE BASE" section
Priority System
Each knowledge item has a priority (1–100). Higher priority items are injected first when space is limited. Use priority to ensure critical SOPs or pricing information always makes it into the AI context.
URL Scraper
Tenants can paste any URL (their website's About, Services, or FAQ page) and KaiVox will:
- Fetch the page via Guzzle
- Strip HTML tags with
strip_tags() - Extract the readable text
- Pre-fill the Add Item modal with the extracted content
- Tenant reviews and saves
File Upload
Supported file types: .txt, .md, .csv, .pdf (basic text extraction). The file content is extracted and pre-fills the Add Item modal for tenant review before saving.
AI Preview
The AI Preview feature shows exactly what text will be injected into the system prompt for the next call. It displays the formatted KNOWLEDGE BASE section with a character count and estimated token count — helping tenants understand the AI's context window usage.
What's Complete
- All 6 knowledge categories with CRUD and active/inactive toggle
- Priority system — higher priority items injected first
- FULLTEXT MySQL index for call-time keyword matching
- URL scraper (Guzzle-based, strip_tags HTML → pre-fills modal)
- File upload (.txt/.md/.csv/.pdf basic extraction)
- KnowledgeService::buildAiContext() wired into ConversationEngine
- AI Preview endpoint showing exact injected text with char/token count
- Category filter sidebar, inline edit, search on knowledge dashboard
- Stats cards (total items, active items, by category)
- FAQ items from Knowledge Brain displayed on public profile (Phase 18)
What's Deferred
- RAG / vector embeddings (pgvector or Chroma — needs self-hosted infra)
- Dynamic website sync (auto re-scrape on schedule)
- Branch-level knowledge (per-location overrides)
- Cross-channel context sync (same Knowledge Brain answers calls + WhatsApp + chat)