Retrieval-Augmented Generation (RAG) over your own PDF documents — powered by FAISS, SentenceTransformers, and Groq's blazing-fast LLaMA-3 inference.
Drop in any PDF documents, ask questions in plain English, and get grounded, cited answers — without hallucination-prone LLMs making things up. The system retrieves the most relevant passages from your documents before generating a response.
You: "What are the key findings in Q3?"
Bot: "According to page 4 of report.pdf: ..."
INGESTION (ingest.py)
docs/*.pdf → PyPDF → Text Chunks → SentenceTransformers
↓
FAISS Index (disk)
┌─────────────────────────────────────────────────────────────┐
│ QUERY (rag_pipeline.py) │
│ │
│ User Question → Embed Query → FAISS Search (top-3) │
│ ↓ │
│ Structured Prompt → Groq API (LLaMA-3 8B) → Answer │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ UI (app.py) │
│ │
│ Streamlit → Text Input → RAGPipeline.query() │
│ ↓ │
│ Answer + Retrieved Chunks + Source Citations │
└─────────────────────────────────────────────────────────────┘
| Component | Technology |
|---|---|
| PDF Parsing | PyPDF |
| Embeddings | sentence-transformers (all-MiniLM-L6-v2) |
| Vector Store | FAISS (persisted to disk) |
| LLM Inference | Groq API — LLaMA-3 8B |
| UI | Streamlit |
git clone https://github.com/your-username/docrag.git
cd docrag
pip install -r requirements.txtexport GROQ_API_KEY="your_groq_api_key_here"Get a free key at console.groq.com.
mkdir docs
cp /path/to/your/files/*.pdf docs/python ingest.pyThis reads all PDFs in docs/, chunks the text, generates embeddings, and saves a FAISS index to faiss_index/.
streamlit run app.pyOpen http://localhost:8501 and start asking questions.
docrag/
├── docs/ # 📂 Place your PDF files here
├── faiss_index/ # 🗄️ Auto-generated vector index (git-ignored)
├── ingest.py # 🔄 PDF → chunks → embeddings → FAISS
├── rag_pipeline.py # 🧠 Query embedding + retrieval + LLM call
├── app.py # 🖥️ Streamlit UI
├── requirements.txt
└── README.md
Key parameters can be tuned at the top of each script:
| Parameter | Location | Default | Description |
|---|---|---|---|
CHUNK_SIZE |
ingest.py |
512 |
Characters per text chunk |
CHUNK_OVERLAP |
ingest.py |
64 |
Overlap between chunks |
TOP_K |
rag_pipeline.py |
3 |
Number of chunks retrieved per query |
MODEL |
rag_pipeline.py |
llama3-8b-8192 |
Groq model name |
EMBEDDING_MODEL |
ingest.py |
all-MiniLM-L6-v2 |
SentenceTransformer model |
Ingestion
- PyPDF reads every
.pdfindocs/and extracts raw text page by page. - Text is split into overlapping chunks to preserve context across boundaries.
- Each chunk is embedded using
SentenceTransformersinto a 384-dimensional vector. - All vectors are stored in a FAISS flat index and saved to disk.
Querying
- The user's question is embedded with the same model used during ingestion.
- FAISS performs an approximate nearest-neighbour search, returning the top-3 most semantically similar chunks.
- Those chunks are injected into a structured prompt alongside the question.
- Groq's API runs inference on LLaMA-3 8B and streams back the answer.
UI
- Streamlit renders a text input and a submit button.
- On submit,
RAGPipeline.query()is called and the answer, retrieved chunks, and source filenames are displayed.
streamlit
pypdf
sentence-transformers
faiss-cpu
groq
Install all at once:
pip install -r requirements.txtNote: Use
faiss-gpuinstead offaiss-cpuif you have a CUDA-capable GPU for faster indexing and search.
Whenever you add or remove PDFs, re-run ingestion to rebuild the index:
python ingest.pyThe old index in faiss_index/ will be overwritten.
Contributions are welcome! Please open an issue first to discuss what you'd like to change, then submit a pull request.
- Fork the repo
- Create your branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add my feature') - Push and open a PR
This project is licensed under the MIT License. See LICENSE for details.
- Groq for ultra-low-latency LLaMA-3 inference
- FAISS by Meta AI Research
- Sentence Transformers by UKP Lab
- Streamlit for the frictionless UI