This project is an AI-powered chatbot that provides customer support by answering questions about a judicial circular. The chatbot is designed with a microservices architecture, allowing modular development and scalability. It leverages Retrieval-Augmented Generation (RAG) to retrieve relevant information and generate context-aware responses.
The project consists of the following services:
-
Frontend: A React application styled with TailwindCSS, providing an interactive user interface to chat with the AI-powered assistant.
-
Service2 (API Gateway): A FastAPI-based backend that acts as a communication bridge between the frontend and Service3. It also manages user interaction history.
-
Service3 (Chatbot Engine): Another FastAPI-based backend hosting the chatbot logic. It uses LangChain and OpenAI’s API to retrieve information from the circular and generate accurate responses.
-
Redis: A Redis server used as a vector database for state management and caching.
-
Postgres (pgvector): A PostgreSQL server with pgvector extension, used for storing embeddings of the circular’s text to optimize retrieval operations.
This project follows a microservices-based architecture, which simulates a real-world software development environment. Each service is containerized using Docker for improved portability and deployment efficiency.
`
- Technology Selection: React, FastAPI, Redis, pgvector, LangChain, and Docker were chosen for their efficiency and compatibility.
- Chunk Size Optimization: The judicial circular is split into optimized chunks to improve retrieval accuracy in the RAG pipeline.
- Microservices Implementation: This ensures modularity, scalability, and better collaboration in a team setting.
- Vector Databases: Using Redis and pgvector significantly improves query response time by leveraging efficient embedding-based searches.
- Docker for Portability: All services are containerized, allowing seamless deployment across different environments.
Rename the .env.example
file to .env
and configure your OpenAI API Key before running the application.
To run the project, ensure you have Docker installed on your system.
Then, execute the following command:
docker-compose up --build
This will start all services as defined in docker-compose.yml
, pulling necessary Docker images, creating containers, and running them together.
The database must be populated with embeddings from the judicial circular before the chatbot can function correctly.
It is recommended to use Anaconda to manage dependencies.
python -m venv venv
.\venv\Scripts\activate
Ensure that all required libraries are installed before running the script:
pip install -r requirements.txt
Once the virtual environment is active and dependencies are installed, run the script:
python insert_data.py
This script will:
✔ Connect to the PostgreSQL (pgvector) database
✔ Create necessary tables (if they don’t exist)
✔ Insert the processed embeddings into the vector database