{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# ModelScope Embeddings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook, we show how to use the ModelScope Embeddings in LlamaIndex. Check out the [ModelScope site](https://www.modelscope.cn/).\n", "\n", "If you're opening this Notebook on colab, you will need to install LlamaIndex 🦙 and the modelscope." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install llama-index-embeddings-modelscope" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Usage\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys\n", "from llama_index.embeddings.modelscope.base import ModelScopeEmbedding\n", "\n", "model = ModelScopeEmbedding(\n", " model_name=\"iic/nlp_gte_sentence-embedding_chinese-base\",\n", " model_revision=\"master\",\n", ")\n", "\n", "rsp = model.get_query_embedding(\"Hello, who are you?\")\n", "print(rsp)\n", "\n", "rsp = model.get_text_embedding(\"Hello, who are you?\")\n", "print(rsp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Generate Batch Embedding" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from llama_index.embeddings.modelscope.base import ModelScopeEmbedding\n", "\n", "model = ModelScopeEmbedding(\n", " model_name=\"iic/nlp_gte_sentence-embedding_chinese-base\",\n", " model_revision=\"master\",\n", ")\n", "\n", "rsp = model.get_text_embedding_batch(\n", " [\"Hello, who are you?\", \"I am a student.\"]\n", ")\n", "print(rsp)" ] } ], "metadata": { "colab": { "name": "gemini.ipynb", "toc_visible": true }, "kernelspec": { "display_name": "Python 3", "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": 0 }