Xilin Zhu
ContactAvailable for work
← All work

Personal project · Independent full-stack project

AI Digital Twin

A multilingual personal agent with a document knowledge base

2026.07 — PresentLive siteSource

A first-person AI twin that combines my approved profile with a document knowledge base: visitors can ask about my work, receive answers grounded in published material, and inspect the sources.

Evidence Recall@5 · fixed test set
98.8%
Correct facts and citations · answerable questions
97.6%
Fictional acceptance questions across three languages
54
Supported document formats
4
Supported languages
3
Offline backend tests passing
138

LiveWaking up

A first-person AI twin whose only source of truth is material I reviewed and approved myself.

Answers are generated by a language model from public material I approved. It can get things wrong — the CV and I are the authority.

Problem

A CV gives a fixed snapshot. Project reports, technical notes, and new work contain much more detail, but keeping every page and prompt in sync takes time.

I built an agent that visitors can ask directly, then added a RAG knowledge base so I can update its factual material by uploading documents. The agent retrieves relevant passages before answering and shows the evidence alongside its reply.

Approach

  • Backend — FastAPI provides the profile, JSON chat, and SSE streaming APIs. A provider adapter handles cancellation, retries, and rate limiting.
  • Frontend — a native Custom Element with Shadow DOM and zero runtime dependencies, embeddable with one script tag and one element; the homepage also has a compact chat interface.
  • Two personas, three languages — professional and casual conversations have separate histories, with Chinese, English, and German support and sessions stored per browser tab.
  • Document knowledge base — upload, private preview, publication, replacement, withdrawal, and deletion all feed the same retrieval and citation path.
  • Operations — anonymous request metrics track latency, failures, and token usage; output and request limits keep API spending predictable.

How the knowledge base works

Upload once, keep the agent up to date

Drag in an MD, TXT, PDF, or DOCX file, or paste text. The management page identifies basic metadata automatically and lets me correct it. A background worker extracts text, splits it into searchable passages, and keeps page, paragraph, or table locations for citations. Processing jobs support retries and recovery after interruption; completed uploads become the current version automatically.

Document updates require no changes to the persona, model retraining, or website rebuild. Scanned PDFs without extractable text prompt for OCR.

Retrieve evidence before generating an answer

Local FastEmbed produces multilingual embeddings. A persistent PostgreSQL-compatible database with pgvector combines semantic similarity and keyword matching, then selects relevant passages from the permitted current document versions.

The persona defines identity and speaking style; RAG supplies changing project facts. The public agent uses DeepSeek to turn retrieved evidence into a reply. Both JSON and streaming replies carry source citations, and the website lets visitors expand the cited passages. When the material does not support an answer, the agent says so.

Choose what visitors can read

Uploads default to private preview. Only documents I explicitly publish enter a separate public mirror. Replacing or withdrawing a document changes which version the public agent can retrieve, without rebuilding the website.

Key engineering decisions

Identity and changing facts have different homes. The persona supplies authoritative identity and education fields; the knowledge base supplies project details. A question about an undergraduate project’s algorithms reaches retrieval instead of an education template. Results from external papers retain their original authorship.

Versions and publication follow the whole path. A replacement becomes current only after processing succeeds, preserving the previous version if it fails. The public mirror synchronises explicitly published current material, and source access is checked again when a citation is opened.

JSON and streaming share their evidence. Both reply modes use the same retrieval preparation and source checks. The interface displays cited sources and supports stopping, retrying, and recovery after interrupted streams. Anonymous metrics record latency, error types, and token use without raw conversations.

Validation

The scores at the top of this page come from a fixed set of fictional Chinese, English, and German acceptance questions. Retrieval is scored against document version, source location, and text; answer scores come from manual review of DeepSeek replies. The latest retrieval regression did not regenerate the full set of answers.

  • Retrieval and answers — the evaluation covers factual answers with supporting citations, insufficient evidence, document permissions, identity, and conflicting versions.
  • Engineering checks — offline backend tests and separate database checks cover the supported formats, job retries, document versions, permissions, citations, and publication withdrawal.
  • Daily operation — a text PDF was timed from upload to automatic activation with a warmed worker. An actual cold backup was restored into an isolated database and checked for complete source files, passages, and vectors.

Running the system

The static website runs on Render. The API, background worker, and database run on my own computer, with Tailscale Funnel providing the HTTPS connection. The services start silently after Windows login; closing the management browser leaves them running. The computer needs to stay awake and connected for knowledge-base answers to be available.

This setup uses free infrastructure and local embeddings. DeepSeek answers are billed by API usage.

In progress

A local inference path using llama.cpp and quantised Qwen3-4B is working as a private trial. The public agent uses DeepSeek for its answer quality.

I am also training a small decoder-only GPT from scratch to work through the full training-to-serving pipeline. Training is in progress; quantised export and integration behind the same OpenAI-compatible interface are the next steps.