Skip to content

AI Configuration

YapHub's AI behaviour is driven by a focused, hardcoded prompt optimised for generating concise Dutch-language summaries. Unlike the original plan for a full prompt template management system, the MVP uses a single proven prompt constant.

Current Implementation

The AI prompt is defined as a PHP constant in DigestConstants::HIGHLIGHT_SUMMARY_PROMPT:

Summarize the following content in 2-3 sentences (in Dutch).
If it's a link or short title, infer its context from the extracted text:

Title/Input: %s
URL: %s

Content:
%s

Three variables are injected via sprintf:

PositionVariableSource
%s (1)TitleKnowledge.title
%s (2)URLKnowledge.url
%s (3)ContentKnowledge.content (user text + extracted URL content)

Generation Parameters

ParameterValuePurpose
Temperature0.3Factual, consistent output
Max Tokens150Keeps summaries to 2-3 sentences
LanguageDutchImplicit in the prompt instruction
FallbackTruncate to 200 charsGraceful degradation on AI failure

Why a Hardcoded Prompt

During development, the prompt was iterated on until it produced reliable Dutch summaries. Since the system only generates one type of summary (a concise highlight), a single well-tuned prompt is simpler and more maintainable than a database-backed template system.

Benefits of this approach:

  • Zero configuration — no admin UI needed, works out of the box
  • Deterministic — same input always produces the same prompt
  • Easy to test — mock mode returns predictable results
  • No database dependency — the prompt doesn't require additional tables

Future Enhancements

The following improvements could be made post-MVP:

  • Configurable prompts — Move the prompt to a config file or environment variable for easy tweaking without code changes
  • Per-category prompts — Different categories could have specialised prompts (e.g., more technical for "DevOps" categories)
  • A/B testing — Compare prompt variations to optimise summary quality
  • Prompt template entity — Database-backed templates with versioning if the system needs to support multiple prompt types

The AiProviderInterface abstraction is already in place, so adding these features would require minimal architectural changes.

Generation flow

  1. During digest creation, KnowledgeHighlightGenerator::generateHighlight() checks if a knowledge item already has a highlight field (lazy — skip if present)
  2. If not, builds the prompt using sprintf(HIGHLIGHT_SUMMARY_PROMPT, title, url, content)
  3. Calls AiProviderInterface::generateCompletion(prompt, options)
  4. Stores the result in Knowledge.highlight (TEXT field)
  5. On failure, falls back to truncating the content to 200 characters

Storage

AI summaries are stored in two locations:

  1. Knowledge.highlight — Primary TEXT field on the knowledge entity
  2. Digest.knowledgeHighlights — JSON snapshot at digest generation time (immutable digest record)