{"id":29383522,"url":"https://github.com/mahbub2001/rag-fastapi","last_synced_at":"2025-10-19T21:25:20.347Z","repository":{"id":301239709,"uuid":"1008609874","full_name":"Mahbub2001/rag-fastapi","owner":"Mahbub2001","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-25T21:03:09.000Z","size":11465,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-25T21:36:15.508Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mahbub2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-25T20:15:13.000Z","updated_at":"2025-06-25T21:03:12.000Z","dependencies_parsed_at":"2025-06-25T21:46:18.570Z","dependency_job_id":null,"html_url":"https://github.com/Mahbub2001/rag-fastapi","commit_stats":null,"previous_names":["mahbub2001/rag-fastapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Mahbub2001/rag-fastapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahbub2001%2Frag-fastapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahbub2001%2Frag-fastapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahbub2001%2Frag-fastapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahbub2001%2Frag-fastapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mahbub2001","download_url":"https://codeload.github.com/Mahbub2001/rag-fastapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahbub2001%2Frag-fastapi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264528815,"owners_count":23623228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-10T04:35:48.633Z","updated_at":"2025-10-19T21:25:15.285Z","avatar_url":"https://github.com/Mahbub2001.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔍 InsightEngine – AI-Powered Document Query System\n\nA lightweight AI micro-agent built with **FastAPI**, **FAISS**, **SentenceTransformers**, and **OpenRouter/OpenAI**, designed to retrieve insights from multiple research documents in PDF format.\n\n---\n\n## 🚀 Features\n\n- 🧠 Embedding-based document retrieval (FAISS + all-MiniLM-L6-v2)\n- 📄 Supports querying over multiple PDF documents\n- 🧾 Structured answers with citations (`[Source: doc_X]`)\n- ⚡ SQLite caching for faster repeat queries\n- 🔁 Streaming responses token-by-token\n- 📚 Query \u0026 response logging in SQLite\n- 📦 OpenAI/OpenRouter compatible LLM backend\n\n---\n\n## 🧰 Tech Stack\n\n- Python, FastAPI\n- FAISS (vector search)\n- sentence-transformers (`all-MiniLM-L6-v2`)\n- SQLite3 for caching/logging\n- OpenAI/OpenRouter LLM API\n- PyMuPDF (`fitz`) for PDF text extraction\n\n---\n\n## 📁 Project Structure\n```plaintext\n├── data/              # Folder containing your PDF documents\n├── main.py            # FastAPI app with endpoints\n├── retriever.py       # FAISS-based document chunking \u0026 search\n├── llm_agent.py       # LLM prompt creation and streaming\n├── db.py              # SQLite caching \u0026 query logging\n├── requirements.txt   # Python dependencies\n└── .env               # API keys and environment variables\n```\n\n---\n\n## ⚙️ Setup Instructions\n\n### 1. Clone this repo\n\n```bash\ngit clone https://github.com/your-username/insightengine\ncd insightengine\n```\n\n### 2. Install dependencies\n\n```bash\npython -m venv venv\nsource venv/bin/activate    # or `venv\\Scripts\\activate` on Windows\npip install -r requirements.txt\n```\n\n### 3. Add PDFs\nPlace at least 10 short .pdf documents inside the data/ folder.\n\n\n### 4. Create .env\nOPENROUTER_API_KEY=your_api_key_here\n\n### 5. Run the API\nuvicorn main:app --reload\n\n\n🛠 API Usage\n🔎 POST /query\nReturns cached or newly generated answer.\n\nRequest:\n```bash\n{\n  \"query\": \"What is the conclusion of document 3?\"\n}\n```\nResponse:\n```bash\n{\n  \"answer\": \"- The study highlights that... [Source: doc_03]\",\n  \"sources\": [\"doc_03_chunk_1\", \"doc_01_chunk_0\", \"doc_02_chunk_2\"]\n}\n```\n🔁 POST /query_stream\nStreams the answer token-by-token (for faster UI feedback).\n\n💾 Caching \u0026 Logging\nSQLite Cache: Stores previous queries and responses in cache.db\n\nLogged Items:\n--Query string\n--Prompt content\n--Final answer\n--Source chunks used\n\n✅ Requirements\nPython 3.8+\n\nNo Redis required — uses SQLite-based caching and logging\n\n🔐 Security\nAll model answers are grounded in retrieved documents\nPrompts explicitly tell the LLM to avoid hallucinations\n\nExample instruction:\n“Only use the following context to answer. Do not make up facts. Always cite the source as [Source: doc_X].”\n\n📦 Models \u0026 LLMs\nYou can use any OpenRouter-supported model, for example:\nqwen/qwen-2.5-coder-32b-instruct:free\nmistralai/mixtral-8x7b-instruct\nmeta-llama/llama-3-70b-instruct\n\nSet the model in llm_agent.py.\n\n🙋‍♂️ Author\nMahbub Ahmed Turza\n\n📝 License\nMIT License — free to use, modify, and distribute.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahbub2001%2Frag-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahbub2001%2Frag-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahbub2001%2Frag-fastapi/lists"}