Kareman commited on
Commit
be9c365
Β·
1 Parent(s): 14faba3

fix(readme and config)

Browse files
Files changed (3) hide show
  1. README.md +59 -61
  2. app/config.py +5 -0
  3. app/rag.py +3 -2
README.md CHANGED
@@ -3,55 +3,55 @@
3
  A **FastAPI-based RAG application** that lets users upload documents (PDF/TXT) and ask questions.
4
  Powered by **LangChain**, **ChromaDB**, and **LLMs** for context-aware answers.
5
 
6
- πŸ“š FastAPI RAG App with LangChain, ChromaDB & Authentication
7
 
8
  This project is a Retrieval-Augmented Generation (RAG) web application built with FastAPI.
9
  It allows users to:
10
 
11
- πŸ”‘ Sign up / Sign in (JWT-based authentication)
12
 
13
- πŸ“‚ Upload PDF or text documents
14
 
15
- 🧠 Store document embeddings in ChromaDB (vector database)
16
 
17
- πŸ’¬ Ask questions about uploaded documents
18
 
19
- ⚑ Get context-aware answers powered by LangChain + LLMs (via OpenRouter
20
  )
21
 
22
- πŸš€ Features
23
 
24
- User authentication with access & refresh tokens
25
 
26
- Secure file uploads (.pdf, .txt)
27
 
28
- Automatic text chunking & embedding with HuggingFace models
29
 
30
- Persistent vector store using ChromaDB
31
 
32
- RAG pipeline with LangChain’s RetrievalQA
33
 
34
- OpenRouter integration for running LLM queries
35
 
36
- CORS configured for frontend integration
37
 
38
- πŸ› οΈ Tech Stack
39
 
40
- FastAPI
41
 
42
- LangChain
43
 
44
- ChromaDB
45
 
46
- SQLModel
47
- for user database
48
 
49
- HuggingFace Embeddings
50
 
51
- OpenRouter
52
- (for LLM access)
53
 
54
- πŸ“‚ Project Structure
55
  app/
56
  β”œβ”€β”€ main.py # FastAPI routes & entrypoint
57
  β”œβ”€β”€ rag.py # RAG pipeline (embeddings, vector store, QA chain)
@@ -62,66 +62,64 @@ app/
62
  uploads/ # User uploaded files (ignored in Git)
63
  chroma_db/ # Vector DB storage (ignored in Git)
64
 
65
- βš™οΈ Setup & Installation
66
- 1️⃣ Clone the repo
67
- git clone https://github.com/your-username/fastapi-rag-app.git
68
- cd fastapi-rag-app
69
 
70
- 2️⃣ Create & activate virtual environment
71
- python -m venv venv
72
- source venv/bin/activate # Linux/Mac
73
- venv\Scripts\activate # Windows
74
 
75
- 3️⃣ Install dependencies
76
- pip install -r requirements.txt
77
 
78
- 4️⃣ Configure environment variables
79
 
80
- Create a .env file in the project root (or copy from .env.example):
81
 
82
- # OpenRouter
83
- OPENROUTER=your_openrouter_api_key_here
84
 
85
- # JWT secret
86
- SECRET_KEY=your_super_secret_key
87
 
88
- ⚠️ Never commit your real .env file.
89
 
90
- ▢️ Run the App
91
 
92
- Start the FastAPI server:
93
 
94
- uvicorn app.main:app --reload
95
 
96
 
97
- The API will be available at:
98
- πŸ‘‰ http://127.0.0.1:8000
99
 
100
- Interactive API docs:
101
- πŸ‘‰ http://127.0.0.1:8000/docs
102
 
103
- πŸ”‘ Authentication Flow
104
 
105
- Signup β†’ POST /signup with username & password
106
 
107
- Signin β†’ POST /signin to receive access_token & refresh_token
108
 
109
- Use Authorization: Bearer <access_token> for protected endpoints
110
 
111
- πŸ“‚ Document Workflow
112
 
113
- User logs in
114
 
115
- Upload document β†’ POST /upload (PDF or TXT)
116
 
117
- Ask a question β†’ GET /ask?q=your+question
118
 
119
- The system searches your embeddings in ChromaDB and queries the LLM with context
120
 
121
- πŸ“ Notes
122
 
123
- uploads/ and chroma_db/ are auto-created at runtime if they don’t exist.
124
 
125
- Both folders are ignored by Git (runtime data only).
126
 
127
- Contributions & pull requests are welcome πŸš€
 
3
  A **FastAPI-based RAG application** that lets users upload documents (PDF/TXT) and ask questions.
4
  Powered by **LangChain**, **ChromaDB**, and **LLMs** for context-aware answers.
5
 
6
+ ## πŸ“š FastAPI RAG App with LangChain, ChromaDB & Authentication
7
 
8
  This project is a Retrieval-Augmented Generation (RAG) web application built with FastAPI.
9
  It allows users to:
10
 
11
+ - πŸ”‘ Sign up / Sign in (JWT-based authentication)
12
 
13
+ - πŸ“‚ Upload PDF or text documents
14
 
15
+ - 🧠 Store document embeddings in ChromaDB (vector database)
16
 
17
+ - πŸ’¬ Ask questions about uploaded documents
18
 
19
+ - ⚑ Get context-aware answers powered by LangChain + LLMs (via OpenRouter
20
  )
21
 
22
+ ## πŸš€ Features
23
 
24
+ - User authentication with access & refresh tokens
25
 
26
+ - Secure file uploads (.pdf, .txt)
27
 
28
+ - Automatic text chunking & embedding with HuggingFace models
29
 
30
+ - Persistent vector store using ChromaDB
31
 
32
+ - RAG pipeline with LangChain’s RetrievalQA
33
 
34
+ - OpenRouter integration for running LLM queries
35
 
36
+ - CORS configured for frontend integration
37
 
38
+ ## πŸ› οΈ Tech Stack
39
 
40
+ - FastAPI
41
 
42
+ - LangChain
43
 
44
+ - ChromaDB
45
 
46
+ - SQLModel
47
+ - - for user database
48
 
49
+ - HuggingFace Embeddings
50
 
51
+ - OpenRouter
52
+ - - (for LLM access)
53
 
54
+ ## πŸ“‚ Project Structure
55
  app/
56
  β”œβ”€β”€ main.py # FastAPI routes & entrypoint
57
  β”œβ”€β”€ rag.py # RAG pipeline (embeddings, vector store, QA chain)
 
62
  uploads/ # User uploaded files (ignored in Git)
63
  chroma_db/ # Vector DB storage (ignored in Git)
64
 
65
+ ## βš™οΈ Setup & Installation
66
+ - 1️⃣ Clone the repo
67
+ - - git clone https://github.com/your-username/fastapi-rag-app.git
68
+ - - cd fastapi-rag-app
69
 
70
+ - 2️⃣ Create & activate virtual environment
71
+ - - python -m venv venv
72
+ - - source venv/bin/activate # Linux/Mac
73
+ - - venv\Scripts\activate # Windows
74
 
75
+ - 3️⃣ Install dependencies
76
+ - - pip install -r requirements.txt
77
 
78
+ - 4️⃣ Configure environment variables
79
 
80
+ - - Create a .env file in the project root (or copy from .env.example):
81
 
82
+ - - ### OpenRouter
83
+ - - OPENROUTER=your_openrouter_api_key_here
84
 
85
+ - - ### JWT secret
86
+ - - SECRET_KEY=your_super_secret_key
87
 
88
+ - - ⚠️ Never commit your real .env file.
89
 
90
+ - ▢️ Run the App
91
 
92
+ - - Start the FastAPI server:
93
 
94
+ - - uvicorn app.main:app --reload
95
 
96
 
97
+ - - The API will be available at:
98
+ - - - πŸ‘‰ http://127.0.0.1:8000
99
 
 
 
100
 
101
+ - ## πŸ”‘ Authentication Flow
102
 
103
+ - - Signup β†’ POST /signup with username & password
104
 
105
+ - - Signin β†’ POST /signin to receive access_token & refresh_token
106
 
107
+ - - Use Authorization: Bearer <access_token> for protected endpoints
108
 
109
+ - ## πŸ“‚ Document Workflow
110
 
111
+ - - User logs in
112
 
113
+ - - Upload document β†’ POST /upload (PDF or TXT)
114
 
115
+ - - Ask a question β†’ GET /ask?q=your+question
116
 
117
+ - - The system searches your embeddings in ChromaDB and queries the LLM with context
118
 
119
+ - ## πŸ“ Notes
120
 
121
+ - - uploads/ and chroma_db/ are auto-created at runtime if they don’t exist.
122
 
123
+ - - Both folders are ignored by Git (runtime data only).
124
 
125
+ - - Contributions & pull requests are welcome πŸš€
app/config.py CHANGED
@@ -1,2 +1,7 @@
 
 
 
 
 
1
  # Vector DB storage
2
  CHROMA_DB_DIR = "./chroma_db"
 
1
+ import os
2
+
3
+ # Embedding model
4
+ EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
5
+
6
  # Vector DB storage
7
  CHROMA_DB_DIR = "./chroma_db"
app/rag.py CHANGED
@@ -8,9 +8,11 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
8
  from langchain_community.document_loaders import TextLoader
9
  from langchain.document_loaders import PyPDFLoader
10
  from langchain.text_splitter import CharacterTextSplitter
11
- from app.config import CHROMA_DB_DIR
12
  from langchain.chat_models import ChatOpenAI
13
  from langchain.chains import RetrievalQA
 
 
14
 
15
  from dotenv import load_dotenv
16
  load_dotenv()
@@ -23,7 +25,6 @@ embeddings = HuggingFaceEmbeddings(model_name=EMBEDDING_MODEL)
23
  # Chroma DB
24
  db = Chroma(persist_directory=CHROMA_DB_DIR, embedding_function=embeddings)
25
 
26
- from langchain.docstore.document import Document
27
 
28
  def add_document(file_path: str, user_id: str):
29
  # Load file
 
8
  from langchain_community.document_loaders import TextLoader
9
  from langchain.document_loaders import PyPDFLoader
10
  from langchain.text_splitter import CharacterTextSplitter
11
+ from app.config import CHROMA_DB_DIR, EMBEDDING_MODEL
12
  from langchain.chat_models import ChatOpenAI
13
  from langchain.chains import RetrievalQA
14
+ from langchain.docstore.document import Document
15
+
16
 
17
  from dotenv import load_dotenv
18
  load_dotenv()
 
25
  # Chroma DB
26
  db = Chroma(persist_directory=CHROMA_DB_DIR, embedding_function=embeddings)
27
 
 
28
 
29
  def add_document(file_path: str, user_id: str):
30
  # Load file