sothulthorn/LLM-powered-chatbot
A hands-on project exploring LangChain's core capabilities through two interactive Jupyter notebooks: a conversational chatbot with session memory and a retrieval-augmented generation (RAG) pipeline using vector stores.
LLM-Powered Chatbot
A hands-on project exploring LangChain's core capabilities through two interactive Jupyter notebooks: a conversational chatbot with session memory and a retrieval-augmented generation (RAG) pipeline using vector stores.
Project Structure
LLM-powered-chatbot/
├── chatbots.ipynb # Conversational chatbot with message history
├── vectorretriever.ipynb # Vector store, retrievers, and RAG pipeline
├── requirements.txt # Python dependencies
├── .env # API keys (not tracked by git)
└── .gitignore
Notebooks
1. Chatbots (chatbots.ipynb)
Builds a conversational chatbot powered by Groq's Llama 3.1 model. Covers:
- Basic chat — Sending and receiving messages with
ChatGroq. - Message history — Using
RunnableWithMessageHistoryandChatMessageHistoryto maintain separate conversation sessions via session IDs. - Prompt templates — Structuring system instructions and user messages with
ChatPromptTemplateandMessagesPlaceholder. - Multi-language support — Parameterizing the prompt to respond in a specified language.
- Conversation trimming — Managing context window limits with
trim_messagesto keep only the most recent messages.
2. Vector Store & Retrievers (vectorretriever.ipynb)
Demonstrates LangChain's retrieval abstractions for RAG workflows. Covers:
- Documents — Creating
Documentobjects with content and metadata. - Embeddings — Generating vector embeddings using HuggingFace's
all-MiniLM-L6-v2model. - Vector store — Storing and querying documents with Chroma (similarity search, scored search, async search).
- Retrievers — Wrapping vector stores as LangChain
Runnableobjects for use in LCEL chains. - RAG chain — Combining a retriever, prompt template, and LLM into a full retrieval-augmented generation pipeline.
Prerequisites
- Python 3.12+
- A Groq API key
- A HuggingFace token (for the embeddings model)
Setup
-
Clone the repository
git clone https://github.com/sothulthorn/LLM-powered-chatbot.git cd LLM-powered-chatbot -
Create and activate a virtual environment
python -m venv .venv # Windows .venv\Scripts\activate # macOS / Linux source .venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Create a
.envfile in the project root:GROQ_API_KEY=your_groq_api_key HF_TOKEN=your_huggingface_token -
Run the notebooks
jupyter notebook
Open either
chatbots.ipynborvectorretriever.ipynbto get started.
Key Technologies
| Technology | Purpose |
|---|---|
| LangChain | LLM application framework |
| Groq | LLM inference (Llama 3.1) |
| Chroma | Vector database |
| HuggingFace | Text embeddings (all-MiniLM-L6-v2) |
| python-dotenv | Environment variable management |
License
This project is for educational purposes.