Architecture
Key design choices
- Layered hybrid retrieval: A/B/C historical text, D
history_imagesdescriptions and runtimelive_messagesform five vector recall paths. HybridRetriever runs these concurrently and reads Recent Live. Outer Layer A runs retrieval, relationship context and Life decisions in parallel. - Optional cross-encoder ranking:
CROSS_RERANK_ENABLED=trueapplies a dedicated model (for examplexop3qwen8brerankerorqwen3-rerank) after RRF, before the main prompt. Relevance and latency depend on provider/model; do not assume a universal timing guarantee. - Optional Query Rewrite: A small model expands short colloquial queries into up to three retrieval variants. Hits merge by
(best_rank, distance)to reduce sparse recall. - Optional adaptive chunking:
CHUNKING_STRATEGY=adaptiveuses topic boundaries through heuristics and an optional small model instead of only fixed 12-message windows. Session concurrency is configurable; runtime depends on corpus and model. - Multiple reply bubbles: Double newlines in one assistant response allow the frontend to display multiple bubbles with separate avatars/timestamps and staggered timing. The API still returns one assistant message. Third-party clients implement splitting if wanted.
- Three weighting layers: Recency boost (capped at 15%), warmth weighting and source trust distinguish recent/live/history material.
- Memory source separation:
user_newrecords user facts;ai_generatedsupports continuity at low weight and does not enter persona/style distillation. Long-term imitation evidence comes fromhuman_originalhistory. - Controllable AI accumulation:
AI_GENERATED_LONG_TERM_ENABLED=falserestricts AI semantic memory to the same conversation by default. Enabling it allows low-weight cross-conversation retrieval and potential drift. - Growing memory: Turns are asynchronously written to
live_messages; storage is not a one-time snapshot. - Per-turn response policy: Rules choose serious, comforting, playful, redirecting, silent, image or sticker behavior, and avoid escalating distress. Optional
RESPONSE_POLICY_MODEL_ENABLEDrefinement is bounded: it cannot lower risk or undo protected rule decisions. - Silence and delayed display: A no-reply policy bypasses the main model and returns
finish_reason="silenced", the sentinel andpolicy.should_reply=false. Clients applypolicy.reply_delay_seconds; the backend does not block for presentation delays. - Three independent offline paths:
xuwen importbuilds vectors and persona/style/circadian/lightweight proactive profiles;xuwen analyzeexplicitly builds timeline/personality/Life/experimental reports;xuwen analyze-proactiveindependently computes proactive statistics and optional AI motive attribution. Ordinary import/analysis does not trigger proactive attribution. - Opt-in report consumption: Timeline is display-only. Personality enters the prompt only with
ANALYSIS_PERSONALITY_PROMPT_ENABLED=true; Life habits requireANALYSIS_LIFE_CONTEXT_ENABLED=true. - Experimental proactive learning: Disabled and not recommended by default. Scheduling prefers independent
proactive_analysis.json, falls back to import-timeproactive_profile.json, then stored windows. Quality checks are read-only, with no AI calls or automatic enablement. Polling rechecks disturbance gates and chooses topic hooks from memory, relationship context and recent cache. - Real time and Life state: Each model call receives current time in the configured zone. A small model maintains daily state for questions about activities, food or sleep. Failed calls write a minimal fallback state to avoid repeated update loops.
- Optional web access: Tavily or SearXNG adds public current information when explicitly requested; disabled by default.
- Large-table indexing:
uv run python -m xuwen.ingestion.cli index --language encreates LanceDB IVF_PQ indexes.cli optimizemerges incremental data. Benefits depend on table size and workload. - No fine-tuning: RAG, prompts and persona cards supply context without modifying model weights.
- Letter-inspired UI: Warm paper, dark blue ink, serif typography, ambient particles, human-paced typing and memory-source overlays.