This project is a Flask-based chatbot application that uses advanced language model techniques to handle user queries. The chatbot is designed to route user questions to appropriate data sources, retrieve relevant information, and generate contextually accurate responses. The application leverages LangGraph for Retrieval-Augmented Generation (RAG), allowing for enhanced interactions based on the Indian Constitution documents. Heres the graph generated
- Language Model Integration: Uses Google Generative AI for processing user queries and generating responses.
- Vector Store: Utilizes AstraDB as the vector store to store and retrieve relevant documents from the Indian Constitution.
- Routing and Grading: The chatbot can route questions to different data sources and assess the relevance of retrieved documents.
- Query Transformation: Improves user queries for better retrieval results.
- Document- Grading: Detects and Grades the retrived Documents.
- Flask: A lightweight WSGI web application framework used for building the chatbot's backend.
- LangGraph: For creating a state graph that defines the workflow for handling user queries.
- Google Generative AI: Used for language model tasks like question routing, document retrieval, and response generation.
- AstraDB: A managed database service that stores the vectorized representations of documents.
- Python 3.7+
- Pip (Python package installer)
- Flask
- AstraDB account and vector store setup
- Google Generative AI API access
-
Clone the Repository:
git clone https://github.com/yourusername/flask-chatbot-langgraph.git cd flask-chatbot-langgraph
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
Create a
.env
file in the project root directory and add the following variables:GOOGLE_API_KEY=your_google_api_key ASTRA_API_KEY=your_astra_api_key DB_ENDPOINT=your_astra_db_endpoint DB_ID=your_astra_db_id LANGCHAIN_API_KEY=your_langchain_api_key
-
Run the Application:
python app.py
- The chatbot interface is served by Flask and can be accessed via a web browser. It features a clean, responsive design, allowing users to interact with the bot by typing their questions.
- LangGraph Integration:
- Routing: Determines whether the user's query should be routed to a vector store containing Indian Constitution documents or handled as an out-of-context query.
- Document Retrieval: Fetches relevant documents from AstraDB based on the user's query.
- Query Transformation: If the retrieved documents are not relevant, the query is refined for better retrieval.
- Response Generation: Generates a response using the retrieved documents and the Google Generative AI model.
- Answer Grading: Grades the generated response to determine if it resolves the user's query.
When a user submits a question, the following steps are executed:
- Routing: The question is analyzed to decide if it should be routed to the vector store or handled as out-of-context.
- Document Retrieval: Relevant documents are retrieved from the AstraDB vector store.
- Query Transformation: If necessary, the query is refined and reprocessed.
- Response Generation: A response is generated based on the retrieved documents.
- Answer Grading: The response is graded to ensure it adequately addresses the query.
If the response is deemed useful, it is returned to the user. Otherwise, the query is transformed, and the process is repeated.
Contributions are welcome! Feel free to submit issues, fork the repository, and make pull requests. Please ensure that your contributions align with the project's objectives and coding standards.