Chatbot احترافي بـ RAG
بوت دردشة ذكي يقرأ ملفاتك (PDF/DOC) ويجيب على أسئلتك حسب محتواها — Retrieval-Augmented Generation. مبني على LangChain + FAISS + OpenAI Embeddings مع ذاكرة محادثة.
abstract
بوت دردشة Production-grade يحوّل أي مكتبة وثائق إلى مساعد ذكي يجاوب فقط من محتواك.
🎯 المشكلة: ChatGPT العام لا يعرف بياناتك الخاصة. كل مرة تحتاج تنسخ الوثيقة في الدردشة.
✨ الحل: نظام RAG (Retrieval-Augmented Generation) يقرأ ملفاتك مرة واحدة ويحفظها كـ vector embeddings.
التقنيات: • LangChain — orchestration للـ chain • PyPDFLoader — تحميل وتحويل PDFs • RecursiveCharacterTextSplitter — تقطيع ذكي يحافظ على السياق • OpenAI Embeddings — تحويل النص إلى vectors • FAISS — متجر vectors محلي عالي السرعة (مفيش API charges على البحث) • ConversationalRetrievalChain — محادثة مع ذاكرة • ConversationBufferMemory — حفظ سياق المحادثة • Custom Prompt Template للأسلوب العربي
architecture
┌──────────────┐ ┌────────────┐ ┌─────────────┐
│ client │─────▶│ nginx │─────▶│ next.js │
│ (browser) │ │ (proxy) │ │ (ssr) │
└──────────────┘ └─────┬──────┘ └──────┬──────┘
│ │
▼ ▼
┌───────────┐ ┌──────────┐
│ fastapi │◀──────▶│ postgres │
│ (asyncio) │ │ (asyncpg)│
└───────────┘ └──────────┘Stateless API behind a reverse proxy. SSR delivers HTML in under a second on warm cache. Connection pool keeps Postgres hot. JWT in HttpOnly cookie for the admin panel.
notes
- SSR-first to keep TTFB < 1s on cold visits.
- Type-checked end-to-end via Pydantic schemas mirrored to TS.
- Migrations versioned via Alembic; zero-downtime restarts.