{"id":50928348,"url":"https://github.com/persteenolsen/fastapi-jwt-auth-rag-two","last_synced_at":"2026-06-17T01:31:08.519Z","repository":{"id":350695083,"uuid":"1207908184","full_name":"persteenolsen/fastapi-jwt-auth-rag-two","owner":"persteenolsen","description":"Python FastAPI with JWT Auth serving RAG using Real embeddings","archived":false,"fork":false,"pushed_at":"2026-06-16T05:34:48.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-16T07:47:02.345Z","etag":null,"topics":["fastapi","llp","pgvector","postgresql","python","rag-pipeline"],"latest_commit_sha":null,"homepage":"https://fastapi-jwt-auth-rag-two.vercel.app/docs","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/persteenolsen.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-11T15:09:06.000Z","updated_at":"2026-06-16T05:34:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/persteenolsen/fastapi-jwt-auth-rag-two","commit_stats":null,"previous_names":["persteenolsen/fastapi-jwt-auth-rag-two"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/persteenolsen/fastapi-jwt-auth-rag-two","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-rag-two","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-rag-two/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-rag-two/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-rag-two/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/persteenolsen","download_url":"https://codeload.github.com/persteenolsen/fastapi-jwt-auth-rag-two/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-rag-two/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34430688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["fastapi","llp","pgvector","postgresql","python","rag-pipeline"],"created_at":"2026-06-17T01:31:07.983Z","updated_at":"2026-06-17T01:31:08.498Z","avatar_url":"https://github.com/persteenolsen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python + FastAPI + JWT Auth + RAG + Hugging Face embeddings\n\nA production-style **Retrieval-Augmented Generation (RAG)** API built with **FastAPI**.  \nThis project combines **secure JWT authentication**, **vector search with pgvector**, **Hugging Face embeddings**, and **Groq LLMs** to deliver context-aware answers from your own data.\n\n---\n\n## 📌 Project Info\n\n- **Last Updated:** 16-06-2026  \n- **Python Version:** 3.12  \n\n---\n\n## ✨ Features\n\n### 🔐 Authentication\n- JWT-based authentication (HS256)\n- Protected endpoints using Bearer tokens\n- Environment-based credentials\n\n---\n\n### 🧠 RAG Pipeline\n- Ingests `.txt` documents from URLs  \n- Splits content into **topic-based chunks**  \n- Generates embeddings using Hugging Face  \n- Stores vectors in PostgreSQL (`pgvector`)  \n- Retrieves relevant context for queries  \n\n---\n\n### 🤖 LLM Integration (Groq)\n- Model: `llama-3.1-8b-instant`  \n- Context-aware answer generation  \n- Structured prompting for grounded responses  \n\n---\n\n### 🔎 Semantic Search\n- Query → embedding  \n- Top-K similarity search via `pgvector`  \n- Cosine distance (`\u003c-\u003e`)  \n\n---\n\n### 🗄️ Vector Database (PostgreSQL + pgvector)\nStores:\n- Document content  \n- Embeddings (384-dim vectors)  \n- Source URL  \n- Metadata  \n- Timestamp  \n\nOptimizations:\n- `VECTOR(384)` column  \n- `ivfflat` index for fast retrieval  \n\n---\n\n### ⚙️ Background Processing\n- FastAPI `BackgroundTasks`  \n- Async ingestion pipeline  \n- Non-blocking embedding + DB insert  \n\n---\n\n### 🧪 Debug Tools\n- `/debug/retrieve` → test retrieval without LLM  \n- Console logging for inspection  \n\n---\n\n## 📡 API Endpoints\n\n| Method | Endpoint            | Description                          |\n|--------|--------------------|--------------------------------------|\n| POST   | `/token`           | Get JWT access token                 |\n| POST   | `/ask`             | Ask questions (RAG-powered) 🔐       |\n| POST   | `/ingest`          | Ingest `.txt` files from URLs        |\n| GET    | `/debug/retrieve`  | Debug semantic search                |\n\n🔐 = Requires authentication\n\n---\n\n## ⚙️ Getting Started\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/your-username/your-repo.git\ncd your-repo\n```\n\n---\n\n### 2. Create Virtual Environment\n\n```bash\npython -m venv venv\n```\n\nActivate it:\n\n**Windows (PowerShell):**\n```bash\nvenv\\Scripts\\activate\n```\n\n**Mac/Linux:**\n```bash\nsource venv/bin/activate\n```\n\n---\n\n### 3. Install Dependencies\n\n```bash\npip install -r requirements.txt\n```\n\n---\n\n## ▶️ Run the Application\n\n```bash\nuvicorn main:app --reload\n```\n\nOnce running:\n\n- 🌐 API: http://127.0.0.1:8000\n\n- 📄 Swagger Docs: http://127.0.0.1:8000/docs  \n\nUse Swagger UI to:\n1. Authenticate via `/token`  \n2. Copy the JWT token  \n3. Authorize requests  \n\n---\n\n## 🔑 Authentication Flow\n\n1. Call `/token` with credentials  \n2. Receive JWT access token  \n3. Use in headers:\n\n```http\nAuthorization: Bearer \u003cyour_token\u003e\n```\n\n---\n\n## 🧠 How RAG Works\n\n```text\nUser Query\n   ↓\nEmbedding (Hugging Face)\n   ↓\npgvector Similarity Search\n   ↓\nTop-K Relevant Chunks\n   ↓\nGroq LLM (LLaMA 3.1)\n   ↓\nFinal Answer + Sources\n```\n\n---\n\n## 📥 Document Ingestion\n\n### `/ingest`\n- Accepts `.txt` file URLs  \n- Downloads and cleans content  \n- Splits into topic-based chunks  \n- Generates embeddings  \n- Stores results in PostgreSQL  \n\n---\n\n## 🧾 Embeddings\n\n- Model: `sentence-transformers/all-MiniLM-L6-v2`  \n- 384-dimensional normalized vectors  \n- Batch processing with retry support  \n- Powered via Hugging Face Inference API  \n\n---\n\n## 🗄️ Database Initialization\n\nOn application startup:\n- Creates `pgvector` extension  \n- Creates `documents` table  \n- Builds `ivfflat` similarity index  \n\n---\n\n## 🛠️ Text Processing\n\n- Fetches `.txt` files from URLs  \n- Validates content type  \n- Cleans and normalizes text  \n\n---\n\n## 📌 Future Improvements\n\n- 🔄 Refresh tokens  \n- 📊 Admin dashboard  \n- 🔍 Hybrid search (BM25 + vector)  \n- 📈 Monitoring \u0026 logging  \n- 🧩 Plugin/tool integrations\n- Splitting the code of the app.py into seperates files inside folders for improved structure  \n\n---\n\n## 📄 License\n\nMIT License  \n\n---\n\n## 🙌 Final Notes\n\nThis project is designed as a **clean, production-style RAG backend** and can be extended into:\n- Chatbots  \n- Internal knowledge systems  \n- AI assistants  \n- Document search platforms  \n\nHappy coding :-)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-rag-two","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-rag-two","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-rag-two/lists"}