Hệ thống trí tuệ nhân tạo hoàn toàn offline cho mạng nội bộ công ty
LocalAIChatBox v6.0 là một hệ thống trí tuệ nhân tạo đa phương tiện (multimodal) được thiết kế để chạy 100% offline trên mạng nội bộ công ty. Hệ thống kết hợp:
- Multimodal RAG - Xử lý văn bản, hình ảnh, bảng biểu, slides (PDF, DOCX, XLSX, PPTX, images)
- LightRAG Integration - Query với 5 modes (naive, local, global, hybrid, mix)
- Knowledge Graph - Trích xuất và quản lý quan hệ thực thể tự động với ChromaDB
- Deep Research - Nghiên cứu sâu với 7 chiến lược tìm kiếm thông minh
- Enterprise Features - RBAC, LDAP/AD, Multi-tenancy, Encryption, Compliance
- Advanced Analytics - Theo dõi usage, export reports, audit logs
✅ Hoàn toàn Offline - Không cần kết nối Internet sau khi cài đặt ✅ Bảo mật Enterprise - RBAC, encryption at rest, LDAP integration, audit logging ✅ Đa phương tiện - Xử lý text, images, tables, presentations với vision models ✅ LightRAG Powered - Fast hybrid search với knowledge graph ✅ Dễ triển khai - Docker Compose với auto-init, health checks ✅ Mã nguồn mở - Tùy chỉnh theo nhu cầu doanh nghiệp ✅ Giao diện hiện đại - Dark mode, responsive, real-time progress tracking
Mạng nội bộ công ty (LAN)
├── Nginx (Port 81) - Reverse proxy với security headers
├── React Frontend (Port 3000) - Giao diện web (13 pages)
├── FastAPI Backend (Port 8001) - API server (Enhanced RAG + LightRAG)
├── PostgreSQL (Port 5432) - Cơ sở dữ liệu (RBAC, tenants, audit logs)
├── Ollama (Port 11434) - LLM Runtime (llama3.1, llama3.2:3b, llava, nomic-embed-text)
├── Ollama-Init - Auto-pull models on startup (exits after complete)
├── Data-Init - Fix permissions for mounted volumes (exits after complete)
├── SearXNG (Port 8080) - Meta search engine
├── ChromaDB Vector Store - Vector embeddings (text + multimodal chunks)
├── LightRAG Storage - Knowledge graph + embeddings
└── Multimodal Processing - Images, tables, presentations via vision models
8 services chạy trong Docker containers (6 persistent + 2 init containers), giao tiếp qua mạng Docker internal với health checks và dependencies.
- Đăng ký / Đăng nhập (Local + LDAP/AD)
- JWT authentication với token expiry
- RBAC (Role-Based Access Control) - Roles và permissions
- Multi-tenancy support - Phân tách dữ liệu theo tenant
- Audit logging - Theo dõi tất cả hành động
- Upload hỗ trợ: PDF, DOCX, TXT, MD, XLSX, PPTX, hình ảnh (PNG, JPG)
- Multimodal processing:
- Trích xuất text với pymupdf, python-docx, openpyxl, python-pptx
- Phân tích hình ảnh với vision model (llava)
- Phát hiện tables, equations, charts tự động
- Document versioning - Lưu trữ phiên bản
- Folders & Tags - Tổ chức tài liệu
- Per-document permissions - Phân quyền chi tiết (read/write/manage)
- Index vào ChromaDB (text chunks + multimodal chunks)
- Trích xuất entities vào Knowledge Graph
- Hybrid query modes:
naive: Simple vector searchlocal: Vector + local KG contextglobal: Vector + full KG contexthybrid: Combined vector + KG (recommended)
- Multimodal context: Tự động sử dụng nội dung images/tables khi trả lời
- Vision-enhanced answers: LLM có thể "nhìn" vào hình ảnh để trả lời
- Trích dẫn nguồn tự động (document + page)
- Lịch sử chat theo sessions (Conversation + ChatSession models)
- Token tracking & rate limiting
- 5 query modes:
naive: Không dùng graphlocal: Local graph contextglobal: Tòan cục graph contexthybrid: Kết hợp local + globalmix: Mix mode của LightRAG
- Streaming support: Real-time response streaming (NDJSON)
- Batch indexing: Xử lý nhiều documents cùng lúc
- Graph exploration: Xem entities, relationships, subgraphs
- Entity/Relation editing: Chỉnh sửa manual entities và relations
- Context-only mode: Lấy context không generate answer
- Dual KG system:
- NetworkX KG: Traditional entity extraction (7 types: PERSON, ORG, PROJECT, TECH, PRODUCT, LOCATION, CONCEPT)
- LightRAG KG: Advanced graph with embeddings
- Multi-hop reasoning: Tìm kiếm nhiều bước qua graph
- Multimodal entities: Entities có thể link đến images/tables
- KG Explorer UI: Search, filter, subgraph viewer
- Rebuild support: Xử lý lại tất cả documents (admin only)
- 7 chiến lược nghiên cứu:
source-based: Theo dõi nguồn chi tiết (mặc định)rapid: Tốc độ cao, single-passparallel: Tìm kiếm đồng thời đa querystandard: Cân bằng giữa tốc độ và độ sâuiterative: Lặp liên tục, tích lũy kiến thứcfocused-iteration: Tinh chỉnh thích ứngsmart: Tự động chọn chiến lược tốt nhất
- Progress tracking: Real-time progress UI
- Scheduled research: Lập lịch chạy tự động
- Notifications: Email/webhook khi research xong
- Report generation: Tạo báo cáo markdown chi tiết
- Research history: Lưu trữ và xem lại
- Usage Analytics Dashboard:
- Tổng quan tài nguyên (users, docs, queries, research)
- Daily activity charts
- Top users by action count
- Popular queries
- Document statistics
- Action breakdown
- Export features:
- Export chat history (JSON/CSV)
- Export research reports (Markdown/PDF)
- Export knowledge graph (JSON/GraphML)
- Export documents list (CSV)
- Quản lý người dùng (thêm/xóa/sửa, assign roles)
- Quản lý tenants (multi-tenancy)
- Thống kê hệ thống chi tiết
- Rebuild Knowledge Graphs (NetworkX + LightRAG)
- Cấu hình LDR settings (LLM, Search, Embedding)
- View audit logs & compliance reports
- Security settings (rate limits, token tracking)
- LDAP/Active Directory: SSO integration
- Encryption at rest: Sensitive data encryption
- Compliance: GDPR/HIPAA reports, data retention policies
- Rate limiting: Per-user/per-endpoint
- Security middleware: Headers, request validation, CORS
- Webhook integration: External system notifications
| Thành phần | Tối thiểu | Khuyến nghị |
|---|---|---|
| RAM | 16GB | 32GB |
| Disk | 50GB free | 100GB+ SSD |
| CPU | 4 cores | 8+ cores |
| GPU | Không bắt buộc | NVIDIA GPU (tăng tốc LLM) |
Dành cho môi trường production, chạy 24/7
Trên Ubuntu 22.04+ hoặc Debian 12+ server mới:
git clone https://github.com/your-username/LocalAIChatBox.git
cd LocalAIChatBox
chmod +x setup.sh && ./setup.shScript này sẽ tự động:
- Cài đặt Docker, Docker Compose, Git
- Tạo thư mục
data/,searxng/ - Tạo SECRET_KEY ngẫu nhiên
- Build và start 8 Docker services (6 persistent + 2 init containers)
- Auto-pull LLM models (llama3.1, llama3.2:3b, llava, nomic-embed-text) vào Ollama
- Kiểm tra health của tất cả services
Thời gian: ~20-40 phút (tùy tốc độ mạng khi download models ~10GB tổng)
Truy cập hệ thống tại: http://<server-ip>:81
Đăng nhập admin mặc định:
- Username:
admin - Password:
admin123
hostname -IVí dụ: 192.168.1.100
Các máy trong cùng mạng LAN truy cập: http://192.168.1.100:81
✅ CÓ THỂ chạy trên Windows 10/11! Sử dụng Docker Desktop + WSL2.
- Tải Docker Desktop: https://www.docker.com/products/docker-desktop/
- Cài đặt và khởi động Docker Desktop
- Kích hoạt WSL2 (Windows Subsystem for Linux 2):
- Mở PowerShell với quyền Admin:
wsl --install- Restart máy tính
- Mở Docker Desktop → Settings → General → Bật "Use the WSL 2 based engine"
Mở PowerShell hoặc Command Prompt:
git clone https://github.com/Khanhlinhdang/LocalAIChatBox.git
cd LocalAIChatBoxTạo file backend\.env với nội dung:
# Core
SECRET_KEY=your-secret-key-here-change-this-to-random-string
DATABASE_URL=postgresql://raguser:ragpassword@postgres:5432/ragdb
# Ollama
OLLAMA_HOST=http://ollama:11434
OLLAMA_LLM_MODEL=llama3.1
OLLAMA_VISION_MODEL=llava
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
# Embeddings
EMBEDDING_PROVIDER=sentence-transformers
EMBEDDING_MODEL=all-MiniLM-L6-v2
# Storage
VECTOR_STORE_PATH=/app/data/vector_store
DOCUMENTS_PATH=/app/data/documents
PARSER_OUTPUT_DIR=/app/data/parser_output
MAX_FILE_SIZE_MB=100
# Auth
ACCESS_TOKEN_EXPIRE_MINUTES=1440
# Search
SEARXNG_URL=http://searxng:8080
LDR_SEARCH_TOOL=searxng
LDR_SEARCH_ITERATIONS=3
LDR_QUESTIONS_PER_ITERATION=3
LDR_SEARCH_MAX_RESULTS=50
# LightRAG
LIGHTRAG_LLM_MODEL=llama3.2:3b
LIGHTRAG_WORKING_DIR=/app/data/lightrag_storage
LIGHTRAG_EMBED_MODEL=nomic-embed-text:latest
LIGHTRAG_CHUNK_SIZE=800
LIGHTRAG_CHUNK_OVERLAP=100
LIGHTRAG_LANGUAGE=Vietnamese
LIGHTRAG_NUM_CTX=2048
# Enterprise (Optional)
ENCRYPTION_KEY=
LDAP_ENABLED=false
LDAP_SERVER=ldap://localhost:389
LDAP_BASE_DN=dc=example,dc=com
# Notifications (Optional)
SMTP_ENABLED=false
SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASSWORD=
WEBHOOK_ENABLED=false
WEBHOOK_URL=Tạo SECRET_KEY ngẫu nhiên (PowerShell):
-join ((65..90) + (97..122) + (48..57) | Get-Random -Count 32 | % {[char]$_})
Copy kết quả vào `SECRET_KEY=...`
#### Bước 4: Tạo thư mục SearXNG config
```powershell
mkdir searxng
Tạo file searxng\settings.yml:
use_default_settings: true
general:
instance_name: "LocalAIChatBox Search"
server:
bind_address: "0.0.0.0:8080"
limiter: false
image_proxy: false
search:
safe_search: 0
autocomplete: ""
default_lang: "vi"
ui:
default_locale: "vi"
theme_args:
simple_style: darkdocker-compose up -d --buildLần đầu tiên sẽ mất ~20-40 phút để:
- Build images (~10 phút)
- Download LLM model llama3.1 (~4.7GB) vào container ollama
docker logs ragchat-ollama-initContainer ollama-init sẽ tự động pull các models: llama3.1, llama3.2:3b, llava, nomic-embed-text.
Đợi hoàn thành (tổng ~10GB). Container này sẽ exit khi xong.
Nếu cần pull thêm models:
docker exec -it ragchat-ollama ollama pull <model-name>docker-compose psollama-initvàdata-initsẽ có statusExited (0)(đã hoàn thành)- Các services còn lại phải có status
Uphoặchealthy
Mở trình duyệt:
- Trên máy Windows hiện tại: http://localhost:81
- Từ máy khác trong mạng LAN: http://<IP-của-máy-Windows>:81
Tìm IP của máy Windows:
ipconfigTìm dòng IPv4 Address của adapter mạng đang dùng (VD: 192.168.1.50)
Nếu bạn muốn kiểm soát từng bước:
Ubuntu/Debian:
sudo apt update
sudo apt install -y docker.io docker-compose git
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker $USERWindows: Cài Docker Desktop như hướng dẫn ở phần B.
git clone https://github.com/your-username/LocalAIChatBox.git
cd LocalAIChatBox- Tạo
backend/.env(xem template ở phần B bước 3) - Tạo
searxng/settings.yml(xem template ở phần B bước 4)
docker-compose up -d --builddocker exec -it ragchat-ollama ollama pull llama3.1docker-compose ps
curl http://localhost/api/healthTruy cập http://<server-ip>:81 → Đăng nhập với admin / admin123
Documents page → Upload Documents → Chọn file
Hỗ trợ định dạng: PDF, DOCX, TXT, MD, XLSX, PPTX, PNG, JPG
Hệ thống tự động:
- Parse text content (multimodal parser xử lý images, tables, charts)
- Tạo vector embeddings (ChromaDB)
- Index vào cả text collection và multimodal collection
- Vision model (llava) phân tích hình ảnh
- Trích xuất entities và relationships vào NetworkX Knowledge Graph
Chat page → Nhập câu hỏi
Query modes:
- Naive: Simple vector search
- Local: Vector + local KG context
- Global: Vector + global KG context
- Hybrid: Combined (khuyến nghị)
Toggle Use Knowledge Graph để bật/tắt KG enhancement.
Kết quả hiển thị:
- Câu trả lời (có thể kèm multimodal context từ images/tables)
- Nguồn trích dẫn (document + page)
- Entities liên quan
- Multimodal results count
LightRAG Query page → Nhập query → Chọn mode
5 modes:
- Naive: Không dùng graph
- Local: Local entities & relations
- Global: Global communities
- Hybrid: Kết hợp local + global (khuyến nghị)
- Mix: LightRAG mix mode
Features:
- Real-time streaming responses
- Context-only mode (xem context không generate answer)
- Top-K tuning
LightRAG Docs page:
- Upload documents vào LightRAG (batch processing)
- View indexed documents (status: pending/processing/completed/failed)
- Delete documents
- Batch indexing với progress tracking
Graph page (NetworkX KG):
- Xem thống kê (entities, relationships by type)
- Search entities
- Click vào entity để xem subgraph
- Admin: Rebuild graph
LightRAG Graph page:
- Browse entities & relations
- Edit entities/relations (admin)
- View graph statistics
- Rebuild LightRAG graph (admin)
Research page → Nhập research query → Chọn strategy → Start Research
Ví dụ query:
- "Phân tích chi tiết về kiến trúc microservices"
- "So sánh React vs Vue.js trong 2024"
- "Phân tích ưu nhược điểm của Kubernetes"
Theo dõi progress real-time → Xem findings → Generate Report để tạo báo cáo chi tiết
Scheduled Research: Lập lịch research tasks chạy định kỳ (với email/webhook notification)
Analytics page:
- Overview statistics (users, docs, queries, research)
- Daily activity charts (queries, uploads, research, logins)
- Top active users
- Popular queries
- Document statistics
- Action breakdown (query, upload, research, export, login)
Các trang hỗ trợ export:
- Chat: Export lịch sử chat (JSON/CSV)
- Research: Export report (Markdown/PDF)
- Graph: Export knowledge graph (JSON/GraphML)
- Documents: Export danh sách tài liệu (CSV)
Enterprise page:
- Tenants: Quản lý multi-tenancy
- Roles & Permissions: RBAC setup
- Audit Logs: Xem toàn bộ user actions
- Compliance Reports: GDPR/HIPAA compliance
Settings page → Chỉnh sửa:
- LLM: Provider, model, temperature, Ollama URL
- LightRAG: LLM model, chunk settings, language
- Search: Tool (searxng/duckduckgo/wikipedia), iterations, max results
- Embedding: Provider (sentence-transformers/ollama), model
- Security: Rate limits, token tracking
- LDAP: AD/LDAP integration settings
- Notifications: Email (SMTP) & Webhook config
→ Save Settings
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| POST | /api/auth/register |
- | Đăng ký user mới |
| POST | /api/auth/login |
- | Đăng nhập (trả về JWT token) |
| GET | /api/auth/me |
User | Lấy thông tin user hiện tại |
| PUT | /api/auth/password |
User | Đổi mật khẩu |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| POST | /api/chat/query |
User | Hỏi đáp RAG (body: {query, use_knowledge_graph, mode}) |
| GET | /api/chat/history |
User | Lấy lịch sử chat |
| DELETE | /api/chat/history |
User | Xóa lịch sử chat |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| POST | /api/documents/upload |
User | Upload tài liệu multimodal (form-data: files[]) - Hỗ trợ PDF, DOCX, XLSX, PPTX, images |
| GET | /api/documents/list |
User | Danh sách tài liệu |
| DELETE | /api/documents/{id} |
User | Xóa tài liệu |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/multimodal/info |
User | Thông tin multimodal processing config |
| GET | /api/multimodal/stats |
User | Thống kê multimodal chunks |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/knowledge-graph/stats |
User | Thống kê KG (entities, relationships, types) |
| GET | /api/knowledge-graph/entities |
User | Danh sách tất cả entities |
| GET | /api/knowledge-graph/search?q={name} |
User | Search entities theo tên |
| GET | /api/knowledge-graph/entity/{name}?hops=2 |
User | Lấy subgraph của entity (hops = độ sâu) |
| POST | /api/knowledge-graph/rebuild |
Admin | Rebuild KG từ tất cả documents |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| POST | /api/research/start |
User | Bắt đầu deep research (body: {query, strategy}) |
| GET | /api/research/{task_id}/progress |
User | Polling progress (status, %, message) |
| GET | /api/research/{task_id}/result |
User | Lấy kết quả (findings, sources) |
| POST | /api/research/{task_id}/report |
User | Tạo báo cáo markdown chi tiết |
| GET | /api/research/history?limit=20 |
User | Lịch sử research tasks |
| DELETE | /api/research/{task_id} |
User | Xóa research task |
| GET | /api/research/strategies |
User | Danh sách 7 strategies có sẵn |
| POST | /api/research/schedule |
User | Lập lịch research tự động |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/lightrag/health |
User | Kiểm tra trạng thái LightRAG service |
| POST | /api/lightrag/query |
User | Query với LightRAG (body: {query, mode, top_k}) - Modes: naive/local/global/hybrid/mix |
| POST | /api/lightrag/query/stream |
User | Streaming query (NDJSON format) |
| POST | /api/lightrag/query/context |
User | Query + trả về context |
| GET | /api/lightrag/documents |
User | Danh sách documents trong LightRAG |
| POST | /api/lightrag/documents/text |
User | Insert text vào LightRAG |
| POST | /api/lightrag/documents/file |
User | Upload file vào LightRAG |
| POST | /api/lightrag/documents/batch |
User | Batch insert files |
| DELETE | /api/lightrag/documents/{doc_id} |
User | Xóa document từ LightRAG |
| GET | /api/lightrag/graph/entities |
User | Danh sách entities trong LightRAG graph |
| GET | /api/lightrag/graph/relations |
User | Danh sách relations |
| POST | /api/lightrag/graph/entity/edit |
Admin | Chỉnh sửa entity |
| POST | /api/lightrag/graph/relation/edit |
Admin | Chỉnh sửa relation |
| POST | /api/lightrag/graph/rebuild |
Admin | Rebuild LightRAG graph |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/analytics/overview?days=30 |
User | Tổng quan usage statistics |
| GET | /api/analytics/daily?days=30 |
User | Daily activity data for charts |
| GET | /api/analytics/top-users?days=30 |
User | Top active users |
| GET | /api/analytics/popular-queries?days=30 |
User | Popular queries |
| GET | /api/analytics/document-stats |
User | Document statistics |
| POST | /api/export/chat |
User | Export chat history (JSON/CSV) |
| POST | /api/export/research/{task_id} |
User | Export research report (Markdown/PDF) |
| POST | /api/export/kg |
User | Export knowledge graph (JSON/GraphML) |
| POST | /api/export/documents |
User | Export documents list (CSV) |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/enterprise/tenants |
Admin | Danh sách tenants |
| POST | /api/enterprise/tenants |
Admin | Tạo tenant mới |
| PUT | /api/enterprise/tenants/{id} |
Admin | Cập nhật tenant |
| GET | /api/enterprise/roles |
Admin | Danh sách roles |
| POST | /api/enterprise/roles |
Admin | Tạo role mới |
| POST | /api/enterprise/roles/{id}/permissions |
Admin | Assign permissions |
| POST | /api/enterprise/users/{id}/roles |
Admin | Assign roles cho user |
| GET | /api/enterprise/audit-logs |
Admin | Xem audit logs |
| GET | /api/enterprise/compliance/report |
Admin | Tạo compliance report |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/settings/ldr |
Admin | Lấy tất cả LDR settings |
| PUT | /api/settings/ldr |
Admin | Cập nhật LDR settings (body: {settings: {...}}) |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/admin/stats |
Admin | Thống kê hệ thống |
| GET | /api/admin/users |
Admin | Danh sách users |
| PUT | /api/admin/users/{id} |
Admin | Cập nhật user (is_admin, is_active) |
| DELETE | /api/admin/users/{id} |
Admin | Xóa user |
| Method | Endpoint | Auth | Mô tả |
|---|---|---|---|
| GET | /api/health |
- | Health check (database, ollama, lightrag status) |
| GET | /api/search |
User | Unified search (documents + entities + multimodal) |
API Docs (Swagger): http://<server-ip>:81/docs
File: backend/.env
| Biến | Mô tả | Mặc định |
|---|---|---|
SECRET_KEY |
JWT secret key | Auto-generated |
DATABASE_URL |
PostgreSQL connection string | postgresql://raguser:ragpassword@postgres:5432/ragdb |
OLLAMA_HOST |
Ollama API URL | http://ollama:11434 |
OLLAMA_LLM_MODEL |
LLM model name | llama3.1 |
OLLAMA_VISION_MODEL |
Vision model cho multimodal | llava |
OLLAMA_EMBEDDING_MODEL |
Embedding model (nếu dùng Ollama) | nomic-embed-text |
EMBEDDING_PROVIDER |
sentence-transformers hoặc ollama |
sentence-transformers |
EMBEDDING_MODEL |
Model cho sentence-transformers | all-MiniLM-L6-v2 |
MAX_FILE_SIZE_MB |
Giới hạn upload file | 100 |
ACCESS_TOKEN_EXPIRE_MINUTES |
Token expiry | 1440 (24h) |
SEARXNG_URL |
SearXNG API URL | http://searxng:8080 |
LDR_SEARCH_TOOL |
Search tool cho LDR | searxng |
LDR_SEARCH_ITERATIONS |
Số vòng lặp search | 3 |
LDR_QUESTIONS_PER_ITERATION |
Số câu hỏi mỗi vòng lặp | 3 |
LDR_SEARCH_MAX_RESULTS |
Số kết quả tối đa mỗi search | 50 |
| LightRAG Settings | ||
LIGHTRAG_LLM_MODEL |
LLM model cho LightRAG | llama3.2:3b |
LIGHTRAG_WORKING_DIR |
Working directory cho LightRAG | /app/data/lightrag_storage |
LIGHTRAG_EMBED_MODEL |
Embedding model cho LightRAG | nomic-embed-text:latest |
LIGHTRAG_CHUNK_SIZE |
Chunk size | 800 |
LIGHTRAG_CHUNK_OVERLAP |
Chunk overlap | 100 |
LIGHTRAG_LANGUAGE |
Language | Vietnamese |
LIGHTRAG_NUM_CTX |
Context length | 2048 |
| Enterprise Settings | ||
ENCRYPTION_KEY |
Key cho encryption at rest | - |
LDAP_ENABLED |
Enable LDAP/AD authentication | false |
LDAP_SERVER |
LDAP server URL | ldap://localhost:389 |
LDAP_BASE_DN |
Base DN | dc=example,dc=com |
LDAP_BIND_DN |
Bind DN | - |
LDAP_BIND_PASSWORD |
Bind password | - |
LDAP_USE_SSL |
Use SSL | false |
LDAP_AUTO_CREATE_USERS |
Auto-create users từ LDAP | true |
| Notifications | ||
SMTP_ENABLED |
Enable email notifications | false |
SMTP_HOST |
SMTP server | - |
SMTP_PORT |
SMTP port | 587 |
SMTP_USER |
SMTP username | - |
SMTP_PASSWORD |
SMTP password | - |
SMTP_FROM |
From email | noreply@localchatbox.local |
WEBHOOK_ENABLED |
Enable webhooks | false |
WEBHOOK_URL |
Webhook URL | - |
WEBHOOK_SECRET |
Webhook secret | - |
LDR_SEARCH_MAX_RESULTS |
Số kết quả tối đa mỗi search | 50 |
Nếu server có GPU NVIDIA, bỏ comment trong docker-compose.yml:
ollama:
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]Yêu cầu: Cài đặt NVIDIA Container Toolkit trên host
# Ubuntu/Debian
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt update
sudo apt install -y nvidia-container-toolkit
sudo systemctl restart dockerRestart containers:
docker-compose down
docker-compose up -dDownload model khác từ Ollama:
# Xem danh sách model: https://ollama.com/library
docker exec -it ragchat-ollama ollama pull mistral
docker exec -it ragchat-ollama ollama pull phi3Cập nhật backend/.env:
OLLAMA_LLM_MODEL=mistralRestart backend:
docker-compose restart backendEdit searxng/settings.yml để thêm engines tùy chỉnh:
engines:
- name: company_wiki
engine: xpath
search_url: http://wiki.company.local/search?q={query}
url_xpath: //a[@class="result-link"]/@href
title_xpath: //a[@class="result-link"]/text()
content_xpath: //p[@class="snippet"]/text()
shortcut: cw
disabled: falseRestart SearXNG:
docker-compose restart searxng# Backup database
docker exec ragchat-postgres pg_dump -U raguser ragdb > backup_$(date +%Y%m%d).sql
# Backup vector store + documents
tar -czf data_backup_$(date +%Y%m%d).tar.gz data/# Restore database
cat backup_YYYYMMDD.sql | docker exec -i ragchat-postgres psql -U raguser -d ragdb
# Restore data
tar -xzf data_backup_YYYYMMDD.tar.gz# Xem logs tất cả services
docker-compose logs -f
# Xem logs của 1 service
docker-compose logs -f backend
# Restart services
docker-compose restart
# Stop tất cả
docker-compose down
# Stop và xóa volumes (XÓA DỮ LIỆU!)
docker-compose down -v
# Rebuild image
docker-compose build --no-cache backend
docker-compose up -d backend
# Xem status
docker-compose ps
# Xem tài nguyên sử dụng
docker stats# List models đã download
docker exec ragchat-ollama ollama list
# Pull model mới
docker exec ragchat-ollama ollama pull llama3.1
# Xóa model
docker exec ragchat-ollama ollama rm llama3.1
# Test model
docker exec -it ragchat-ollama ollama run llama3.1 "Hello"# Kết nối PostgreSQL CLI
docker exec -it ragchat-postgres psql -U raguser -d ragdb
# SQL commands:
\dt # List tables
\d users # Describe users table
\d tenants # Describe tenants table
SELECT COUNT(*) FROM users;
SELECT COUNT(*) FROM documents;
SELECT COUNT(*) FROM usage_logs;# Check ChromaDB collections
docker exec -it ragchat-backend python -c "
import chromadb
client = chromadb.PersistentClient(path='/app/data/vector_store')
print('Collections:', client.list_collections())
for col in client.list_collections():
print(f'{col.name}: {col.count()} items')
"
# Check LightRAG status
curl http://localhost:8001/api/lightrag/health | jq .
# LightRAG statistics
curl -H "Authorization: Bearer <token>" http://localhost:8001/api/lightrag/graph/entities | jq '.entities | length'\dt # List tables \d research_tasks # Describe table SELECT COUNT(*) FROM users;
### SearXNG
```bash
# Test SearXNG
curl "http://localhost:8080/search?q=test&format=json" | jq .
# Restart SearXNG
docker-compose restart searxng
Triệu chứng: docker-compose ps hiện backend status Restarting hoặc Exited
Kiểm tra logs:
docker-compose logs backendNguyên nhân thường gặp:
- PostgreSQL chưa ready → Đợi 30s và kiểm tra lại
.envfile thiếu hoặc sai format → Kiểm tra lại file- Port 8000 bị chiếm → Đổi port trong
docker-compose.yml
Triệu chứng: docker exec -it ragchat-ollama ollama pull llama3.1 bị lỗi
Kiểm tra:
docker logs ragchat-ollamaNguyên nhân:
- Không có kết nối Internet → Cần Internet để download model lần đầu
- Disk full → Kiểm tra
df -h - OOM (out of memory) → Tăng RAM hoặc swap
Giải pháp: Download model offline:
- Tải model từ https://ollama.com/library/llama3.1 trên máy khác
- Copy vào server:
scp llama3.1.gguf user@server:/tmp/ - Import:
docker exec ragchat-ollama ollama create llama3.1 -f /tmp/llama3.1.gguf
Triệu chứng: Trên trình duyệt, console hiển thị "Network Error"
Kiểm tra:
curl http://localhost/api/healthNguyên nhân:
- Nginx config sai → Xem logs:
docker-compose logs nginx - Backend chưa ready → Đợi backend start xong
- Firewall chặn port 80 → Mở port:
sudo ufw allow 80
Triệu chứng: Research task bị stuck ở "pending" hoặc "running" không tiến triển
Kiểm tra:
docker-compose logs backend | grep "research"Nguyên nhân:
- SearXNG không hoạt động → Test:
curl http://localhost:8080 - LLM model chưa download → Kiểm tra:
docker exec ragchat-ollama ollama list - Backend OOM → Kiểm tra:
docker stats
Giải pháp:
# Restart toàn bộ services
docker-compose restart
# Rebuild backend nếu code thay đổi
docker-compose build backend && docker-compose up -d backendTriệu chứng: Docker Desktop hiển thị "Starting..." mãi không xong
Giải pháp:
- Kiểm tra WSL2:
wsl --status - Nếu chưa cài:
wsl --install - Restart máy
- Bật Virtualization trong BIOS (Intel VT-x / AMD-V)
- Reinstall Docker Desktop
Triệu chứng: Trên máy Windows có thể truy cập http://localhost, nhưng từ máy khác không được
Windows Firewall:
# Mở PowerShell với quyền Admin
New-NetFirewallRule -DisplayName "LocalAIChatBox" -Direction Inbound -Protocol TCP -LocalPort 80 -Action AllowKiểm tra IP:
ipconfig
# Tìm IPv4 Address của adapter đang dùngTest từ máy khác:
ping <IP-của-máy-Windows>
curl http://<IP-của-máy-Windows>/api/health# Backend health
curl http://localhost/api/health
# Kết quả: {"status":"ok","services":{"database":"ok","ollama":"ok"}}
# Check all containers
docker-compose psdocker stats --no-streamTheo dõi:
- CPU%: Ollama thường 50-200% khi đang inference
- MEM USAGE: Backend ~2-4GB, Ollama ~4-8GB (tùy model)
- NET I/O: Kiểm tra traffic giữa containers
# Real-time logs
docker-compose logs -f --tail=100
# Filter by service
docker-compose logs -f backend
# Filter by keyword
docker-compose logs | grep ERRORAdmin password: Đăng nhập → User menu → Change Password
PostgreSQL password: Edit docker-compose.yml và backend/.env:
# docker-compose.yml
POSTGRES_PASSWORD: new-secure-password
# backend/.env
DATABASE_URL=postgresql://raguser:new-secure-password@postgres:5432/ragdbRestart:
docker-compose down
docker-compose up -d# Linux/Mac
openssl rand -hex 32
# Windows PowerShell
-join ((65..90) + (97..122) + (48..57) | Get-Random -Count 32 | % {[char]$_})Cập nhật vào backend/.env:
SECRET_KEY=your-new-32-char-random-string-hereNginx: Chỉ cho phép truy cập từ LAN
Edit nginx/nginx.conf:
server {
listen 80;
# Chỉ cho phép LAN
allow 192.168.0.0/16;
allow 10.0.0.0/8;
deny all;
# ... rest of config
}Restart: docker-compose restart nginx
Để enable HTTPS, thêm vào nginx/nginx.conf:
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
# ... rest of config
}Mount SSL certs:
# docker-compose.yml
nginx:
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx/ssl:/etc/nginx/ssl:roLocalAIChatBox/
├── backend/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI app v6.0 (includes multimodal, LightRAG, enterprise)
│ │ ├── models.py # SQLAlchemy models (User, Document, Conversation, ChatSession,
│ │ │ # ResearchTask, UsageLog, Tenant, Role, DocumentPermission, etc.)
│ │ ├── database.py # Database connection & init
│ │ ├── auth.py # JWT authentication, password hashing
│ │ ├── enhanced_rag_engine.py # ChromaDB + multimodal RAG engine
│ │ ├── document_processor.py # Basic document parsing
│ │ ├── knowledge_graph.py # NetworkX KG, entity extraction
│ │ ├── deep_research.py # DeepResearchService (LDR wrapper)
│ │ ├── ldr_settings.py # LDR settings adapter
│ │ ├── research_routes.py # Deep Research API endpoints
│ │ ├── lightrag_service.py # LightRAG service wrapper
│ │ ├── lightrag_routes.py # LightRAG API endpoints (query, documents, graph)
│ │ ├── enterprise_routes.py # Enterprise features API (tenants, roles, audit)
│ │ ├── analytics.py # Usage analytics & logging
│ │ ├── export_service.py # Export features (chat, reports, KG)
│ │ ├── security_middleware.py # Security headers, request validation
│ │ ├── rate_limiter.py # Rate limiting
│ │ ├── token_tracker.py # Token usage tracking
│ │ ├── rbac.py # Role-Based Access Control
│ │ ├── ldap_auth.py # LDAP/AD integration
│ │ ├── encryption.py # Data encryption service
│ │ ├── compliance.py # Compliance reports (GDPR, HIPAA)
│ │ ├── notification_service.py # Email/webhook notifications
│ │ ├── research_scheduler.py # Scheduled research tasks
│ │ ├── advanced_research.py # Advanced research features
│ │ ├── search_engines.py # Search engine implementations
│ │ ├── citation_handler.py # Citation tracking
│ │ ├── multimodal/ # Multimodal processing package
│ │ │ ├── __init__.py
│ │ │ ├── config.py # Multimodal config
│ │ │ ├── document_parser.py # Advanced multimodal parsing (PDF, DOCX, XLSX, PPTX, images)
│ │ │ ├── modal_processors.py # Image, table, equation processors
│ │ │ ├── query_engine.py # Multimodal query engine
│ │ │ ├── prompts.py # Multimodal prompts
│ │ │ └── utils.py # Multimodal utilities
│ │ └── lightrag/ # LightRAG package (vendored or symlink)
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Multi-stage build
│ └── .env # Environment variables
├── frontend/
│ ├── public/
│ │ └── index.html
│ ├── src/
│ │ ├── components/
│ │ │ └── Navbar.jsx
│ │ ├── pages/
│ │ │ ├── LoginPage.jsx
│ │ │ ├── RegisterPage.jsx
│ │ │ ├── ChatPage.jsx # Enhanced RAG chat UI (multimodal + KG)
│ │ │ ├── DocumentsPage.jsx # Document management (multimodal files)
│ │ │ ├── AdminPage.jsx # User & system management
│ │ │ ├── KnowledgeGraphPage.jsx # NetworkX KG explorer
│ │ │ ├── DeepResearchPage.jsx # Deep Research UI
│ │ │ ├── SettingsPage.jsx # LDR & system settings (admin)
│ │ │ ├── LightRAGQueryPage.jsx # LightRAG query interface (5 modes)
│ │ │ ├── LightRAGDocumentsPage.jsx # LightRAG document management
│ │ │ ├── LightRAGGraphPage.jsx # LightRAG graph explorer
│ │ │ ├── AnalyticsPage.jsx # Usage analytics dashboard
│ │ │ └── EnterprisePage.jsx # Enterprise features (tenants, roles, audit logs)
│ │ ├── api.js # Axios API client
│ │ ├── App.jsx # Main app, routes
│ │ ├── App.css # Global styles
│ │ └── index.js
│ ├── package.json
│ ├── Dockerfile # Nginx + React build
│ └── nginx.conf
├── nginx/
│ └── nginx.conf # Reverse proxy config (port 81)
├── searxng/
│ └── settings.yml # SearXNG config
├── data/
│ ├── documents/ # Uploaded files (all types)
│ ├── vector_store/ # ChromaDB persistent storage
│ ├── parser_output/ # Multimodal parsing outputs
│ ├── lightrag_storage/ # LightRAG working directory (KG + embeddings)
│ └── database/ # PostgreSQL data (Docker volume)
├── LightRAG-main/ # LightRAG library source (optional, for development)
├── local-deep-research-main/ # LDR library source (optional)
├── RAG-Anything-main/ # RAG-Anything inspiration (optional)
├── scripts/ # Utility scripts
├── docker-compose.yml # 8 services orchestration (6 persistent + 2 init)
├── .dockerignore
├── setup.sh # Automated setup script (Ubuntu/Debian)
└── README.md # This file
Dự án mã nguồn mở, chào đón mọi đóng góp:
- Fork repo
- Tạo branch:
git checkout -b feature/your-feature - Commit:
git commit -m "Add your feature" - Push:
git push origin feature/your-feature - Tạo Pull Request
MIT License - Xem file LICENSE để biết thêm chi tiết.
- Issues: https://github.com/your-username/LocalAIChatBox/issues
- Wiki: https://github.com/your-username/LocalAIChatBox/wiki
- Discussions: https://github.com/your-username/LocalAIChatBox/discussions
- Ollama: https://ollama.com/
- LangChain: https://python.langchain.com/
- ChromaDB: https://www.trychroma.com/
- LightRAG: https://github.com/HKUDS/LightRAG
- SearXNG: https://docs.searxng.org/
- Sentence Transformers: https://www.sbert.net/
- FastAPI: https://fastapi.tiangolo.com/
- React: https://react.dev/
- NetworkX: https://networkx.org/
- Docker: https://docs.docker.com/
LocalAIChatBox v6.0 - Hệ thống AI Multimodal hoàn toàn offline cho doanh nghiệp
Enterprise-ready • Multimodal • Knowledge Graph • Deep Research
Made with ❤️ by [Your Name/Team]
- ✅ Add logging (structlog + ELK/Loki)
- ✅ Add monitoring (Prometheus + Grafana)
- ✅ Implement backup/restore scripts
- ✅ Add unit + integration tests (target: 70% coverage)
- ✅ Setup CI/CD pipeline (GitHub Actions)
- ✅ Add audit logging system
- ✅ Migrate FAISS → ChromaDB
- ✅ Implement Redis caching (via rate limiting)
- ✅ Enable GPU support + quantized models
- ✅ Add response streaming (SSE/NDJSON)
- ✅ Migrate deep research → async background tasks
- ✅ Load testing & optimization
- ✅ Document versioning & folders
- ✅ Chat history with context (Conversation + ChatSession)
- ✅ Interactive KG visualization (NetworkX + LightRAG)
- ✅ Advanced filters & faceted search
- ✅ Usage analytics dashboard
- ✅ Export features (chat, reports, graphs)
- ✅ LDAP/AD integration (SSO)
- ✅ RBAC (Role-Based Access Control)
- ✅ Per-document permissions
- ✅ Encryption at rest
- ✅ Compliance reports (GDPR, etc.)
- ✅ Multi-tenancy support
- ✅ Multimodal document processing (PDF, DOCX, XLSX, PPTX, images)
- ✅ Vision model integration (llava)
- ✅ Image/table/chart extraction and understanding
- ✅ Multimodal query engine
- ✅ Hybrid search (text + multimodal + KG)
- ✅ LightRAG service integration
- ✅ 5 query modes (naive, local, global, hybrid, mix)
- ✅ Streaming query support
- ✅ Batch document indexing
- ✅ Graph editing capabilities
- ✅ Dual KG system (NetworkX + LightRAG)
- 🔄 Advanced RAG techniques (hypothetical document embeddings, multi-query)
- 🔄 Fine-tuning support for domain-specific models
- 🔄 Multi-language support (automatic language detection)
- 🔄 Advanced visualization (3D graph, timeline view)
- 🔄 Voice input/output (speech-to-text, text-to-speech)
- 🔄 Mobile app (React Native)
- 🔄 Collaborative features (shared workspaces, comments)
- 🔄 Integration với external tools (Slack, Teams, Jira)