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:
π Authentication Flow
Signup β POST /signup with username & password
Signin β POST /signin to receive access_token & refresh_token
Use Authorization: Bearer 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 π