From 99b61bdf8bf3e892af01f983b0e25bef791d3a07 Mon Sep 17 00:00:00 2001 From: Max Jakob Date: Mon, 13 May 2024 15:12:35 +0200 Subject: [PATCH] update Elasticsearch doc notebook with link --- .../vector_stores/Elasticsearch_demo.ipynb | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/docs/docs/examples/vector_stores/Elasticsearch_demo.ipynb b/docs/docs/examples/vector_stores/Elasticsearch_demo.ipynb index 91a77cf72e6e37..f59afebcad056f 100644 --- a/docs/docs/examples/vector_stores/Elasticsearch_demo.ipynb +++ b/docs/docs/examples/vector_stores/Elasticsearch_demo.ipynb @@ -26,9 +26,7 @@ "id": "b5331b6b", "metadata": {}, "source": [ - "## Basic Example\n", - "\n", - "In this basic example, we take the a Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Elasticsearch, and then query it." + "## Basic Example\n" ] }, { @@ -37,6 +35,8 @@ "id": "f3aaf790", "metadata": {}, "source": [ + "In this basic example, we take the a Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Elasticsearch, and then query it. For an example using different retrieval strategies see [Elasticsearch Vector Store](https://docs.llamaindex.ai/en/stable/examples/vector_stores/ElasticsearchIndexDemo/).\n", + "\n", "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙." ] }, @@ -47,20 +47,7 @@ "metadata": {}, "outputs": [], "source": [ - "%pip install llama-index-embeddings-huggingface\n", - "%pip install llama-index-vector-stores-elasticsearch" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b3df0b97", - "metadata": {}, - "outputs": [], - "source": [ - "# !pip install llama-index elasticsearch --quiet\n", - "# !pip install sentence-transformers\n", - "# !pip install pydantic==1.10.11" + "%pip install -qU llama-index-vector-stores-elasticsearch llama-index-embeddings-huggingface llama-index" ] }, { @@ -73,8 +60,7 @@ "# import\n", "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n", "from llama_index.vector_stores.elasticsearch import ElasticsearchStore\n", - "from llama_index.core import StorageContext\n", - "from IPython.display import Markdown, display" + "from llama_index.core import StorageContext" ] }, { @@ -105,10 +91,18 @@ "execution_count": null, "id": "06874a37", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2024-05-13 15:10:43 URL:https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt [75042/75042] -> \"data/paul_graham/paul_graham_essay.txt\" [1]\n" + ] + } + ], "source": [ "!mkdir -p 'data/paul_graham/'\n", - "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'" + "!wget -nv 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'" ] }, { @@ -132,38 +126,41 @@ "execution_count": null, "id": "667f3cb3-ce18-48d5-b9aa-bfc1a1f0f0f6", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "The author worked on writing and programming outside of school. They wrote short stories and tried writing programs on an IBM 1401 computer. They also built a microcomputer kit and started programming on it, writing simple games and a word processor." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "# load documents\n", "documents = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()\n", "\n", + "# define index\n", "vector_store = ElasticsearchStore(\n", - " index_name=\"paul_graham_essay\", es_url=\"http://localhost:9200\"\n", + " es_url=\"http://localhost:9200\", # see Elasticsearch Vector Store for more authentication options\n", + " index_name=\"paul_graham_essay\",\n", ")\n", "storage_context = StorageContext.from_defaults(vector_store=vector_store)\n", - "\n", "index = VectorStoreIndex.from_documents(\n", - " documents,\n", - " storage_context=storage_context,\n", - ")\n", - "\n", + " documents, storage_context=storage_context\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d3658bd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The author worked on writing and programming outside of school. They wrote short stories and tried writing programs on an IBM 1401 computer. They also built a microcomputer kit and started programming on it, writing simple games and a word processor.\n" + ] + } + ], + "source": [ "# Query Data\n", "query_engine = index.as_query_engine()\n", "response = query_engine.query(\"What did the author do growing up?\")\n", - "display(Markdown(f\"{response}\"))" + "print(response)" ] } ],