A simple Retrieval-Augmented Generation (RAG) app built with Streamlit, OpenAI embeddings, and FAISS.
Upload your PDFs or text files, build a vector index, and then chat with your documents — with inline citations.
- 📂 Upload PDFs / TXT / MD files
- ✂️ Chunking + overlap for context preservation
- 🔎 FAISS vector search for fast semantic retrieval
- 🤖 OpenAI embeddings (
text-embedding-3-small) - 💬 LLM-powered answers with citations using GPT (
gpt-4o-mini) - ⚙️ Customizable settings for chunk size, overlap, and top-k retrieval
git clone https://github.com/your-username/rag-ai-agent.git
cd rag-ai-agent
python -m venv venv
source venv/bin/activate
venv\Scripts\activate
.\venv\Scripts\Activate.ps1
pip install -r requirements.txt
Create a .env file in the project root with your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
Run the app with Streamlit:
streamlit run app.py
Then open the link in your browser (usually http://localhost:8501).
- Upload documents → PDFs, TXT, or MD files.
- Chunking & overlap → Long text is split into smaller overlapping chunks (default: 900 chars, 150 overlap).
- Embedding → Each chunk is embedded using OpenAI (
text-embedding-3-small). - Indexing → FAISS stores and searches embeddings efficiently.
- Querying → User query is embedded, matched with top-k chunks.
- Answering → GPT (
gpt-4o-mini) generates a response using only retrieved chunks, citing sources inline.
You can configure these in the Streamlit sidebar:
- Top-K Chunks → how many chunks to retrieve per query (default: 5).
- Chunk Size → maximum characters per chunk (default: 900).
- Overlap → number of overlapping characters between chunks (default: 150).
Upload a contract PDF and ask:
"What’s the termination clause?"
The app responds with:
"The contract may be terminated with 30 days’ notice [contract.pdf p.4]."
- Python 3.9+
- Dependencies (listed in
requirements.txt):- streamlit
- openai
- faiss-cpu
- pypdf
- python-dotenv
- numpy