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 git@github.com:SiddKay/BachelorThesis-RAGulator.git
-
Rename the cloned directory to
RAGulatorto 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
.envfile from the sample.env.examplefile. Please modify the values in the.envfile as needed.Note 2: The
MAIN_PORTin the.envfile is set to8000. If the port is already in use, please change it to a different port number. Similarly, adjust theLANGSERVE_PORTwhich is set to8001by 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_databaseexists 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
sessionssection, run theGET /v1/sessions/endpoint by clicking on theTry it outbutton, to get all the available sessions. Copy theid(first JSON key-value pair) of the session you want to evaluate. -
Next, navigate to the
chainssection and run theGET /v1/available-chainsendpoint to detect all the available chain files in the backend/langserver/chains/ directory. Form the API response body, copy thefile_nameof the chain you want to evaluate. -
Now, access the
POST /v1/sessions/{session_id}/select-chainsendpoint and paste the copied sessionidin thesession_idparameter and the copiedfile_namein thefile_namesfield in the request body. Click on theExecutebutton to select the chain for evaluation. From the API response, copy the generated chainidof the selected chain. -
To get the configuration schema of the selected chain, access the
GET /v1/sessions/{session_id}/chains/{chain_id}/configurations/schemaendpoint under theconfigurationssection, and paste the copied sessionidin thesession_idparameter and the chainidin thechain_idparameter. Click on theExecutebutton to get the configuration schema. -
Based on the configuration schema, you can create a
config_valuesobject and access the "Create Configuration" API atPOST /v1/sessions/{session_id}/chains/{chain_id}/configurationsendpoint to set the configuration values for the selected chain. Paste the copied sessionidand the chainidin thesession_idandchain_idparameters, respectively. Then paste theconfig_valuesobject in the request body. Click on theExecutebutton to set the configuration values. From the API response, copy the generatedidof the created configuration. For a typical LCEL chain withsearch_kwargs_faiss,answer_styleandgeneration_max_tokensparameters as the defined configurable fields, theconfig_valuesobject 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}/invokeendpoint under thechainssection, and paste the copied sessionid, chainid, and configurationidin thesession_id,chain_id, andconfig_idparameters, respectively. Click on theExecutebutton 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.