v1.0 Dashboard Public Profile GitHub
✅ Complete (Core) Phase 11

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

CategoryUse CaseExample
faqFrequently asked caller questions"Do you accept walk-ins?" → "Yes, we accept walk-ins Mon-Fri before 5pm."
pricingService prices, consultation fees"Consultation: ₹500, Ultrasound: ₹800"
sopStandard operating procedures for staff/AI"If caller reports chest pain, immediately escalate to emergency."
policyBusiness policies (cancellation, payment, etc.)"Cancellations must be made 2 hours in advance."
promotionCurrent offers and promotions"20% off all dental cleanings in January."
generalBusiness info, location, parking, etc."Free parking available at basement level."

Key Routes

URLDescription
GET /knowledgeKnowledge Brain dashboard with stats, category filter, search
POST /knowledgeCreate new knowledge item
PUT /knowledge/{id}Update item (inline edit)
DELETE /knowledge/{id}Delete item
POST /knowledge/{id}/toggleToggle active/inactive
POST /knowledge/scrape-urlScrape a URL and pre-fill the Add modal
POST /knowledge/upload-fileUpload .txt/.md/.csv/.pdf and extract content
GET /knowledge/ai-previewShow exact text that would be injected into AI with char/token count

Key Files

TypePath
Serviceapp/Services/KnowledgeService.php — buildAiContext(), keyword search
Controllerapp/Http/Controllers/KnowledgeController.php
Modelapp/Models/KnowledgeItem.php
Tableknowledge_items — tenant_id, category, title, content, priority, is_active, source (manual/scraped/uploaded)
IndexFULLTEXT MySQL index on knowledge_items.title + content for call-time keyword search
Viewresources/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:

  1. Fetch the page via Guzzle
  2. Strip HTML tags with strip_tags()
  3. Extract the readable text
  4. Pre-fill the Add Item modal with the extracted content
  5. 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)