{"cells": [{"cell_type": "markdown", "id": "efe8f603c3a1ea67", "metadata": {}, "source": ["\"在\n"]}, {"cell_type": "markdown", "id": "7d05ee2e5015619a", "metadata": {}, "source": ["# Ollama嵌入\n", "\n", "Ollama是一个用于学习嵌入表示的Python库。嵌入表示是将对象映射到连续向量空间的技术,通常用于自然语言处理和推荐系统中。Ollama库提供了一种简单而灵活的方法来训练和使用嵌入表示。\n"]}, {"cell_type": "markdown", "id": "7ec795e92b745944", "metadata": {}, "source": ["如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。\n"]}, {"cell_type": "code", "execution_count": null, "id": "429b804c", "metadata": {}, "outputs": [], "source": ["%pip install llama-index-embeddings-ollama"]}, {"cell_type": "code", "execution_count": null, "id": "bd65f26028357e05", "metadata": {}, "outputs": [], "source": ["!pip install llama-index"]}, {"cell_type": "code", "execution_count": null, "id": "a45593c62b5a6518", "metadata": {}, "outputs": [], "source": ["from llama_index.embeddings.ollama import OllamaEmbedding\n", "\n", "ollama_embedding = OllamaEmbedding(\n", " model_name=\"llama2\",\n", " base_url=\"http://localhost:11434\",\n", " ollama_additional_kwargs={\"mirostat\": 0},\n", ")\n", "\n", "pass_embedding = ollama_embedding.get_text_embedding_batch(\n", " [\"This is a passage!\", \"This is another passage\"], show_progress=True\n", ")\n", "print(pass_embedding)\n", "\n", "query_embedding = ollama_embedding.get_query_embedding(\"Where is blue?\")\n", "print(query_embedding)"]}], "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}