Self-hostable AI backend for document Q&A — runs fully local with Ollama, or plug in OpenAI / Gemini API keys. Switch providers at runtime, no code changes.
AIHub gives you a complete RAG (Retrieval-Augmented Generation) stack you can run on your own machine: ingest documents, search them semantically, chat with sources, and link directories that auto-sync as files change. Designed for teams that want the convenience of a hosted AI assistant without sending their documents to a third party.
- Local-first — defaults to Ollama, no API keys needed
- Bring Your Own Model (BYOM) — swap in OpenAI or Gemini per request
- Full RAG pipeline — parsing, chunking, embeddings, vector search, answer synthesis with source attribution
- Persistent chat sessions — multi-turn conversations with history
- Directory linking — point at a folder, files are auto-ingested as they change
- Interactive CLI — drive everything from the terminal without writing curl by hand
- Encrypted credentials — provider API keys are encrypted at rest
For a deep dive on the design, see ARCHITECTURE.md.
Node.js · TypeScript · Fastify · PostgreSQL (Drizzle ORM) · Redis (BullMQ) · Qdrant · Ollama / OpenAI / Gemini
Client → Fastify API → Provider Registry → Ollama / OpenAI / Gemini
→ BullMQ Queue → Ingestion Worker → Qdrant
→ RAG Engine → Qdrant + AI Provider
→ Chat Manager → History + RAG + AI Provider
docker compose up -dThis starts PostgreSQL, Redis, Qdrant, and Ollama.
docker exec aihub-ollama ollama pull llama3.2
docker exec aihub-ollama ollama pull nomic-embed-textcp .env.example .env
# Generate an encryption key and paste it into .env:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
npm install
npm run db:push
npm run devServer starts at http://localhost:3001.
npm run cliInteractive menu for ingesting files, querying, chatting, and managing providers — no curl required.
# Ingest a document
curl -X POST http://localhost:3001/api/ingest \
-F 'file=@./my-document.pdf'
# Query
curl -X POST http://localhost:3001/api/query \
-H 'Content-Type: application/json' \
-d '{"query":"What is this document about?"}'The CLI (npm run cli) wraps the HTTP API in an interactive menu:
- Link directory — point at a folder and auto-ingest everything in it
- Upload files — pick files to ingest individually
- Query — single-shot RAG question
- Chat — multi-turn conversation with history
- Sources — list and manage ingested documents
- Providers — configure Ollama / OpenAI / Gemini at runtime
Ollama is used by default. To switch to a cloud provider at runtime:
curl -X POST http://localhost:3001/api/providers/config \
-H 'Content-Type: application/json' \
-d '{"providerType":"openai","capability":"generation","apiKey":"sk-...","isActive":true}'curl -X POST http://localhost:3001/api/providers/config \
-H 'Content-Type: application/json' \
-d '{"providerType":"gemini","capability":"generation","apiKey":"AI...","isActive":true}'API keys are encrypted with AES-256-GCM before being written to Postgres, using the ENCRYPTION_KEY from your env.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health |
Health check |
| POST | /api/ingest |
Upload a document (multipart) |
| POST | /api/query |
Single-shot RAG query |
| GET | /api/sources |
List ingested documents |
| GET | /api/sources/:id |
Get document details |
| DELETE | /api/sources/:id |
Delete document + vectors |
| POST | /api/directories/link |
Link a directory for ingestion |
| GET | /api/directories |
List linked directories |
| POST | /api/directories/:id/sync |
Re-sync a directory |
| DELETE | /api/directories/:id |
Unlink directory |
| POST | /api/chat |
Create chat session |
| POST | /api/chat/:id/message |
Send chat message |
| GET | /api/chat/:id/history |
Get chat history |
| GET | /api/chat |
List chat sessions |
| DELETE | /api/chat/:id |
Delete chat session |
| POST | /api/providers/config |
Configure AI provider |
| GET | /api/providers |
List provider configs |
| DELETE | /api/providers/:id |
Delete provider config |
| Variable | Default | Description |
|---|---|---|
PORT |
3001 |
Server port |
DATABASE_URL |
postgresql://...localhost:5433/aihub |
PostgreSQL connection |
REDIS_URL |
redis://localhost:6380 |
Redis connection |
QDRANT_URL |
http://localhost:6333 |
Qdrant connection |
OLLAMA_URL |
http://localhost:11434 |
Ollama connection |
ENCRYPTION_KEY |
(required) | 32-byte hex key for encrypting provider API keys at rest |
MIT — see LICENSE.