RAGulator is a proof-of-concept framework built to enable real-time evaluation of custom RAG chains created using LangChain Expression Language (LCEL).
This project is a culmination of my bachelor thesis at TU Darmstadt.
These instructions will help you set up the project on your local machine for development and testing purposes. To ensure the persistence of evaluation sessions and the related data, a postgreSQL database is used inside a Docker container.
Before you begin, make sure you have the following installed:
- Python 3.12.x
- pip (Usually comes with python installation)
- Docker Desktop (Recommended)
-
Clone the repository:
git clone [email protected]:SiddKay/BachelorThesis-RAGulator.git
-
Rename the cloned directory to
RAGulator
to avoid any issues with the project structure and navigate to the root directory of the project:cd RAGulator
-
Make sure that (valid) LCEL chain files (.py) to be evaluated are present in the backend/langserve/chains/ directory. Some example chains can be found in this directory for reference.
-
Next, import the chain file and add a route for it at the end of backend/langserve/server.py file. For instance, to add a route for a chain file named
useful_chain.py
, where the name of the LCEL chain ismy_rag_chain
, add the following line at the end of the file:add_routes(app, my_rag_chain, path="/useful_chain")
-
Navigate to the
backend/
directory of the root:cd backend
-
Setup a virtual environment (optional but recommended):
# Create a new virtual environment python -m venv .venv # Activate the venv source .venv/bin/activate #Linux/MacOS .venv/Scripts/activate # Windows
-
Install the necessary dependencies for the backend:
pip install -r requirements.txt
-
Run the following command to set up your environment variables:
cp .env.example .env
Note 1: This will create a
.env
file from the sample.env.example
file. Please modify the values in the.env
file as needed.Note 2: The
MAIN_PORT
in the.env
file is set to8000
. If the port is already in use, please change it to a different port number. Similarly, adjust theLANGSERVE_PORT
which is set to8001
by default. -
Start Docker desktop on your local machine and run the following command to setup the postgreSQL database in a Docker container:
docker-compose up -d
-
Starting the both the Main as well as the LangServe servers:
python main.py
Check the terminal for the relevant endpoints and to see where the server is running. The API endpoints can be tested at http://localhost:8000/docs & http://localhost:8001/docs for Main app and LangServe, respectively.
-
Open a new terminal and Navigate to the
frontend/
directory of the project root:cd frontend
-
Install the necessary dependencies for the frontend:
npm install
-
Start the frontend server:
npm run dev
-
Open your browser and navigate to http://localhost:3000/sessions to view the RAGulator web application.
After the initial setup, for every subsequent usage of the app, you can directly start the backend servers and the frontend. Make sure to place the LCEL chain files in the backend/langserve/chains/ directory.
-
Start Docker desktop app, and check if the the container
ragulator_database
exists and is running. If the container is not present, navigate to thebackend/
directory and create a new one using the following commands:cd backend docker-compose up -d
-
To start the backend servers, run the following command in the
backend/
directory:python main.py
-
To start the frontend server, open a new terminal and navigate to the
RAGulator/frontend/
directory and run the following commands:npm run dev
-
Open your browser and navigate to http://localhost:3000/sessions to view the RAGulator web application.
Note: It is recommended to have the clipboard history enabled on your system to copy and paste multiple ids at the same time during the evaluation run.
Since the app frontend is currently missing a working sidebar with the relevant functionality to enable real-time evaluation of the LCEL chains, a typical evaluation flow involves the usage of the API endpoints directly via the OpenAPI docs UI. The following steps outline the process:
-
Once a session is created in the RAGulator interface, navigate to the OpenAPI docs UI to access the endpoints related to the chain selection and configuration adjustment at http://localhost:8000/docs.
-
Under the
sessions
section, run theGET /v1/sessions/
endpoint by clicking on theTry it out
button, to get all the available sessions. Copy theid
(first JSON key-value pair) of the session you want to evaluate. -
Next, navigate to the
chains
section and run theGET /v1/available-chains
endpoint to detect all the available chain files in the backend/langserver/chains/ directory. Form the API response body, copy thefile_name
of the chain you want to evaluate. -
Now, access the
POST /v1/sessions/{session_id}/select-chains
endpoint and paste the copied sessionid
in thesession_id
parameter and the copiedfile_name
in thefile_names
field in the request body. Click on theExecute
button to select the chain for evaluation. From the API response, copy the generated chainid
of the selected chain. -
To get the configuration schema of the selected chain, access the
GET /v1/sessions/{session_id}/chains/{chain_id}/configurations/schema
endpoint under theconfigurations
section, and paste the copied sessionid
in thesession_id
parameter and the chainid
in thechain_id
parameter. Click on theExecute
button to get the configuration schema. -
Based on the configuration schema, you can create a
config_values
object and access the "Create Configuration" API atPOST /v1/sessions/{session_id}/chains/{chain_id}/configurations
endpoint to set the configuration values for the selected chain. Paste the copied sessionid
and the chainid
in thesession_id
andchain_id
parameters, respectively. Then paste theconfig_values
object in the request body. Click on theExecute
button to set the configuration values. From the API response, copy the generatedid
of the created configuration. For a typical LCEL chain withsearch_kwargs_faiss
,answer_style
andgeneration_max_tokens
parameters as the defined configurable fields, theconfig_values
object would look like this:{ "config_values": { "search_kwargs_faiss": { "k": 2 }, "answer_style": "brief", "generation_max_tokens": 5 } }
-
Once the chain is selected, the configuration is set, and the questions have been added to the session via the RAGulator web-app interface, you can now invoke the chain concurrently for all the provided questions with the selected configuration. Access the
GET /v1/sessions/{session_id}/chains/{chain_id}/configuration/{config_id}/invoke
endpoint under thechains
section, and paste the copied sessionid
, chainid
, and configurationid
in thesession_id
,chain_id
, andconfig_id
parameters, respectively. Click on theExecute
button to invoke the chain. The generated answers will be displayed in the API response as well as the RAGulator web-app interface.
Similarly, create new configurations and invoke the chain multiple times to evaluate the chain with different configurations for all the questions.