RAG Arena is an open-source Next.js project made my mendable.ai that interfaces with LangChain to provide a RAG chatbot experience where queries receive multiple responses. Users vote on these responses, which are then unblurred to reveal the Retriever used, differentiating the chatbots by their data RAG methods. The project utilizes Supabase for database operations and features a real-time leaderboard displaying data from the database.
Ensure you have pnpm
installed on your system. If not, install it via:
npm install -g pnpm
Clone the project repository:
git clone https://github.com/mendableai/rag-arena
Navigate to the project directory and install the dependencies:
cd RAG-arena
pnpm i
Configure your environment variables:
# probably in: https://platform.openai.com/api-keys
OPENAI_API_KEY=
# probably in: https://supabase.com/dashboard/ project>project settings>api
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_PRIVATE_KEY=
# probably in: https://console.upstash.com/redis/
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
PRODUCTION=false
PYTHON_MICRO_SERVER=
Start the development (nextjs) web server:
pnpm dev
cd python_service
poetry install
*(if you don't have poetry just add id using pip install poetry)
For the Graph Rag retriever you'll need to have the graph store built, or let the server automatically run the 'create_neo4j_graph_store' function (localized in /python_service/retrievers/neo4j_retriever.py
) by uncommenting the lines:
# if not os.path.exists(storage_dir) or not os.listdir(storage_dir):
# create_neo4j_graph_store()
This will take a while depending on the data used in data/chunks
. At the end you will have your neo/storage
directory populated with persisted data for the graph store locally.
You will need the index loaded and cached so that the Graph RAG can be used. The load_index()
function does that for you inside python_service/app.py
. So in your very first execution it may take a while to create the cached .pkl file placed in python_service/index/cache
.
poetry run flask run --debug
Open http://localhost:3000 with your browser to see the result.
app/api/ingest/route.ts
RecursiveCharacterTextSplitter
from LangChain for effective text splitting.OpenAIEmbeddings
for generating document embeddings.SupabaseVectorStore
for storing the processed documents in Supabase.app/api/retrievers/dynamic-retriever/route.ts
actions/voting-system.ts
// calculation used for the elo
function calculateEloAdjustment(timesTested: number, averageTimesTested: number): number {
if (averageTimesTested === 0) return 10;
const adjustmentFactor = timesTested / averageTimesTested;
return (1 / adjustmentFactor) * 10;
}
id
, retriever
, elo
, votes
, times_tested
, full_name
, description
, and link
.(https://js.langchain.com/docs/modules/data_connection/retrievers/)
This section outlines the various RAG functions defined in app/api/retrievers/dynamic-retriever/tools/functions.ts
, detailing their purpose and implementation within the project's architecture. These functions play a crucial role in the document RAG process, leveraging different strategies and technologies to optimize performance and accuracy.
Contributions are welcome! Please follow the standard fork & pull request workflow. Ensure you adhere to the coding styles and patterns present in the project and write tests for new features or bug fixes.
RAG Arena is open source and released under the MIT License. See the LICENSE file for more information.