AI Assistant โ
HaloLight AI service is built with Hono + LangChain.js, providing RAG retrieval-augmented generation, action execution, and multi-model automatic fallback.
Live Preview: Internal API service (no standalone demo)
GitHub: https://github.com/halolight/halolight-ai
Tech Stack โ
| Technology | Version | Description |
|---|---|---|
| Hono | latest | Lightweight HTTP framework |
| LangChain.js | latest | LLM orchestration + RAG pipeline |
| pgvector | latest | PostgreSQL vector search extension |
| Drizzle ORM | latest | TypeScript ORM & migrations |
| PostgreSQL | 14+ | Persistence and vector storage |
| Node.js | 22+ | Runtime |
| Zod | latest | Data validation |
Directory Structure โ
halolight-ai/
โโโ src/
โ โโโ index.ts # Application entry
โ โโโ routes/ # API routes
โ โ โโโ chat.ts # Chat interface
โ โ โโโ actions.ts # Action execution
โ โ โโโ history.ts # History records
โ โ โโโ knowledge.ts # Knowledge base management
โ โโโ services/
โ โ โโโ llm/ # LLM service layer
โ โ โ โโโ openai.ts
โ โ โ โโโ anthropic.ts
โ โ โ โโโ factory.ts # Model factory (auto fallback)
โ โ โโโ rag/ # RAG pipeline
โ โ โ โโโ embeddings.ts # Document chunking & embedding
โ โ โ โโโ retriever.ts # Vector retrieval
โ โ โ โโโ pipeline.ts # RAG pipeline
โ โ โโโ actions/ # Action execution system
โ โ โ โโโ executor.ts # Action executor
โ โ โ โโโ registry.ts # Action registry
โ โ โ โโโ permissions.ts # Permission validation
โ โ โโโ memory/
โ โ โโโ conversation.ts # Conversation memory management
โ โโโ db/
โ โ โโโ schema.ts # Drizzle Schema (with pgvector)
โ โ โโโ client.ts # Database client
โ โโโ middleware/
โ โ โโโ auth.ts # Authentication middleware
โ โ โโโ tenant.ts # Tenant isolation
โ โโโ types/
โ โโโ index.ts # TypeScript type definitions
โโโ drizzle/ # Migration files
โโโ drizzle.config.ts
โโโ Dockerfile
โโโ docker-compose.yml
โโโ package.jsonQuick Start โ
Prerequisites โ
- Node.js >= 22.0.0
- PostgreSQL >= 14 (with pgvector extension)
- At least one LLM provider API Key configured
Installation โ
# Clone repository
git clone https://github.com/halolight/halolight-ai.git
cd halolight-ai
# Install dependencies
pnpm installEnvironment Variables โ
cp .env.example .envKey configurations:
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/halolight_ai
# LLM Providers (configure at least one)
OPENAI_API_KEY=sk-...
# or
ANTHROPIC_API_KEY=sk-ant-...
# or
AZURE_OPENAI_API_KEY=...
# RAG Configuration
CHUNK_SIZE=1000 # Document chunk size
CHUNK_OVERLAP=200 # Chunk overlap
RETRIEVAL_TOP_K=5 # Retrieval count
# Conversation Configuration
MAX_CONVERSATION_HISTORY=20 # Conversation history length
ENABLE_STREAMING=true # Enable streaming response
ENABLE_AUDIT_LOG=true # Enable audit logging
# Production
JWT_SECRET=your-secret-key
CORS_ORIGINS=https://your-domain.comInitialize Database โ
# Generate migration files
pnpm db:generate
# Run migrations
pnpm db:migrate
# Or push schema directly (development)
pnpm db:push
# Open Drizzle Studio
pnpm db:studioStart Development Server โ
pnpm devService will start at http://localhost:3000.
Production Build โ
pnpm build
pnpm startCore Features โ
1. Multi-Model Support โ
The system automatically detects available LLM providers and falls back by priority:
Azure OpenAI (1) โ OpenAI (2) โ Anthropic (3) โ Ollama (4)2. RAG Knowledge Base โ
| Step | Description | Configuration |
|---|---|---|
| Document Chunking | RecursiveCharacterTextSplitter | 1000 chars, 200 overlap |
| Vector Embedding | OpenAI Embeddings | text-embedding-3-small |
| Vector Storage | pgvector | 1536 dimensions |
| Retrieval | Cosine similarity | Top-K (default 5) |
| Context Injection | Inject retrieval results into LLM prompt | - |
3. Streaming Response โ
Enable SSE streaming output to reduce first-token latency:
POST /api/ai/chat/stream
Content-Type: application/json
{
"message": "Hello",
"streaming": true
}4. Permission Control โ
Role-based access control (RBAC):
| Role | Permission Level |
|---|---|
super_admin | Highest permission |
admin | Admin permission |
user | Regular user |
guest | Guest |
Sensitive operations require confirmation (_confirmed: true).
5. Conversation Memory โ
- Stored in
conversationsandmessagestables - Retains last 20 messages by default
- Supports multi-turn conversation context
6. Tenant Isolation โ
All data operations are based on TenantContext:
interface TenantContext {
tenantId: string;
userId: string;
role: UserRole;
}Extracted from request headers:
X-Tenant-IDX-User-IDX-User-Role
API Endpoints โ
Health Check โ
GET /health
GET /health/ready
GET /api/ai/infoChat โ
# Send message
POST /api/ai/chat
Content-Type: application/json
{
"message": "Hello, introduce HaloLight",
"conversationId": "uuid", // optional
"includeContext": true,
"maxContextDocs": 5
}
# Streaming response
POST /api/ai/chat/streamAction Execution โ
# Execute action
POST /api/ai/actions/execute
Content-Type: application/json
{
"action": "query_users",
"params": {
"role": "admin",
"limit": 10
}
}
# Get available actions
GET /api/ai/actions/available
# Get action details
GET /api/ai/actions/:nameHistory โ
GET /api/ai/history?limit=10
GET /api/ai/history/:id
DELETE /api/ai/history/:id
PATCH /api/ai/history/:idKnowledge Base โ
# Import document
POST /api/ai/knowledge/ingest
Content-Type: application/json
{
"content": "Document content...",
"metadata": {
"title": "Document Title",
"category": "Technical Documentation"
},
"source": "manual",
"sourceId": "doc-001"
}
# Batch import
POST /api/ai/knowledge/batch-ingest
# List documents
GET /api/ai/knowledge?limit=50&offset=0
# Delete document
DELETE /api/ai/knowledge/:idAuthentication โ
All /api/* endpoints require the following headers (optional in development):
X-Tenant-ID: your-tenant-id
X-User-ID: your-user-id
X-User-Role: admin | user | guestDeployment โ
Docker โ
# Build image
docker build -t halolight-ai .
# Run container
docker run -p 3000:3000 \
-e DATABASE_URL=postgresql://... \
-e OPENAI_API_KEY=sk-... \
halolight-aiDocker Compose โ
docker-compose up -dProduction Requirements โ
DATABASE_URL: PostgreSQL connection stringNODE_ENV=production- At least one LLM provider API Key
JWT_SECRET: Secret key for authenticationCORS_ORIGINS: Allowed cross-origin sources
Troubleshooting โ
Database Connection Failed โ
# Check if PostgreSQL is running
psql $DATABASE_URL -c "SELECT 1"
# Check pgvector extension
psql $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS vector"LLM Provider Errors โ
# Check available providers
curl http://localhost:3000/api/ai/infoInaccurate Vector Retrieval โ
- Increase
RETRIEVAL_TOP_Kvalue - Adjust
CHUNK_SIZEandCHUNK_OVERLAP - Use hybrid retrieval (vector + keyword)
Related Projects โ
- halolight - Next.js frontend
- halolight-vue - Vue frontend
- halolight-docs - Documentation