Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python Groq Llama ChromaDB LangChain RAG Embeddings

πŸ“š Local PDF RAG

A production-ready Retrieval-Augmented Generation (RAG) application built using Python, Groq API, Llama 3.3, LangChain, ChromaDB, and HuggingFace Embeddings.

The application converts PDF documents into a searchable vector database and enables users to ask natural language questions grounded in the document content using semantic retrieval and LLM-powered answer generation.

This project demonstrates the complete RAG pipeline used in modern AI applications, including document ingestion, chunking, embeddings, vector search, retrieval, prompt engineering, and LLM inference.


πŸš€ Features

  • πŸ“„ Load one or multiple PDF documents
  • βœ‚οΈ Intelligent document chunking
  • 🧠 Local HuggingFace Embeddings
  • πŸ—„οΈ ChromaDB Vector Database
  • πŸ” Semantic Similarity Search
  • πŸ“š Retrieval-Augmented Generation (RAG)
  • πŸ€– Groq Llama 3.3 Integration
  • πŸ’¬ Interactive CLI Chat Interface
  • ⚑ Fast Vector Retrieval
  • 🧩 Modular Project Architecture
  • πŸ” Secure API Key Management using Environment Variables

πŸ—οΈ Architecture

                    PDF Documents
                          β”‚
                          β–Ό
                PyMuPDF Document Loader
                          β”‚
                          β–Ό
          Recursive Character Text Splitter
                          β”‚
                          β–Ό
           HuggingFace Embedding Model
                          β”‚
                          β–Ό
                Chroma Vector Database
                          β”‚
                    User Question
                          β”‚
                          β–Ό
               Embed User Question
                          β”‚
                          β–Ό
             Semantic Similarity Search
                          β”‚
                          β–Ό
              Retrieve Top-K Chunks
                          β”‚
                          β–Ό
         Prompt Engineering with Context
                          β”‚
                          β–Ό
             Groq (Llama 3.3 70B)
                          β”‚
                          β–Ό
                  Grounded AI Answer

πŸ“‚ Project Structure

local-pdf-rag/
β”‚
β”œβ”€β”€ data/                     # PDF documents
β”œβ”€β”€ chroma_db/                # Vector database (generated)
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ loader.py             # PDF loading
β”‚   β”œβ”€β”€ splitter.py           # Document chunking
β”‚   └── embeddings.py         # Embedding model
β”‚
β”œβ”€β”€ ingest.py                 # Creates ChromaDB
β”œβ”€β”€ rag.py                    # Retrieval pipeline
β”œβ”€β”€ app.py                    # CLI interface
β”œβ”€β”€ config.py                 # Configuration
β”‚
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
└── README.md

πŸ› οΈ Tech Stack

Component Technology
Language Python
LLM Provider Groq API
Model Llama 3.3 70B Versatile
Framework LangChain
Vector Database ChromaDB
Embeddings HuggingFace Sentence Transformers
PDF Loader PyMuPDF
Text Splitting RecursiveCharacterTextSplitter
Environment Variables python-dotenv

πŸ“¦ Installation

1. Clone Repository

git clone https://github.com/your-username/local-pdf-rag.git

cd local-pdf-rag

2. Create Virtual Environment

python -m venv venv

Windows

venv\Scripts\activate

Linux / Mac

source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

πŸ”‘ Environment Setup

Create a .env file.

GROQ_API_KEY=your_groq_api_key

πŸ“„ Add PDFs

Place your PDF files inside:

data/

πŸ—οΈ Build the Vector Database

Run:

python ingest.py

This will:

  • Load PDFs
  • Split text into chunks
  • Generate embeddings
  • Store vectors inside ChromaDB

▢️ Run the Application

python app.py

Example:

You:
What is Retrieval Augmented Generation?

Assistant:
Retrieval-Augmented Generation (RAG) is...

πŸ’‘ How It Works

  1. Load PDF documents.
  2. Extract text using PyMuPDF.
  3. Split documents into overlapping chunks.
  4. Generate embeddings using HuggingFace.
  5. Store embeddings in ChromaDB.
  6. User asks a question.
  7. The question is embedded.
  8. ChromaDB retrieves the most relevant chunks.
  9. Retrieved context is inserted into a prompt.
  10. Groq's Llama 3.3 generates a grounded response.

🧠 Key Concepts Learned

πŸ“„ PDF Processing

Extracting structured text from PDF documents.

βœ‚οΈ Text Chunking

Breaking large documents into overlapping chunks for better retrieval.

🧠 Embeddings

Converting text into dense vector representations for semantic similarity.

πŸ—„οΈ Vector Database

Efficient storage and retrieval of document embeddings using ChromaDB.

πŸ” Semantic Search

Finding relevant information based on meaning instead of keyword matching.

πŸ“š Retrieval-Augmented Generation (RAG)

Combining retrieval with LLM inference to generate grounded answers.

πŸ€– LLM Integration

Using Groq's ultra-fast inference API with Llama 3.3.

🧠 Prompt Engineering

Injecting retrieved context into prompts to reduce hallucinations.

πŸ—οΈ Modular AI Applications

Separating ingestion, retrieval, embeddings, and inference into reusable components.


πŸš€ Future Improvements

  • πŸ“‘ Source citations (PDF & page numbers)
  • 🎯 Metadata filtering
  • πŸ”€ Hybrid Search (Keyword + Semantic)
  • πŸ“ˆ MMR Retrieval
  • πŸ’¬ Conversation Memory
  • 🌐 Streamlit Web Interface
  • ⚑ FastAPI REST API
  • 🐳 Docker Support
  • ☁️ Cloud Deployment
  • πŸ“š Multi-user document collections

⚠️ Limitations

  • Supports PDF documents only.
  • Requires rebuilding the vector database when documents change.
  • Responses depend on retrieval quality.
  • Internet connection required for Groq API inference.

πŸ“š Learning Outcomes

After building this project, you understand:

  • Retrieval-Augmented Generation (RAG)
  • Vector databases
  • Semantic search
  • Embeddings
  • ChromaDB
  • LangChain
  • HuggingFace Embeddings
  • Prompt Engineering
  • Groq API integration
  • LLM application architecture
  • Document Question Answering
  • Modular AI system design

🀝 Contributing

Contributions are welcome!

Possible improvements:

  • Better retrieval strategies
  • Improved prompt templates
  • UI development
  • Additional document formats
  • Multi-model support
  • Performance optimization

⭐ Acknowledgements

  • Groq for ultra-fast LLM inference
  • Meta for the Llama models
  • LangChain for orchestration
  • ChromaDB for vector storage
  • HuggingFace for embedding models
  • PyMuPDF for PDF parsing

πŸ‘¨β€πŸ’» Author

Built as a hands-on learning project while exploring Retrieval-Augmented Generation (RAG), Large Language Models (LLMs), Vector Databases, Semantic Search, Prompt Engineering, and Production-Ready AI Systems.

About

A production-ready Local PDF RAG application built with Python, Groq, ChromaDB, and HuggingFace Embeddings for semantic document search and grounded question answering.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages