"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/cookbooks/mixedbread_reranker.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "360313ab-9393-430e-9647-e0d5545809b9",
"metadata": {},
"source": [
"# mixedbread Rerank Cookbook\n",
"\n",
"mixedbread.ai has released three fully open-source reranker models under the Apache 2.0 license. For more in-depth information, you can check out their detailed [blog post](https://www.mixedbread.ai/blog/mxbai-rerank-v1). The following are the three models:\n",
"\n",
"1. `mxbai-rerank-xsmall-v1`\n",
"2. `mxbai-rerank-base-v1`\n",
"3. `mxbai-rerank-large-v1`\n",
"\n",
"In this notebook, we'll demonstrate how to use the `mxbai-rerank-base-v1` model with the `SentenceTransformerRerank` module in LlamaIndex. This setup allows you to seamlessly swap in any reranker model of your choice using the `SentenceTransformerRerank` module to enhance your RAG pipeline."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "856ecfdc-04fa-4fe9-a81c-9a5858cd4a6d",
"metadata": {},
"source": [
"### Installation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bfb5314f-e6c7-409c-86df-8e1a5ca59adb",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index\n",
"!pip install sentence-transformers"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "5f5393fb-b410-4769-9380-0ef90a33b82e",
"metadata": {},
"source": [
"### Set API Keys"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9782acf-b0ab-4933-bb41-27cd2a02b5dd",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"YOUR OPENAI API KEY\""
"We will first retrieve 10 relevant nodes and pick top-2 nodes using the defined postprocessor."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e1b23700-15ae-4f1a-9443-43eb1eecab5f",
"metadata": {},
"outputs": [],
"source": [
"query_engine = index.as_query_engine(\n",
" similarity_top_k=10,\n",
" node_postprocessors=[postprocessor],\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "93871f9c-8871-4f43-8ee9-b3ca4e403d86",
"metadata": {},
"source": [
"### Test Queries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "658d3092-7d86-4520-83a2-c3e630dc02b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sam Altman initially declined the offer of becoming president of Y Combinator because he wanted to start a startup focused on making nuclear reactors.\n"
]
}
],
"source": [
"response = query_engine.query(\n",
" \"Why did Sam Altman decline the offer of becoming president of Y Combinator?\",\n",
")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "497e715e-3f7a-4140-a3ba-34356e473702",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Paul Graham started YC because he and his partners wanted to create an investment firm where they could implement their own ideas and provide the kind of support to startups that they felt was lacking when they were founders themselves. They aimed to not only make seed investments but also assist startups with various aspects of setting up a company, similar to the help they had received from others in the past.\n"
<ahref="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/cookbooks/mixedbread_reranker.ipynb"target="_parent"><imgsrc="https://colab.research.google.com/assets/colab-badge.svg"alt="Open In Colab"/></a>
mixedbread.ai has released three fully open-source reranker models under the Apache 2.0 license. For more in-depth information, you can check out their detailed [blog post](https://www.mixedbread.ai/blog/mxbai-rerank-v1). The following are the three models:
1.`mxbai-rerank-xsmall-v1`
2.`mxbai-rerank-base-v1`
3.`mxbai-rerank-large-v1`
In this notebook, we'll demonstrate how to use the `mxbai-rerank-base-v1` model with the `SentenceTransformerRerank` module in LlamaIndex. This setup allows you to seamlessly swap in any reranker model of your choice using the `SentenceTransformerRerank` module to enhance your RAG pipeline.
Paul Graham started YC because he and his partners wanted to create an investment firm where they could implement their own ideas and provide the kind of support to startups that they felt was lacking when they were founders themselves. They aimed to not only make seed investments but also assist startups with various aspects of setting up a company, similar to the help they had received from others in the past.