Skip to content

Latest commit

History

1,179 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

🧠 SelfSmart AI

PythonFastAPINext.jsPyTorchMLXChromaDBLicense

A RAG-enhanced chatbot with manual fine-tuning capabilities for domain-specific knowledge integration.

Architecture · Deployment Guide


📌 The Engineering Vision

SelfSmart addresses a limitation of static LLMs: knowledge cutoff dates. By integrating web crawling with Retrieval-Augmented Generation (RAG), the system can access up-to-date information without retraining. For domain-specific use cases, manual LoRA/DPO fine-tuning scripts allow knowledge to be baked directly into model weights.

Core Thesis: Combine RAG for fresh context access with optional fine-tuning for domain specialization. RAG provides immediate knowledge updates; fine-tuning encodes domain expertise into model weights for efficiency.


🏗️ System Architecture

The system has 5 phases for knowledge integration. Phases 1-2 (data collection and RAG) are automated. Phases 3-5 (fine-tuning) are manual scripts that require developer execution.

graph TD
subgraph Phase 1: Data Acquisition
Crawler[Web/RSS Crawler] --> JSON[Processed JSON Data]
end
subgraph Phase 2: RAG Pipeline
JSON --> Embed[Sentence Transformers]
Embed --> VectorDB[(ChromaDB)]
VectorDB -.->|Context Injection| Inference
end
subgraph Phase 3: Cognitive Integration
JSON --> Instruct[Instruction Formatting]
Instruct --> LoRA[Supervised Fine-Tuning LoRA]
LoRA --> Merge[Model Merging]
end
subgraph Phase 4: Local Execution
Merge --> MLX[Apple MLX Unified Memory]
MLX --> Inference[Fast Streaming API]
end
subgraph Phase 5: The Data Flywheel
Inference --> User[User UI]
User -.->|Thumbs Up/Down| Feedback[feedback.jsonl]
Feedback --> Gemini[Gemini Synthesis]
Gemini --> Preference[DPO Preference Dataset]
Preference --> DPOTrain[Direct Preference Optimization]
DPOTrain --> MLX
end
classDef primary fill:#2b3137,stroke:#24292e,stroke-width:2px,color:#fff;
classDef secondary fill:#0366d6,stroke:#005cc5,stroke-width:2px,color:#fff;
classDef db fill:#28a745,stroke:#22863a,stroke-width:2px,color:#fff;
class Crawler,JSON,Instruct,LoRA,Merge,MLX,Inference,User,Feedback,Gemini,Preference,DPOTrain primary;
class VectorDB db;
Loading

✅ System Capabilities (The 5 Phases)

PhaseFeatureEngineering DetailsAutomation Status
1Web CrawlingAsync data collector pulling HTML/RSS into JSON pipelines via aiohttp and BeautifulSoup4.Manual script execution
2RAG Search EngineChromaDB integration with sentence-transformers for semantic retrieval and context-grounding.Automated in chat flow
3SFT LoRA Fine-TuningPyTorch peft and trl.SFTTrainer pipelines for domain-specific knowledge integration.Manual script execution
4Apple MLX Inferencemlx-lm for native Apple Silicon Unified Memory execution with streaming SSE responses.Automated in chat flow
5DPO TrainingRLHF pipeline using trl.DPOTrainer with Gemini-synthesized preference pairs from user feedback.Manual script execution

🚀 Quick Start

Prerequisites

  • Python 3.9 - 3.11
  • Node.js 20+
  • Apple Silicon Mac (M1/M2/M3) recommended for local MLX inference

1. Installation

git clone https://github.com/genius-0963/SelfSmart.git
cd SelfSmart
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

2. Environment Configuration

cp .env.example .env

Add your GEMINI_API_KEY (used for data synthesis and evaluation) inside .env.

3. Start the Ecosystem

# Terminal 1: Backend API
uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reload
# Terminal 2: Frontend UIcd frontend && npm install && npm run dev

🔭 Potential Applications

The SelfSmart architecture could be adapted for various domain-specific use cases:

  1. Technical Documentation Assistant: Crawl and ingest technical docs, API references, and code repositories. Use RAG for immediate Q&A and fine-tune for domain-specific terminology.

  2. Corporate Knowledge Base: Index internal wikis, Slack conversations, and documentation. RAG provides fresh context; fine-tuning encodes company-specific jargon.

  3. Research Assistant: Digest academic papers and research publications. RAG retrieves relevant papers; fine-tuning adapts to specific research domains.


ROADMAP · Deployment Guide


🛠️ Tech Stack

AI / ML Core

LayerTechnologyPurpose
Inference EngineApple MLX (mlx-lm)High-speed, native Apple Silicon LLM execution
Alignment (RLHF)TRL (DPOTrainer)Direct Preference Optimization using human feedback
Fine-Tuning (SFT)PEFT (LoRA)Parameter-efficient weight updates on Kaggle/Local GPUs
Vector StoreChromaDBLocal persistent semantic memory

Backend Infrastructure

LayerTechnologyPurpose
FrameworkFastAPIAsync REST, Server-Sent Events (SSE) streaming
AutomationasyncioConcurrent web crawling and dataset synthesis
SynthesisGemini APIGenerates missing preference pairs for DPO datasets

🗂️ Project Structure

SelfSmart/
├── src/
│ ├── api/main.py # FastAPI application entry point
│ ├── llm_training/
│ │ ├── inference.py # MLX-powered LocalLLMClient
│ │ ├── lora_trainer.py # SFTTrainer Pipeline
│ │ └── dpo_trainer.py # RLHF DPOTrainerManager
│ └── llm/ # RAG logic and Gemini API integrations
│
├── scripts/
│ ├── build_dataset.py # Phase 1: Web Scraper -> Instruction JSON
│ ├── ingest_data.py # Phase 2: Instruction JSON -> ChromaDB RAG
│ ├── build_dpo_dataset.py # Phase 5: Feedback JSONL -> DPO Triplets
│ ├── train_local.py # Local LoRA SFT Execution
│ └── train_dpo.py # Local DPO Execution
│
├── data/ # Persistent SQLite and Feedback logs
├── vector_store/ # ChromaDB storage
├── training_data/ # Raw and Processed JSON datasets
├── models/ # LoRA Checkpoints and Merged Safetensors
│
├── kaggle_train.ipynb # Cloud GPU SFT Notebook
└── kaggle_dpo.ipynb # Cloud GPU DPO Notebook

🔬 Engineering Principles

SelfSmart is designed with a Senior AI/ML Engineering mindset:

PrincipleHow It's Applied
Hardware SymbiosisWe ditched PyTorch inference on Mac in favor of mlx-lm to tap directly into Apple's Unified Memory, bypassing expensive CUDA constraints.
VRAM OptimizationKaggle notebooks utilize bitsandbytes 4-bit NF4 quantization to squeeze 3.8B parameter models into 16GB T4 instances without OOM crashes.
Data IntegrityInstead of manually writing synthetic data, the DPO builder proxies through Gemini to guarantee structurally perfect chosen/rejected pairings.
Architectural AgilityThe system is highly modular. The LLM engine, RAG database, and UI are fully decoupled, allowing plug-and-play swaps as the ecosystem evolves.

🤝 Contributing & License

Contributions are welcome. Please keep PRs focused and ensure they align with the ARCHITECTURE.md. This project is licensed under the MIT License.


If SelfSmart helped you envision the future of autonomous AI, give it a star!

Built with 🧠 and ☕ by Subh | Report a Bug

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages