{"cells": [{"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\"在\n"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# 使用Optimum-Intel优化嵌入模型\n", "\n", "LlamaIndex支持使用[Optimum-Intel库](https://huggingface.co/docs/optimum/main/en/intel/index)加载Intel的量化嵌入模型。\n", "\n", "优化模型更小更快,准确性损失最小,详见[文档](https://huggingface.co/docs/optimum/main/en/intel/optimization_inc)和使用IntelLabs/fastRAG库的[优化指南](https://huggingface.co/docs/optimum/main/en/intel/optimization_inc)。\n", "\n", "优化基于Xeon®第4代或更新处理器中的数学指令。\n", "\n", "为了能够加载和使用量化模型,需要安装所需的依赖`pip install optimum[exporters] optimum-intel neural-compressor intel_extension_for_pytorch`。\n", "\n", "加载使用`IntelEmbedding`类,用法类似于任何HuggingFace本地嵌入模型;参见示例:\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["%pip install llama-index-embeddings-huggingface-optimum-intel"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.embeddings.huggingface_optimum_intel import IntelEmbedding\n", "\n", "embed_model = IntelEmbedding(\"Intel/bge-small-en-v1.5-rag-int8-static\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["384\n", "[-0.0032782123889774084, -0.013396517373621464, 0.037944991141557693, -0.04642259329557419, 0.027709005400538445]\n"]}], "source": ["embeddings = embed_model.get_text_embedding(\"Hello World!\")\n", "print(len(embeddings))\n", "print(embeddings[:5])"]}], "metadata": {"kernelspec": {"display_name": "Python 3 (ipykernel)", "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": 4}