File size: 3,257 Bytes
34241fb 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 14faba3 be9c365 ade181c 14faba3 be9c365 14faba3 be9c365 ade181c 14faba3 be9c365 d50d28b 14faba3 d50d28b 14faba3 be9c365 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 d50d28b 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 55f362f 14faba3 ef21bff 14faba3 ef21bff 14faba3 ef21bff 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f 14faba3 55f362f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
---
title: ContextAI
emoji: π€
colorFrom: blue
colorTo: green
sdk: docker
sdk_version: "1.0"
app_file: app.main
pinned: false
---
# ContextAI
A **FastAPI-based RAG application** that lets users upload documents (PDF/TXT) and ask questions.
Powered by **LangChain**, **ChromaDB**, and **LLMs** for context-aware answers.
## π FastAPI RAG App with LangChain, ChromaDB & Authentication
This project is a Retrieval-Augmented Generation (RAG) web application built with FastAPI.
It allows users to:
- π Sign up / Sign in (JWT-based authentication)
- π Upload PDF or text documents
- π§ Store document embeddings in ChromaDB (vector database)
- π¬ Ask questions about uploaded documents
- β‘ Get context-aware answers powered by LangChain + LLMs (via OpenRouter
)
## π Features
- User authentication with access & refresh tokens
- Secure file uploads (.pdf, .txt)
- Automatic text chunking & embedding with HuggingFace models
- Persistent vector store using ChromaDB
- RAG pipeline with LangChainβs RetrievalQA
- OpenRouter integration for running LLM queries
- CORS configured for frontend integration
## π οΈ Tech Stack
- FastAPI
- LangChain
- ChromaDB
- SQLModel
- for user database
- HuggingFace Embeddings
- OpenRouter
- (for LLM access)
## π Project Structure
`````
app/
βββ main.py # FastAPI routes & entrypoint
βββ rag.py # RAG pipeline (embeddings, vector store, QA chain)
βββ models.py # User models & schemas
βββ auth.py # Auth logic (hashing, tokens, verification)
βββ database.py # SQLModel setup
βββ config.py # Settings & constants
uploads/ # User uploaded files (ignored in Git)
chroma_db/ # Vector DB storage (ignored in Git)
`````
## βοΈ Setup & Installation
1οΈβ£ Clone the repo
- git clone https://github.com/your-username/fastapi-rag-app.git
- cd fastapi-rag-app
2οΈβ£ Create & activate virtual environment
- python -m venv venv
- source venv/bin/activate # Linux/Mac
- venv\Scripts\activate # Windows
3οΈβ£ Install dependencies
- pip install -r requirements.txt
4οΈβ£ Configure environment variables
- Create a .env file in the project root (or copy from .env.example):
- ### OpenRouter
- OPENROUTER=your_openrouter_api_key_here
- ### JWT secret
- SECRET_KEY=your_super_secret_key
β οΈ Never commit your real .env file.
βΆοΈ Run the App
- Start the FastAPI server:
- uvicorn app.main:app --reload
- The API will be available at:
- π http://127.0.0.1:8000
## π Authentication Flow
- Signup β POST /signup with username & password
- Signin β POST /signin to receive access_token & refresh_token
- Use Authorization: Bearer <access_token> for protected endpoints
## π Document Workflow
- User logs in
- Upload document β POST /upload (PDF or TXT)
- Ask a question β GET /ask?q=your+question
- The system searches your embeddings in ChromaDB and queries the LLM with context
## π Notes
- uploads/ and chroma_db/ are auto-created at runtime if they donβt exist.
- Both folders are ignored by Git (runtime data only).
- Contributions & pull requests are welcome π |