This project showcases an advanced chatbot system built with Flask, Pinecone, RAG(Retrieval-Augmented Generation) and Langchain. It leverages OpenAI embeddings for semantic understanding and integrates a retrieval-based chat system with agents and memory capabilities to handle complex conversations and follow-up questions. The system is designed to retrieve relevant information from a Pinecone vector store and utilize SerpAPI for fetching web search results when necessary.
The response generated with our model using Langchain, OpenAI, RAG
![Chat Memory Example](https://private-user-images.githubusercontent.com/84759422/341966887-c32cbcd2-74c8-4e8f-be9f-78c6fb518f69.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4Mjk2OTIsIm5iZiI6MTcyMDgyOTM5MiwicGF0aCI6Ii84NDc1OTQyMi8zNDE5NjY4ODctYzMyY2JjZDItNzRjOC00ZThmLWJlOWYtNzhjNmZiNTE4ZjY5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEzVDAwMDk1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTljODQwMmYyNmE0NDkwM2Q1NjZhODk0ZGFkMzI1Njg3ZmIzNzE5MmMwYjljNDU5ODE5ZTZiNTgzMmNlNzM5ZTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.8ehdvG7rlLCGN3VBRBYDA1gtItTODPKXASflnJUTnJI)
Able to catch the memory, as I have not specified the drugs for which disease, competent to comprehend chat history.
![Web Search Example](https://private-user-images.githubusercontent.com/84759422/341967003-15465ed2-fee0-467d-bd3e-136231a3d29b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4Mjk2OTIsIm5iZiI6MTcyMDgyOTM5MiwicGF0aCI6Ii84NDc1OTQyMi8zNDE5NjcwMDMtMTU0NjVlZDItZmVlMC00NjdkLWJkM2UtMTM2MjMxYTNkMjliLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEzVDAwMDk1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVhNDAxODY1NzA2MGVlY2E2ZTczN2RmZmJhMjY1ZjEwZDVlNWU0ODMzMmMyNGQzNDc3MGQ1ZDQ2NzFiOWY0NjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fyRn8TA0PKKpqC86VJ7Dht3K3e6-OlrYDNKq7wxb-vM)
If the chatbot cannot find the response from the given data, our Serp-API agents come into play and give you the web search results.
![Reduced Image Size Example](https://private-user-images.githubusercontent.com/84759422/341967202-553e6f54-fa2c-43b4-b519-10b6964ff33a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4Mjk2OTIsIm5iZiI6MTcyMDgyOTM5MiwicGF0aCI6Ii84NDc1OTQyMi8zNDE5NjcyMDItNTUzZTZmNTQtZmEyYy00M2I0LWI1MTktMTBiNjk2NGZmMzNhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEzVDAwMDk1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEzYzkyMzE0NzAzNGFkN2FjN2YyOTg1N2Y5YWY0MDg5NGEwNWQwMmMwMzc1MDdhNDJjMjk4MGYxZDk4ZDc3ZmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PYz4lrVpgeoDH859XL0IkrK_a1EGPnA6E_B9XHtwSO0)
- Conversational AI: Harnesses the power of
RAG
alongsideLangchain
andOpenAI's LLM
to craft nuanced and contextually relevant responses, generating coherent and context-aware responses. - Information Retrieval: Utilizes Pinecone for efficient storage and retrieval of document embeddings, enabling the chatbot to fetch relevant information based on user queries.
- Semantic Understanding: Incorporates OpenAI embeddings to comprehend the nuances of user inputs, enhancing the accuracy of retrieved information.
- Agent Integration: Implements custom agents for specialized functionalities, such as leveraging SerpAPI to fetch web search results when the internal knowledge base is insufficient.
- Memory Management: Equipped with a memory component that allows the chatbot to remember past interactions and ask follow-up questions, improving the flow of conversations.
- Frontend: HTML, CSS, Bootstrap
- Backend: Flask
- Vector Storage: Pinecone
- Natural Language Processing: Langchain, OpenAI, RAG
- Search API: SerpAPI
- Open your terminal or command prompt.
- Navigate to the project directory.
- Run
python -m venv venv
to create a virtual environment namedvenv
.
- On Windows, run
.\venv\Scripts\activate
. - On macOS/Linux, run
source venv/bin/activate
.
Run pip install -r requirements.txt
to install all necessary packages.
Create a .env
file in the root of your project and add the following lines:
OPENAI_API_KEY="your_openai_api_key_here"
PINECONE_API_KEY="your_pinecone_api_key_here"
PINECONE_API_ENV="your_pinecone_api_env_here"
SERPAPI_KEY="your_serpapi_key_here"
INDEXNAME="your_index_name_here"
Replace the placeholders with your actual API keys and environment-specific values.
- To change the user image, replace the existing
profile.jpeg
in thestatic/img
folder with your desired image. - Ensure the image name remains
profile.jpeg
for consistency.
- To use the default medical chatbot, simply run
python app.py
in your terminal. - For a customized chatbot, add or append your data in PDF format to the
data
folder. - Run
python store_index.py
to update your vector database and store its embeddings. - Finally, run
python app.py
again to see the customized results.
- Access the chatbot by navigating to
http://localhost:5000/
. - Interact with the chatbot by typing your queries in the input field and pressing Enter to receive responses.
Contributions are welcome. Feel free to submit pull requests or open issues for discussions.