The multi-query vector search with blocking urllib.request.urlopen calls was stalling the single-threaded uvicorn event loop. Now uses async httpx.AsyncClient with asyncio.gather for parallel requests. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ce8d4a79a0
·
2026-06-03 11:51:48 +00:00
6 Commits
Zportal Wiki VectorDB Chat
Multi-provider AI chat with RAG (Wiki KB + VectorDB) for the Z.ai portal.
Architecture
| Component | Port | File | Purpose |
|---|---|---|---|
| wiki-vector-chat | 8770 | wiki-vector-chat.py |
FastAPI chat backend — multi-provider LLM, RAG pipeline, SSE streaming |
| wiki-api | 8097 | wiki-api.py |
KB keyword search over wiki-kb.json (1,301 Q&A entries) |
| vector-db-service | 8099 | vector-db-service.py |
TF-IDF vector search on Discord/Reddit messages |
| Frontend | static | zportal-chat.html |
Odysseus-style chat UI at /zportal/chat |
| wiki-chat-server | 8098 | wiki-chat-server.py |
Legacy Z.ai GLM-4 proxy (being replaced) |
| wiki-chat-proxy | — | wiki-chat-proxy.py |
Legacy chat proxy helper |
Features
- Multi-provider LLM — OpenAI, Anthropic, Ollama, OpenRouter, Groq, custom endpoints
- RAG pipeline — Dual-source context from Wiki KB + VectorDB with per-session toggles
- Chat modes — Chat, Code, Brainstorm with mode-specific system prompts
- Session history — localStorage persistence, switch between sessions, auto-save
- Save to Wiki — Save AI answers as new Q&A entries in the Wiki KB
- Message actions — Copy, Redo, Save-to-Wiki buttons on AI responses
- Markdown rendering — Bold, italic, code blocks, lists in AI replies
- SSE streaming — Server-Sent Events for real-time token streaming
- Provider management — CRUD for custom providers, preset forking with API keys
- Odysseus UI — Tokyo Night palette, sidebar, chat bubbles, model picker
Provider Presets
| ID | Name | Format |
|---|---|---|
| zai-coding | Z.ai Coding Plan | OpenAI |
| openadapter | OpenAdapter | OpenAI |
| openrouter | OpenRouter | OpenRouter |
| crofai | Crof.AI | OpenAI |
| opencode-zen | Opencode Zen | OpenAI |
Nginx Config
location = /zportal/chat {
default_type text/html;
alias /opt/zportal/chat.html;
}
location ^~ /zportal/wiki/api/chat/ {
proxy_pass http://127.0.0.1:8770/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 120s;
}
Systemd
sudo systemctl restart wiki-vector-chat
sudo systemctl status wiki-vector-chat
API Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /chat/message |
Main chat (SSE stream) |
| POST | /chat/tunnel |
Server-side token chat |
| POST | /chat/save-to-wiki |
Save Q&A to wiki KB |
| GET | /providers |
List all providers |
| GET | /providers/presets |
Built-in presets |
| POST | /providers/save |
Save/edit custom provider |
| DELETE | /providers/{id} |
Remove custom provider |
| GET | /health |
Health check |
Description
Multi-provider AI chat with RAG (Wiki KB + VectorDB) for Z.ai portal. FastAPI backend with Odysseus-style UI.
Languages
HTML
54.2%
Python
45.8%