Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into javier/llamacloud-fra…
Browse files Browse the repository at this point in the history
…mework-integration
  • Loading branch information
Javtor committed Jun 19, 2024
2 parents 97ac307 + 031de6b commit fdd2f61
Show file tree
Hide file tree
Showing 103 changed files with 7,029 additions and 18,092 deletions.
6 changes: 6 additions & 0 deletions docs/docs/api_reference/embeddings/ibm_watsonx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IBM watsonx.ai

::: llama_index.embeddings.ibm
options:
members:
- WatsonxEmbeddings
6 changes: 6 additions & 0 deletions docs/docs/api_reference/llms/ibm_watsonx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IBM watsonx.ai

::: llama_index.llms.ibm
options:
members:
- WatsonxLLM
4 changes: 4 additions & 0 deletions docs/docs/api_reference/readers/upstage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
::: llama_index.readers.upstage
options:
members:
- UpstageDocumentReader
26 changes: 13 additions & 13 deletions docs/docs/examples/embeddings/ibm_watsonx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"source": [
"# IBM watsonx.ai\n",
"\n",
">WatsonxEmbeddings is a wrapper for IBM [watsonx.ai](https://www.ibm.com/products/watsonx-ai) embeddings models.\n",
">WatsonxEmbeddings is a wrapper for IBM [watsonx.ai](https://www.ibm.com/products/watsonx-ai) embedding models.\n",
"\n",
"This example shows how to communicate with `watsonx.ai` embedding models using `LlamaIndex`."
"This example shows how to communicate with `watsonx.ai` embedding models using the `LlamaIndex` Embeddings API."
]
},
{
Expand All @@ -24,7 +24,7 @@
"source": [
"## Setting up\n",
"\n",
"Install the package `llama-index-embeddings-ibm`."
"Install the `llama-index-embeddings-ibm` package:"
]
},
{
Expand All @@ -40,10 +40,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This cell defines the WML credentials required to work with watsonx Embeddings.\n",
"The cell below defines the credentials required to work with watsonx Embeddings.\n",
"\n",
"**Action:** Provide the IBM Cloud user API key. For details, see\n",
"[documentation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui)."
"[Managing user API keys](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui)."
]
},
{
Expand All @@ -63,7 +63,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Additionaly you are able to pass additional secrets as an environment variable. "
"Additionally, you can pass additional secrets as an environment variable:"
]
},
{
Expand All @@ -89,7 +89,7 @@
"source": [
"## Load the model\n",
"\n",
"You might need to adjust embedding parameters for different tasks."
"You might need to adjust embedding parameters for different tasks:"
]
},
{
Expand All @@ -105,18 +105,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialize the `WatsonxEmbeddings` class with previously set parameter.\n",
"Initialize the `WatsonxEmbeddings` class with the previously set parameter.\n",
"\n",
"\n",
"**Note**: \n",
"\n",
"- To provide context for the API call, you must add `project_id` or `space_id`. For more information see [documentation](https://www.ibm.com/docs/en/watsonx-as-a-service?topic=projects).\n",
"- Depending on the region of your provisioned service instance, use one of the urls described [here](https://ibm.github.io/watsonx-ai-python-sdk/setup_cloud.html#authentication).\n",
"- To provide context for the API call, you must pass the `project_id` or `space_id`. To get your project or space ID, open your project or space, go to the **Manage** tab, and click **General**. For more information see: [Project documentation](https://www.ibm.com/docs/en/watsonx-as-a-service?topic=projects) or [Deployment space documentation](https://www.ibm.com/docs/en/watsonx/saas?topic=spaces-creating-deployment).\n",
"- Depending on the region of your provisioned service instance, use one of the urls listed in [watsonx.ai API Authentication](https://ibm.github.io/watsonx-ai-python-sdk/setup_cloud.html#authentication).\n",
"\n",
"In this example, we’ll use the `project_id` and Dallas url.\n",
"In this example, we’ll use the `project_id` and Dallas URL.\n",
"\n",
"\n",
"You need to specify `model_id` that will be used for inferencing."
"You need to specify the `model_id` that will be used for inferencing. You can find the list of all the available models in [Supported foundation models](https://ibm.github.io/watsonx-ai-python-sdk/fm_model.html#ibm_watsonx_ai.foundation_models.utils.enums.ModelTypes)."
]
},
{
Expand All @@ -139,7 +139,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively you can use Cloud Pak for Data credentials. For details, see [documentation](https://ibm.github.io/watsonx-ai-python-sdk/setup_cpd.html). "
"Alternatively, you can use Cloud Pak for Data credentials. For details, see [watsonx.ai software setup](https://ibm.github.io/watsonx-ai-python-sdk/setup_cpd.html). "
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/examples/embeddings/ipex_llm_gpu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"\n",
"> **Note**\n",
">\n",
"> You could refer to [here](https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/embeddings/llama-index-embeddings-ipex-llm/examples) for full examples of `IpexLLMEmbedding`. Please note that for running on Intel GPU, please specify `-d 'xpu'` in command argument when running the examples.\n",
"> You could refer to [here](https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/embeddings/llama-index-embeddings-ipex-llm/examples) for full examples of `IpexLLMEmbedding`. Please note that for running on Intel GPU, please specify `-d 'xpu'` or `-d 'xpu:<device_id>'` in command argument when running the examples.\n",
"\n",
"## Install Prerequisites\n",
"To benefit from IPEX-LLM on Intel GPUs, there are several prerequisite steps for tools installation and environment preparation.\n",
Expand Down Expand Up @@ -82,6 +82,8 @@
"```\n",
"\n",
"> Please note that `IpexLLMEmbedding` currently only provides optimization for Hugging Face Bge models.\n",
">\n",
"> If you have multiple Intel GPUs available, you could set `device=\"xpu:<device_id>\"`, in which `device_id` is counted from 0. `device=\"xpu\"` is equal to `device=\"xpu:0\"` by default.\n",
"\n",
"You could then conduct the embedding tasks as normal:\n",
"\n",
Expand Down
264 changes: 264 additions & 0 deletions docs/docs/examples/embeddings/mixedbreadai.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ef96689e6d0db317",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/embeddings/mixedbreadai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "82e5a0e429e08f86",
"metadata": {},
"source": [
"# Mixedbread AI Embeddings\n",
"\n",
"Explore the capabilities of MixedBread AI's embedding models with custom encoding formats (binary, int, float, base64, etc.), embedding dimensions (Matryoshka) and context prompts."
]
},
{
"cell_type": "markdown",
"id": "e1796b6747b975b6",
"metadata": {},
"source": [
"If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12e44155a01c6658",
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-embeddings-mixedbreadai"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e9c93730f08783c",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "615be84a4ebdb2aa",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from llama_index.embeddings.mixedbreadai import MixedbreadAIEmbedding\n",
"from llama_index.embeddings.mixedbreadai import EncodingFormat"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5562e0afabcd3d57",
"metadata": {},
"outputs": [],
"source": [
"# API Key and Embedding Initialization\n",
"\n",
"# You can visit https://www.mixedbread.ai/api-reference#quick-start-guide\n",
"# to get an api key\n",
"mixedbread_api_key = os.environ.get(\"MXBAI_API_KEY\", \"your-api-key\")\n",
"\n",
"# Please check https://www.mixedbread.ai/docs/embeddings/models#whats-new-in-the-mixedbread-embed-model-family\n",
"# for our embedding models\n",
"model_name = \"mixedbread-ai/mxbai-embed-large-v1\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "288d34815403983f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1024\n",
"[0.011276245, 0.0309906, -0.0060424805, 0.029174805, -0.03857422]\n"
]
}
],
"source": [
"oven = MixedbreadAIEmbedding(api_key=mixedbread_api_key, model_name=model_name)\n",
"\n",
"embeddings = oven.get_query_embedding(\"Why bread is so tasty?\")\n",
"\n",
"print(len(embeddings))\n",
"print(embeddings[:5])"
]
},
{
"cell_type": "markdown",
"id": "b8075b9329c1e21e",
"metadata": {},
"source": [
"### Using prompt for contextual embedding\n",
"\n",
"The prompt can improve the model's understanding of how the embedding will be used in subsequent tasks, which in turn increases the performance. Our experiments show that having domain specific prompts can increase the performance. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "459c8d8da3c0dbde",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1024\n",
"[-0.023544312, -0.015213013, 0.008407593, 0.00340271, -0.044708252]\n"
]
}
],
"source": [
"prompt_for_retrieval = (\n",
" \"Represent this sentence for searching relevant passages:\"\n",
")\n",
"\n",
"contextual_oven = MixedbreadAIEmbedding(\n",
" api_key=mixedbread_api_key,\n",
" model_name=model_name,\n",
" prompt=prompt_for_retrieval,\n",
")\n",
"\n",
"contextual_embeddings = contextual_oven.get_query_embedding(\n",
" \"What bread is invented in Germany?\"\n",
")\n",
"\n",
"print(len(contextual_embeddings))\n",
"print(contextual_embeddings[:5])"
]
},
{
"cell_type": "markdown",
"id": "9a9475daf5ac9879",
"metadata": {},
"source": [
"## Quantization and Matryoshka support\n",
"\n",
"The Mixedbread AI embedding supports quantization and matryoshka to reduce the size of embeddings for better storage while retaining most of the performance.\n",
"See these posts for more information: \n",
"* [Binary and Scalar Embedding Quantization for Significantly Faster & Cheaper Retrieval](https://huggingface.co/blog/embedding-quantization)\n",
"* [64 bytes per embedding, yee-haw](https://www.mixedbread.ai/blog/binary-mrl)."
]
},
{
"cell_type": "markdown",
"id": "5e5f5d29ebc54f31",
"metadata": {},
"source": [
"### Using different encoding formats\n",
"\n",
"The default `encoding_format` is `float`. We also support `float16`, `binary`, `ubinary`, `int8`, `uint8`, `base64`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "73cd06ff5f933333",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"128\n",
"[-121.0, 96.0, -108.0, 111.0, 110.0]\n"
]
}
],
"source": [
"# with `binary` embedding types\n",
"binary_oven = MixedbreadAIEmbedding(\n",
" api_key=mixedbread_api_key,\n",
" model_name=model_name,\n",
" encoding_format=EncodingFormat.BINARY,\n",
")\n",
"\n",
"binary_embeddings = binary_oven.get_text_embedding(\n",
" \"The bread is tiny but still filling!\"\n",
")\n",
"\n",
"print(len(binary_embeddings))\n",
"print(binary_embeddings[:5])"
]
},
{
"cell_type": "markdown",
"id": "b3cfbff8d6d03352",
"metadata": {},
"source": [
"### Using different embedding dimensions\n",
"\n",
"Mixedbread AI embedding models support Matryoshka dimension truncation. The default dimension is set to the model's maximum.\n",
"Keep an eye on our website to see what models support Matryoshka."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c711c05f7df269e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"512\n",
"[-0.014221191, -0.013671875, -0.03314209, 0.025909424, -0.035095215]\n"
]
}
],
"source": [
"# with truncated dimension\n",
"half_oven = MixedbreadAIEmbedding(\n",
" api_key=mixedbread_api_key,\n",
" model_name=model_name,\n",
" dimensions=512, # 1024 is the maximum of `mxbai-embed-large-v1`\n",
")\n",
"\n",
"half_embeddings = half_oven.get_text_embedding(\n",
" \"I want the better half of my bread.\"\n",
")\n",
"\n",
"print(len(half_embeddings))\n",
"print(half_embeddings[:5])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit fdd2f61

Please sign in to comment.