Commit Β·
b344f06
1
Parent(s): 3f5127b
add README
Browse filesFiles changed (2)
- README.md+327-1
- screenshot.pngAdded
4 unmodified lines56784 unmodified linescolorTo: greensdk: dockerpinned: false---4 unmodified lines567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333344 unmodified linescolorTo: greensdk: dockerpinned: false---# π€π½ AI Knowledge Assistant> Turn any document into a smart chatbot β with citations, memory, and hybrid search.[](https://knowledge-frontend-ten.vercel.app)[](https://t.me/7asaneen_bot)[](https://khaled0fouad000-knowledge-assistant-api.hf.space)[](https://python.org)[](https://fastapi.tiangolo.com)[](LICENSE)---## Preview---## What Is This?**AI Knowledge Assistant** is a production-ready RAG (Retrieval-Augmented Generation) system that ingests documents from multiple sources, builds a searchable knowledge base, and answers questions with accurate, cited responses.Upload a PDF, paste a URL, or send a CSV β then ask anything. The assistant retrieves the most relevant chunks using **hybrid search** (semantic + keyword), and generates answers grounded in your document β not hallucinated.Available as a **web app**, a **Telegram bot**, and a **REST API**.---## Features- π§ **Hybrid RAG Search** β Combines FAISS semantic search with BM25 keyword retrieval for higher accuracy- π **Multi-source Ingestion** β PDF, TXT, CSV, DOCX, and URLs- π¬ **Conversation Memory** β Maintains context across multiple turns per session- π **Page-level Citations** β Every answer references its source page or chunk- π€ **Telegram Bot** β Chat with your documents directly from Telegram- π **Next.js Frontend** β Clean, responsive web interface- β‘ **Fast Inference** β Powered by Groq (LLaMA 3.3 70B) for near-instant responses- π **Session Management** β Independent conversation history per user/session---## How It Works```User (Web / Telegram)βUpload DocumentβText Extraction βββ Chunking βββ Embeddings βββ FAISS IndexβUser Question βββ Hybrid Retrieval (FAISS + BM25)βTop K Relevant ChunksβGroq LLM (LLaMA 3.3 70B) + Chat HistoryβAnswer with Page Citations```### Why Hybrid Search?Pure semantic search misses exact keyword matches. Pure BM25 misses conceptual similarity. Combining both covers more ground β the system deduplicates results and returns the best chunks from either approach.---## ποΈ Project Structure```knowledge-assistant/ββββ main.py # FastAPI backend β all endpoints, RAG logic, session managementβββ bot.py # Telegram bot β file handling, URL ingestion, message routingβββ app.py # Streamlit UI β lightweight web interfaceββββ requirements.txt # Python dependenciesβββ Dockerfile # Container configurationβββ Procfile # Process definitionsββββ README.md```**Frontend (separate repo):**```knowledge-frontend/ββββ app/βββ page.tsx # Next.js chat interface β file upload, URL input, chat UI```---## βοΈ Setup & Run### 1. Clone the repository```bashgit clone https://github.com/Khaled-fouad0/knowledge-assistant.gitcd knowledge-assistant```### 2. Install dependencies```bashpip install -r requirements.txt```### 3. Configure environmentCreate a `.env` file:```envGROQ_API_KEY=your_groq_key_hereTELEGRAM_TOKEN=your_telegram_token_here```Get a free Groq key at [console.groq.com](https://console.groq.com) β no credit card required.### 4. Run the backend```bashuvicorn main:app --reload```API available at `http://localhost:8000`Interactive docs at `http://localhost:8000/docs`### 5. Run the Telegram bot (optional)```bashpython bot.py```### 6. Run the Streamlit UI (optional)```bashstreamlit run app.py```---## π API Reference### Upload Endpoints| Method | Endpoint | Description ||--------|----------|-------------|| `POST` | `/upload` | Upload a PDF file || `POST` | `/upload_text` | Upload a TXT file || `POST` | `/upload_csv` | Upload a CSV file || `POST` | `/upload_docx` | Upload a DOCX file || `POST` | `/upload_url` | Ingest content from a URL |**Example β Upload PDF:**```bashcurl -X POST http://localhost:8000/upload \-F "file=@document.pdf"```**Response:**```json{"status": "success","pages": 12,"chunks": 47,"filename": "document.pdf"}```---### Conversation Endpoints#### `POST /ask`Ask a question about the uploaded document.**Request:**```json{"message": "What is the main conclusion of the report?","session_id": "user_123"}```**Response:**```json{"answer": "According to page 4, the main conclusion is...","session_id": "user_123"}```---#### `POST /chat`General chat without document context (no RAG).**Request:**```json{"message": "Explain what a vector database is.","session_id": "user_123"}```---#### `DELETE /reset/{session_id}`Clear conversation history for a session.```bashcurl -X DELETE http://localhost:8000/reset/user_123```---#### `POST /upload_url`Ingest a webpage into the knowledge base.**Request:**```json{"url": "https://example.com/article"}```**Response:**```json{"status": "success","chunks": 31,"url": "https://example.com/article"}```---## π€ Telegram Bot UsageFind the bot at [@7asaneen_bot](https://t.me/7asaneen_bot)| Action | How ||--------|-----|| Upload a file | Send any PDF, TXT, CSV, or DOCX directly || Ingest a URL | `/url https://example.com` || Ask a question | Just type your message || Start / Help | `/start` |---## π§± Tech Stack| Layer | Technology ||-------|------------|| Backend | FastAPI + Uvicorn || LLM | Groq β LLaMA 3.3 70B || Embeddings | HuggingFace β `all-MiniLM-L6-v2` || Vector Store | FAISS || Keyword Search | BM25 (rank-bm25) || PDF Parsing | PyMuPDF (fitz) || Web Scraping | httpx + BeautifulSoup4 || Memory | LangChain `ChatMessageHistory` || Frontend | Next.js + Tailwind CSS || Alt UI | Streamlit || Bot | python-telegram-bot || Deployment | Hugging Face Spaces + Vercel || Container | Docker |---## π Deployment### Backend β Hugging Face Spaces (Docker)The backend is deployed as a Docker Space on Hugging Face.The `Dockerfile` and `Procfile` are included in the repo.Live API: [khaled0fouad000-knowledge-assistant-api.hf.space](https://khaled0fouad000-knowledge-assistant-api.hf.space)### Frontend β VercelThe Next.js frontend is deployed on Vercel.Live app: [knowledge-frontend-ten.vercel.app](https://knowledge-frontend-ten.vercel.app)---## π Notes- `allow_origins=["*"]` is set for development β restrict in production- Each session maintains independent conversation history- The document index is shared globally β designed for single-user or demo use; extend with per-session vectorstores for multi-tenant production use- LLM responses are grounded in retrieved context only β hallucination is minimized by design---## π§ Possible Extensions- [ ] Per-session document isolation (multi-tenant support)- [ ] Persistent vectorstore (save/load FAISS index to disk)- [ ] Streaming responses (SSE / token-by-token)- [ ] Multi-document support (upload and query multiple files at once)- [ ] Confidence scoring per answer- [ ] Admin dashboard for session monitoring- [ ] Authentication layer (API keys or OAuth)- [ ] Support for more file types (PPTX, XLSX, audio transcripts)---## π€ AuthorBuilt by **Khaled** π€π½[](https://github.com/Khaled-fouad0)---## π LicenseMIT β free to use, modify, and distribute.
README.md+327-1
screenshot.pngAdded
