Xilin Zhu
ContactAvailable for work
← AI Digital Twin

AI Digital Twin

Architecture

FastAPI, an embeddable chat interface, and a persistent RAG knowledge base

The browser carries conversation history; a local database stores documents and searchable evidence. The public agent combines an approved persona with explicitly published material and answers through DeepSeek.

From question to answer

Personal website / Web Component
                 │ JSON or SSE over HTTPS
                 ▼
Tailscale Funnel → public FastAPI service
                 │
                 ├── approved persona: identity and speaking style
                 ├── public knowledge mirror: current published passages
                 └── provider adapter → DeepSeek
                 │
                 ▼
Answer + citations → expandable source passages on the website

FastAPI validates the request and prepares the same evidence for JSON and streaming replies. The persona defines who the agent represents and how it speaks; the knowledge base supplies changing project facts. Semantic similarity, keyword matching, and evidence selection find relevant passages before the model writes its answer.

The provider adapter keeps model access separate from the frontend contract. It handles cancellation, retries, and rate limiting. Local llama.cpp inference uses the same interface for private trials; DeepSeek serves public answers.

From upload to searchable material

Local management page
        │ drag in MD / TXT / PDF / DOCX
        ▼
Background worker → text extraction → passages + source locations
        │
        ├── original files + persistent private document index
        └── explicit publication → separate public mirror

The management page identifies basic metadata automatically. The worker extracts text, records page, paragraph, and table locations, and generates multilingual embeddings locally with FastEmbed. A PostgreSQL-compatible database with pgvector stores the passages and vectors alongside document versions and processing state.

Completed uploads become the current version automatically; a failed replacement preserves the previous version. Private preview uses the owner’s permitted documents; visitors can retrieve only current published versions in the public mirror. Replacement, withdrawal, and deletion update availability without rebuilding the website. Processing jobs support retries and recovery after interruption.

Citation access is checked against current permissions. Sources expose the authorised passages; original files remain in local storage.

Deployment topology

The static website is hosted on Render under my own domain. FastAPI, the background worker, original files, and the persistent databases run on my Windows computer. Tailscale Funnel supplies the public HTTPS connection to the visitor service; the management interface stays local.

The services start after Windows login without a visible console window. Closing the management browser leaves them running. The computer must stay awake and connected for knowledge-base answers; the static portfolio remains independently available.

The infrastructure and local embeddings use free resources. DeepSeek is billed by API usage, with output and request limits to control spending. Cold backups include the original files and indexes; recovery has been checked in an isolated database.

Decisions carried forward from the original agent

  • Conversation history stays in the browser. Requests carry recent turns; the backend does not keep long-term chat sessions. Documents, indexes, versions, and processing state are persistent.
  • An embeddable frontend. A native Custom Element and Shadow DOM isolate the widget’s styles. Professional and casual histories are separate, with Chinese, English, and German support.
  • Shared reply preparation. JSON and SSE use the same evidence path and citations. Cancellation, retry, and interrupted-stream recovery keep the interface usable.
  • Useful operating metrics. Anonymous structured metrics track latency, failures, and token usage without recording raw conversations. Rendering protection, approved-origin CORS, and readiness checks remain part of the service.
  • A separate container path. The original Docker deployment remains available, built from a lockfile with a non-root runtime and graceful shutdown. The current persistent RAG service runs locally.