<?php

declare(strict_types=1);

namespace App\Config;

final class NdjsonHybridRetrieverConfig
{
    /**
     * Maximum number of chunks the retriever may finally hand to the model.
     *
     * Rationale:
     * - enough room for the stronger hybrid pipeline
     * - still conservative enough to avoid prompt bloat
     */
    public const HARD_MAX_CHUNKS = 6;

    /**
     * Hard upper bound for vector retrieval candidate size.
     *
     * Rationale:
     * - the pipeline now combines primary vector, secondary vector,
     *   lexical, scoped retrieval and re-ranking
     * - the old limit would constrain recall too early
     * - still capped to keep latency controlled
     */
    public const HARD_MAX_VECTORK = 18;

    /**
     * Default semantic score threshold for vector hits.
     *
     * Rationale:
     * - slightly relaxed compared to stricter pure-vector setups
     * - the system now has more safeguards:
     *   lexical cross-signals, scoped retrieval, title/meta boost, selection rules
     */
    public const VECTOR_SCORE_THRESHOLD = 0.83;

    /**
     * Lower safety boundary for dynamic threshold adjustments.
     *
     * Rationale:
     * - prevents the system from getting too noisy in fallback cases
     * - still allows recovery when exact signals are sparse
     */
    public const THRESHOLD_FLOOR = 0.75;

    /**
     * Upper safety boundary for dynamic threshold adjustments.
     *
     * Rationale:
     * - protects objection/pricing/list adjustments from becoming too strict
     * - keeps retrieval from collapsing into empty result sets too easily
     */
    public const THRESHOLD_CEIL = 0.90;

    /**
     * Additional candidate expansion factor for list-like prompts.
     *
     * Rationale:
     * - list requests benefit from wider candidate recall
     * - too high would create noise across multiple retrieval channels
     */
    public const LIST_BONUS = 1.35;

    /**
     * Reciprocal Rank Fusion constant.
     *
     * Rationale:
     * - keep rank importance meaningful
     * - but not so aggressive that one retrieval source dominates too hard
     */
    public const RRF_K = 50;

    /**
     * Fallback size when thresholded fusion yields no candidates.
     *
     * Rationale:
     * - slightly larger safety net for the richer hybrid stack
     * - helps no-tag and low-signal cases without exploding context
     */
    public const EMPTY_RRF_FALLBACK_TOPN = 5;

    /**
     * Maximum number of chunks allowed from one document in spread mode.
     *
     * Rationale:
     * - preserve diversity across documents
     * - still allow coherent multi-chunk retrieval from strong sources
     */
    public const MAX_CHUNKS_PER_DOC = 2;

    /**
     * Minimum distance between chunk indices from the same document
     * during spread-style selection.
     *
     * Rationale:
     * - reduce near-duplicate neighboring chunks
     * - still allow relevant continuation when needed
     */
    public const MIN_CHUNK_DISTANCE = 2;

    /**
     * When one document clearly dominates the top-ranked window,
     * temporarily switch from "spread" mode to "dominant document" mode.
     */
    public const DOMINANT_DOC_WINDOW = 6;
    public const DOMINANT_DOC_MIN_HITS = 3;
    public const DOMINANT_DOC_MAX_CHUNKS = 4;
    public const EXACT_DOCUMENT_MAX_CHUNKS = 6;
    public const FOCUSED_PRODUCT_WINDOW = 8;
    public const FOCUSED_PRODUCT_MIN_SCORE = 10.0;
    public const FOCUSED_PRODUCT_MIN_GAP = 4.0;
    public const FOCUSED_PRODUCT_MAX_CHUNKS = 4;

    public const GENERIC_PRODUCT_TOKEN = [
        'produkt', 'produkte', 'produktkarte', 'titel', 'geraet', 'gerät',
        'messgeraet', 'messgerät', 'wasser', 'haerte', 'härte', 'resthaerte',
        'resthärte', 'analyse', 'analysator', 'automat', 'online', 'messung',
        'messen', 'preis', 'preise', 'kosten', 'info', 'infos', 'passend',
        'richtige', 'richtiges', 'geeignet', 'geeignete', 'welche', 'welcher',
        'welches', 'brauche', 'suche'
    ];

    const IMPORTANT_SHORT_MODEL_TOKEN = ['th', 'tc', 'tp', 'tm', 'ph', 'rx'];

    const FAMILY_DESCRIPTOR_TOKEN = [
        'evo', 'eco', 'self', 'clean', 'mini', 'pro', 'plus', 'basic', 'lab',
        'inline', 'compact', 'panel', 'sc',
    ];

    const LOOKS_LIKE_REAGENT_TOKENS = [
        'indikator', 'reagenz', 'reagens', 'laborchemikalie', 'chemikalie',
        'sicherheitsdatenblatt', 'sdb', 'msds', 'ufi', 'gebinde', 'flasche',
        'ersatzteil', 'zubehoer', 'zubehör', 'service set', 'filtereinsatz',
        'kerzenfilter', 'druckregler',
    ];

    const LOOKS_LIKE_SAFETY_DOCS = [
        'sicherheitsdatenblatt', 'sdb', 'msds', 'gefahrenbewertung',
        'gefahrenpiktogramm', 'signalwort', 'lagerung', 'transport', 'clp',
        'kennzeichnung', 'h290', 'pbt', 'vpvb',
    ];

    public const LOOKS_LIKE_REAGENT_WORDS = [
        'indikator', 'reagenz', 'reagens', 'chemie', 'chemikalie', 'sdb',
        'sicherheitsdatenblatt', 'msds', 'flasche', 'gebinde',
    ];

    public const LOOKS_LIKE_DOCUMENT_WORDS = [
        'datenblatt', 'dokument', 'pdf', 'handbuch', 'manual', 'beschreibung',
        'sdb', 'sicherheitsdatenblatt', 'msds',
    ];

    public const LOOKS_LIKE_SAFETY_WORDS = [
        'gefahr', 'gefahrgut', 'clp', 'h290', 'sicherheit', 'kennzeichnung',
        'transport', 'lagerung', 'piktogramm',
    ];

    public const LOOKS_LIKE_DEVICE_WORDS = [
        'geraet', 'gerät', 'messgeraet', 'messgerät', 'analysator', 'automat',
        'messung', 'messen', 'ueberwachung', 'überwachung', 'online', 'monitor',
    ];

}