{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Text Embedding Inference\n", "\n", "This notebook demonstrates how to configure `TextEmbeddingInference` embeddings.\n", "\n", "The first step is to deploy the embeddings server. For detailed instructions, see the [official repository for Text Embeddings Inference](https://github.com/huggingface/text-embeddings-inference). Or [tei-gaudi repository](https://github.com/huggingface/tei-gaudi) if you are deploying on Habana Gaudi/Gaudi 2. \n", "\n", "Once deployed, the code below will connect to and submit embeddings for inference." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install llama-index-embeddings-text-embeddings-inference" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install llama-index" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from llama_index.embeddings.text_embeddings_inference import (\n", " TextEmbeddingsInference,\n", ")\n", "\n", "\n", "embed_model = TextEmbeddingsInference(\n", " model_name=\"BAAI/bge-large-en-v1.5\", # required for formatting inference text,\n", " timeout=60, # timeout in seconds\n", " embed_batch_size=10, # batch size for embedding\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1024\n", "[0.010597229, 0.05895996, 0.022445679, -0.012046814, -0.03164673]\n" ] } ], "source": [ "embeddings = embed_model.get_text_embedding(\"Hello World!\")\n", "print(len(embeddings))\n", "print(embeddings[:5])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1024\n", "[0.010597229, 0.05895996, 0.022445679, -0.012046814, -0.03164673]\n" ] } ], "source": [ "embeddings = await embed_model.aget_text_embedding(\"Hello World!\")\n", "print(len(embeddings))\n", "print(embeddings[:5])" ] } ], "metadata": { "kernelspec": { "display_name": "llama-index-4a-wkI5X-py3.11", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }