Files
wehub-resource-sync a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:26:52 +08:00

114 lines
2.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/embeddings/modelscope.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"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
}