Knowledge Assistant is an advanced serverless RAG (Retrieval-Augmented Generation) engine designed for personal or team intelligence management. It bypasses the common limitations of purely semantic search by employing a Smart Hybrid Retrieval strategy, ensuring 100% precision for critical facts while maintaining deep semantic discovery.
- Runtime: Cloudflare Workers (Hono)
- Database: Cloudflare D1 (Serverless SQL)
- Object Storage: Cloudflare R2 (For raw document persistence)
- Vector Search: Cloudflare Vectorize (Neural search index)
- Background Jobs: Cloudflare Workflows (Durable indexing pipeline)
- AI Models:
@cf/baai/bge-base-en-v1.5(Embeddings) & Google Gemini/DeepSeek (LLM)
The routing engine automatically chooses the most accurate retrieval method based on your query:
- Direct Date Scan: 100% accurate lookups for specific dates (e.g., "NAV on 01/01/2025") via raw R2 text scanning.
- Year Range Scan: Complete extraction of all records within a specific year for performance analysis.
- Semantic Search: Deep discovery for open-ended questions using neural vector reranking.
Upload or edit documents in a beautiful dark-mode Knowledge Hub. The system handles indexing in the background using Cloudflare Workflows, ensuring that even massive documents are vectorized reliably without blocking the UI.
Maintains high search relevance with built-in maintenance tools:
- Orphan Detection: Scans and purges vectors from historically deleted documents.
- Tombstone Tracking: Ensures clean cleanup for every document delete action.
- Maintenance UI: One-click nuclear reset and re-indexing capability.
- MFA Required: Secure dashboard login with TOTP (Google Authenticator) support.
- Secret Management: Built-in protection against credential leaks in source code.
- Access Control: Hardened middleware ensuring only your
ALLOWED_USER_IDcan access the intelligence hub.
Designed for developers who value performance without the overhead.
- Infrastructure ($0): Runs entirely on Cloudflare's Free Tier (Workers, D1, R2, Vectorize, and Workflows). No monthly substrate fees.
- Intelligence (Cent-scale): Uses the DeepSeek API—one of the world's most cost-effective LLMs—providing high-reasoning capabilities at a fraction of the cost of other providers.
- Smart Retrieval: Reduces LLM token usage by employing a highly precise hybrid retrieval engine that only sends the most relevant data to the model.
- Wrangler CLI installed and authenticated.
- A Cloudflare account with D1, R2, and Vectorize enabled.
-
Clone & Install
git clone https://github.com/05ng/pi.git cd assistant-worker npm install -
Configure Local Environment Open the
assistant-workerdirectory and create your local secrets file:cp .dev.vars.example .dev.vars
Open
.dev.varsand fill in your actual API keys and secrets. -
Initialize Resources
npx wrangler d1 create mywiki-metadata-db npx wrangler r2 bucket create mywiki-kb npx wrangler vectorize create mywiki-vectors --dimensions=768 --metric=cosine
-
Configure Secrets Set up your production environment variables:
npx wrangler secret put DEEPSEEK_API_KEY npx wrangler secret put TELEGRAM_BOT_TOKEN npx wrangler secret put MFA_SECRET npx wrangler secret put JWT_SECRET npx wrangler secret put ALLOWED_USER_ID
-
Deploy
npm run deploy
Contributions are welcome! Please feel free to submit a Pull Request or open an issue for any bugs or feature requests.