This repository contains a retrieval-based Question and Answer (Q&A) system that uses ChromaDB and sentence embeddings to retrieve the most relevant response for a user's query. The application provides a simple user interface built with Streamlit and processes user queries using a pre-trained SentenceTransformer model.
- Streamlit UI: A user-friendly interface for submitting queries and displaying results.
- ChromaDB Integration: Persistent vector database to store and retrieve embeddings for question-answer pairs.
- Preprocessing: Automatic text preprocessing for consistent query handling.
- Top-k Retrieval: Retrieves the top-k relevant responses for a given user query.
Retrieval/
βββ Data/
β βββ Raw Data/
β β βββ chatbot_basic_conversations.json
β βββ Chroma DB/
β β βββ chatbot basic conversations/
βββ setup_chromDB.py
βββ chromaDB_query_handler.py
βββ retrieval_ui.py
- Clone this repository:
git clone https://github.com/augustine-aj/RAG-basics.git
cd RAG-basics/Retrieval
- Install required dependencies:
pip install -r requirements.txt
- Run the setup script to initialize ChromaDB and load the Q&A pairs:
python setup_chromaDB.py
- Start the Streamlit application:
streamlit run retrieval_ui.py
Open the URL provided by Streamlit in your browser (e.g., http://localhost:8501).
-
Interact with the application:
- Enter your query in the input box.
- Click Get Response to see the retrieved answer.
retrieval_ui.py
-
Provides a graphical user interface for users to interact with the Q&A system.
-
Displays the retrieved answer based on the input query.
setup_chromaDB.py
-
Loads the Q&A pairs from the JSON file.
-
Encodes questions using a pre-trained SentenceTransformer model.
-
Stores embeddings and metadata in a ChromaDB collection.
chromaDB_query_handler.py
-
Handles user queries by encoding them into embeddings and querying ChromaDB for the most relevant responses.
-
Implements utility functions like setup_chroma_client() and retrieve_documents().
- Error Handling: Improve error handling for missing files or incorrect input formats.
- Scalability: Optimize embedding storage and retrieval for larger datasets.
- Advanced Retrieval: Add semantic search capabilities for complex queries.
- Web Scraping: Dynamically update the Q&A database with web-scraped data.
- Multilingual Support: Extend support for queries in multiple languages.
Welcome to the Ollama 3.2 ChatBot repository! This project features an interactive chatbot built using Streamlit for the web interface and OllamaLLM (Langchain integration with Ollama 3.2) for generating intelligent responses. The bot now has simple conversational memory, where new responses are generated using the past 5 interactions to maintain context.
- Project Overview
- Features
- Installation
- Running the Application
- Project Structure
- Example Interaction
- Contributing
This project provides a conversational chatbot powered by Ollama 3.2. It utilizes Langchain for the integration and Streamlit for the web interface, allowing users to interact with the chatbot in real time. The bot retains a conversation history and provides meaningful responses based on the context of the dialogue.
New Feature: The bot now uses simple conversational memory. This means that each new response is generated based on the last 5 interactions, making the conversation feel more connected and contextually aware.
- Interactive Chatbot: Users can interact with the chatbot and ask questions.
- Context-Aware Responses: The bot retains the conversation history (last 5 interactions) to generate more relevant and coherent answers.
- Streamlit Interface: A user-friendly web interface to interact with the chatbot.
- Response Generation: The chatbot uses Ollama 3.2 LLM to generate detailed, intelligent answers based on user queries.
To run the chatbot, you need Python 3.x installed on your local machine.
You also need to install the following tools:
- Ollama 3.2: The chatbot relies on this model for generating responses. Follow the Ollama Setup Guide for installing Ollama models on your local system.
- Langchain: A Python library used for integrating the Ollama model.
- Streamlit: A library used for building the web interface.
- Clone this repository:
git clone https://github.com/augustine-aj/RAG-basics.git
cd RAG-basics/Generator Model
You can install the required dependencies by using the requirements.txt
file in this repository.
Run the following command in your terminal:
pip install -r requirements.txt
This will install all the necessary libraries, including langchain
and streamlit
.
To use the Ollama 3.2 model locally, you need to install it on your system. Follow these steps:
- 1. Install Ollama: You can install Ollama by following the official installation guide on the Ollama website.
- 2. Download the LLM Model: Ensure that the
llama3.2
model is available and set up on your local machine.If it not downloaded then dowload it from here.
1. Start the Streamlit App: To run the chatbot interface, execute the following command in the terminal:
streamlit run chatbot.py
2. Access the ChatBot: Once the app is running, open the provided URL (usually http://localhost:8501
) in your browser to start interacting with the chatbot.
3. Chat with the Bot: Type your message into the text input field, and the bot will respond based on the context of the conversation.
The project consists of two main files:
response_generation.py
: Handles the logic for generating chatbot responses using the Ollama 3.2 model. The new responses are based on the most recent 5 interactions in the chat history.chatbot.py
: Sets up the Streamlit interface and manages the conversation flow, using the response generation fromresponse_generation.py
.
Note: The response generated is based on the recent conversation history (last 5 interactions), making the responses contextually more relevant.
Feel free to fork the repository, submit issues, and contribute to improving the chatbot! Contributions are always welcome.
Welcome to the Ollama 3.2 ChatBot project! π This chatbot application utilizes a locally hosted Ollama 3.2 Language Model (LLM) for generating intelligent and engaging responses, supported by a vector database (ChromaDB) for retrieving relevant information from a predefined knowledge base. The application is built with Streamlit, offering an interactive and user-friendly web interface. π¬
- Semantic Search: Incorporates advanced semantic search capabilities using ChromaDB to retrieve the most relevant information based on user queries. This ensures accurate and context-aware results. π
- Session-Aware Responses: Tracks the current session's chat history to generate interactive and contextually rich responses, enhancing the overall user experience. π‘
- Dynamic Interaction: Leverages the combination of semantic search and session tracking to provide more meaningful and conversational answers that adapt to the flow of the dialogue. π¨οΈ
- Local LLM Integration: The chatbot uses Ollama 3.2, a locally hosted language model, for generating responses. π€
- ChromaDB Integration: Utilizes ChromaDB, a vector database, to store and retrieve Q&A pairs based on embeddings. ποΈ
- Predefined Knowledge Base: Supports easy customization of the knowledge base data in JSON format for seamless updates. π
- Interactive UI: A clean and user-friendly interface built with Streamlit for smooth interaction. π¨
- Response Ranking: Ranks retrieved documents based on relevance and generates fallback responses when relevant data is unavailable. π
.
βββ Data
β βββ ChromaDb
β β βββ chatbot_basic_conversations
β βββ Raw Data
β βββ chatbot_basic_conversations.json
βββ setup_chromaDB.py
βββ chromaDB_query_handler.py
βββ response_generation.py
βββ rag_app.py
βββ requirements.txt
βββ README.md
-
setup_chromDB.py:
- Initializes the ChromaDB client. ποΈ
- Loads Q&A pairs from a JSON file and stores them in the database. π
-
chromaDB_query_handler.py:
- Handles querying ChromaDB to retrieve relevant documents. π
- Automatically initializes and populates the database if it's missing. βοΈ
-
response_generation.py:
- Generates responses using the retrieved documents and the Ollama 3.2 model. π§
- Implements document ranking and fallback mechanisms. π
-
rag_app.py:
- A Streamlit-based web application for user interaction. π»
- Displays retrieved documents, chat history, and generated responses. π¨οΈ
Before you start, make sure you have the following installed:
- Python 3.8+ β¬οΈ
- Required Python Libraries:
streamlit
πchromadb
ποΈsentence_transformers
πlangchain_ollama
π€
- Ollama 3.2 installed locally on your machine π₯οΈ
First, clone the repository to your local machine:
git clone https://github.com/augustine-aj/RAG-Basics/llama 3.2b rag app.git
cd llama 3.2b rag app
Install the required Python libraries:
pip install -r requirements.txt
The requirements.txt
file includes the following libraries:
streamlit
chromadb
sentence_transformers
langchain_ollama
Make sure the JSON file containing Q&A pairs (chatbot_basic_conversations.json) is present in the Data/Raw Data directory. π
Start the chatbot application with:
streamlit run rag_app.py
- Open the application in your browser (the URL will be provided in the terminal after running Streamlit). π
- Type your query into the chat box. π±οΈ
- View retrieved documents, chat history, and generated responses in the interface. π
- Responses are generated based on the knowledge base stored in ChromaDB. π
- Ensure that Ollama 3.2 is installed and running locally for the chatbot to work properly. π₯οΈ
- The quality of responses is dependent on the data in your knowledge base (ChromaDB). π
- Responses may take a few seconds due to resource constraints. β³
π License This project is licensed under the MIT License. See the LICENSE file for details. π
Augustine Joseph πΌ
- π§ Email: augustine04849@gmail.com
- π± GitHub: @augustine-aj
- π LinkedIn: linkedin.com/in/augustine-aj
Enjoy building and interacting with your Ollama 3.2 ChatBot! π