diff --git a/bootcamp/tutorials/integration/evaluation_with_ragas.ipynb b/bootcamp/tutorials/integration/evaluation_with_ragas.ipynb
index 65a42d3f3..3c7845c97 100644
--- a/bootcamp/tutorials/integration/evaluation_with_ragas.ipynb
+++ b/bootcamp/tutorials/integration/evaluation_with_ragas.ipynb
@@ -238,11 +238,23 @@
"outputs": [],
"source": [
"openai_client = OpenAI()\n",
- "milvus_client = MilvusClient(\"./milvus_demo.db\")\n",
+ "milvus_client = MilvusClient(uri=\"./milvus_demo.db\")\n",
"\n",
"my_rag = RAG(openai_client=openai_client, milvus_client=milvus_client)"
]
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"cell_type": "markdown",
"source": [
diff --git a/bootcamp/tutorials/integration/milvus_and_DSPy.ipynb b/bootcamp/tutorials/integration/milvus_and_DSPy.ipynb
index b24d0f218..183299aae 100644
--- a/bootcamp/tutorials/integration/milvus_and_DSPy.ipynb
+++ b/bootcamp/tutorials/integration/milvus_and_DSPy.ipynb
@@ -3,7 +3,9 @@
{
"metadata": {},
"cell_type": "markdown",
- "source": "",
+ "source": [
+ ""
+ ],
"id": "cc9c54a108f3efae"
},
{
@@ -106,7 +108,9 @@
{
"metadata": {},
"cell_type": "markdown",
- "source": "> If you are using Google Colab, to enable dependencies just installed, you may need to **restart the runtime** (click on the \"Runtime\" menu at the top of the screen, and select \"Restart session\" from the dropdown menu).",
+ "source": [
+ "> If you are using Google Colab, to enable dependencies just installed, you may need to **restart the runtime** (click on the \"Runtime\" menu at the top of the screen, and select \"Restart session\" from the dropdown menu)."
+ ],
"id": "bbf27b3225a33dae"
},
{
@@ -482,4 +486,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
-}
+}
\ No newline at end of file
diff --git a/bootcamp/tutorials/integration/milvus_with_Jina.ipynb b/bootcamp/tutorials/integration/milvus_with_Jina.ipynb
index c93c77aa9..4ef2dfac7 100644
--- a/bootcamp/tutorials/integration/milvus_with_Jina.ipynb
+++ b/bootcamp/tutorials/integration/milvus_with_Jina.ipynb
@@ -256,10 +256,24 @@
"outputs": [],
"execution_count": null
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"metadata": {},
"cell_type": "markdown",
- "source": "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search.",
+ "source": [
+ "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search."
+ ],
"id": "774929336febc81d"
},
{
diff --git a/bootcamp/tutorials/integration/qa_with_milvus_and_hf.ipynb b/bootcamp/tutorials/integration/qa_with_milvus_and_hf.ipynb
index d1699f83e..6daf7eabd 100644
--- a/bootcamp/tutorials/integration/qa_with_milvus_and_hf.ipynb
+++ b/bootcamp/tutorials/integration/qa_with_milvus_and_hf.ipynb
@@ -161,7 +161,7 @@
"\n",
"Now we have question-answer pairs ready with question embeddings. The next step is to insert them into the vector database.\n",
"\n",
- "We will first need to connect to Milvus service and create a Milvus collection. This section will use [Milvus Lite](https://milvus.io/docs/milvus_lite.md) as example. If you want to use other types of Milvus or [Zilliz Cloud](https://zilliz.com), please make sure you have started the service and connect with your own URI & credentials. You are also able to change parameters to customize your collection."
+ "We will first need to connect to Milvus service and create a Milvus collection."
]
},
{
@@ -190,6 +190,18 @@
")"
]
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"cell_type": "markdown",
"metadata": {},
diff --git a/bootcamp/tutorials/integration/rag_with_milvus_and_bentoml.ipynb b/bootcamp/tutorials/integration/rag_with_milvus_and_bentoml.ipynb
index 80de64efd..ba6f584c6 100644
--- a/bootcamp/tutorials/integration/rag_with_milvus_and_bentoml.ipynb
+++ b/bootcamp/tutorials/integration/rag_with_milvus_and_bentoml.ipynb
@@ -287,6 +287,18 @@
],
"id": "f4fc2677daaefe9b"
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"metadata": {},
"cell_type": "markdown",
diff --git a/bootcamp/tutorials/integration/rag_with_milvus_and_haystack.ipynb b/bootcamp/tutorials/integration/rag_with_milvus_and_haystack.ipynb
index e3fcfa0de..a71565aa1 100644
--- a/bootcamp/tutorials/integration/rag_with_milvus_and_haystack.ipynb
+++ b/bootcamp/tutorials/integration/rag_with_milvus_and_haystack.ipynb
@@ -131,6 +131,47 @@
"Create an indexing pipeline that converts the text into documents, splits them into sentences, and embeds them. The documents are then written to the Milvus document store."
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "outputs": [],
+ "source": [
+ "from haystack import Pipeline\n",
+ "from haystack.components.converters import MarkdownToDocument\n",
+ "from haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder\n",
+ "from haystack.components.preprocessors import DocumentSplitter\n",
+ "from haystack.components.writers import DocumentWriter\n",
+ "\n",
+ "from milvus_haystack import MilvusDocumentStore\n",
+ "from milvus_haystack.milvus_embedding_retriever import MilvusEmbeddingRetriever\n",
+ "\n",
+ "\n",
+ "document_store = MilvusDocumentStore(\n",
+ " connection_args={\"uri\": \"./milvus.db\"},\n",
+ " # connection_args={\"uri\": \"http://localhost:19530\"},\n",
+ " # connection_args={\"uri\": YOUR_ZILLIZ_CLOUD_URI, \"token\": YOUR_ZILLIZ_API_KEY},\n",
+ " drop_old=True,\n",
+ ")"
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> For the connection_args:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"cell_type": "code",
"execution_count": 4,
@@ -165,19 +206,6 @@
}
],
"source": [
- "from haystack import Pipeline\n",
- "from haystack.components.converters import MarkdownToDocument\n",
- "from haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder\n",
- "from haystack.components.preprocessors import DocumentSplitter\n",
- "from haystack.components.writers import DocumentWriter\n",
- "\n",
- "from milvus_haystack import MilvusDocumentStore\n",
- "from milvus_haystack.milvus_embedding_retriever import MilvusEmbeddingRetriever\n",
- "\n",
- "document_store = MilvusDocumentStore(\n",
- " connection_args={\"uri\": \"./milvus.db\"},\n",
- " drop_old=True,\n",
- ")\n",
"indexing_pipeline = Pipeline()\n",
"indexing_pipeline.add_component(\"converter\", MarkdownToDocument())\n",
"indexing_pipeline.add_component(\n",
diff --git a/bootcamp/tutorials/integration/rag_with_milvus_and_langchain.ipynb b/bootcamp/tutorials/integration/rag_with_milvus_and_langchain.ipynb
index 41dd382b7..64e3c1a82 100644
--- a/bootcamp/tutorials/integration/rag_with_milvus_and_langchain.ipynb
+++ b/bootcamp/tutorials/integration/rag_with_milvus_and_langchain.ipynb
@@ -2,12 +2,15 @@
"cells": [
{
"cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
"source": [
"\n"
- ],
- "metadata": {
- "collapsed": false
- }
+ ]
},
{
"cell_type": "markdown",
@@ -44,12 +47,15 @@
},
{
"cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
"source": [
"> If you are using Google Colab, to enable dependencies just installed, you may need to **restart the runtime** (click on the \"Runtime\" menu at the top of the screen, and select \"Restart session\" from the dropdown menu)."
- ],
- "metadata": {
- "collapsed": false
- }
+ ]
},
{
"cell_type": "markdown",
@@ -65,19 +71,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "outputs": [],
- "source": [
- "import os\n",
- "\n",
- "os.environ[\"OPENAI_API_KEY\"] = \"sk-***********\""
- ],
+ "execution_count": 2,
"metadata": {
"collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ },
"pycharm": {
"name": "#%%\n"
}
- }
+ },
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "os.environ[\"OPENAI_API_KEY\"] = \"sk-***********\""
+ ]
},
{
"cell_type": "markdown",
@@ -96,7 +105,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {
"collapsed": false,
"jupyter": {
@@ -113,7 +122,7 @@
"Document(page_content='Fig. 1. Overview of a LLM-powered autonomous agent system.\\nComponent One: Planning#\\nA complicated task usually involves many steps. An agent needs to know what they are and plan ahead.\\nTask Decomposition#\\nChain of thought (CoT; Wei et al. 2022) has become a standard prompting technique for enhancing model performance on complex tasks. The model is instructed to “think step by step” to utilize more test-time computation to decompose hard tasks into smaller and simpler steps. CoT transforms big tasks into multiple manageable tasks and shed lights into an interpretation of the model’s thinking process.\\nTree of Thoughts (Yao et al. 2023) extends CoT by exploring multiple reasoning possibilities at each step. It first decomposes the problem into multiple thought steps and generates multiple thoughts per step, creating a tree structure. The search process can be BFS (breadth-first search) or DFS (depth-first search) with each state evaluated by a classifier (via a prompt) or majority vote.\\nTask decomposition can be done (1) by LLM with simple prompting like \"Steps for XYZ.\\\\n1.\", \"What are the subgoals for achieving XYZ?\", (2) by using task-specific instructions; e.g. \"Write a story outline.\" for writing a novel, or (3) with human inputs.\\nAnother quite distinct approach, LLM+P (Liu et al. 2023), involves relying on an external classical planner to do long-horizon planning. This approach utilizes the Planning Domain Definition Language (PDDL) as an intermediate interface to describe the planning problem. In this process, LLM (1) translates the problem into “Problem PDDL”, then (2) requests a classical planner to generate a PDDL plan based on an existing “Domain PDDL”, and finally (3) translates the PDDL plan back into natural language. Essentially, the planning step is outsourced to an external tool, assuming the availability of domain-specific PDDL and a suitable planner which is common in certain robotic setups but not in many other domains.\\nSelf-Reflection#', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/'})"
]
},
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@@ -125,7 +134,10 @@
"\n",
"# Create a WebBaseLoader instance to load documents from web sources\n",
"loader = WebBaseLoader(\n",
- " web_paths=(\"https://lilianweng.github.io/posts/2023-06-23-agent/\",),\n",
+ " web_paths=(\n",
+ " \"https://lilianweng.github.io/posts/2023-06-23-agent/\",\n",
+ " \"https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/\",\n",
+ " ),\n",
" bs_kwargs=dict(\n",
" parse_only=bs4.SoupStrainer(\n",
" class_=(\"post-content\", \"post-title\", \"post-header\")\n",
@@ -172,33 +184,25 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
+ "is_executing": true,
"name": "#%%\n"
}
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/Users/zilliz/miniforge3/envs/py39/lib/python3.9/site-packages/scipy/__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.26.0 is required for this version of SciPy (detected version 1.26.4\n",
- " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
- "from langchain_milvus import Milvus\n",
+ "from langchain_milvus import Milvus, Zilliz\n",
"from langchain_openai import OpenAIEmbeddings\n",
"\n",
"embeddings = OpenAIEmbeddings()\n",
"\n",
- "vectorstore = Milvus.from_documents(\n",
+ "vectorstore = Milvus.from_documents( # or Zilliz.from_documents\n",
" documents=docs,\n",
" embedding=embeddings,\n",
" connection_args={\n",
@@ -217,12 +221,27 @@
}
},
"source": [
- "Search the documents in the Milvus vector store using a test query question. We will get the top 3 documents."
+ "> For the `connection_args`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, replace `Milvus.from_documents` with `Zilliz.from_documents`, and adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "Search the documents in the Milvus vector store using a test query question. Let's take a look at the top 1 document."
]
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {
"collapsed": false,
"jupyter": {
@@ -236,24 +255,22 @@
{
"data": {
"text/plain": [
- "[Document(page_content='Self-Reflection#\\nSelf-reflection is a vital aspect that allows autonomous agents to improve iteratively by refining past action decisions and correcting previous mistakes. It plays a crucial role in real-world tasks where trial and error are inevitable.\\nReAct (Yao et al. 2023) integrates reasoning and acting within LLM by extending the action space to be a combination of task-specific discrete actions and the language space. The former enables LLM to interact with the environment (e.g. use Wikipedia search API), while the latter prompting LLM to generate reasoning traces in natural language.\\nThe ReAct prompt template incorporates explicit steps for LLM to think, roughly formatted as:\\nThought: ...\\nAction: ...\\nObservation: ...\\n... (Repeated many times)', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449757808726900738}),\n",
- " Document(page_content='Fig. 2. Examples of reasoning trajectories for knowledge-intensive tasks (e.g. HotpotQA, FEVER) and decision-making tasks (e.g. AlfWorld Env, WebShop). (Image source: Yao et al. 2023).\\nIn both experiments on knowledge-intensive tasks and decision-making tasks, ReAct works better than the Act-only baseline where Thought: … step is removed.\\nReflexion (Shinn & Labash 2023) is a framework to equips agents with dynamic memory and self-reflection capabilities to improve reasoning skills. Reflexion has a standard RL setup, in which the reward model provides a simple binary reward and the action space follows the setup in ReAct where the task-specific action space is augmented with language to enable complex reasoning steps. After each action $a_t$, the agent computes a heuristic $h_t$ and optionally may decide to reset the environment to start a new trial depending on the self-reflection results.\\n\\nFig. 3. Illustration of the Reflexion framework. (Image source: Shinn & Labash, 2023)\\nThe heuristic function determines when the trajectory is inefficient or contains hallucination and should be stopped. Inefficient planning refers to trajectories that take too long without success. Hallucination is defined as encountering a sequence of consecutive identical actions that lead to the same observation in the environment.\\nSelf-reflection is created by showing two-shot examples to LLM and each example is a pair of (failed trajectory, ideal reflection for guiding future changes in the plan). Then reflections are added into the agent’s working memory, up to three, to be used as context for querying LLM.', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449757808726900739}),\n",
- " Document(page_content='Fig. 1. Overview of a LLM-powered autonomous agent system.\\nComponent One: Planning#\\nA complicated task usually involves many steps. An agent needs to know what they are and plan ahead.\\nTask Decomposition#\\nChain of thought (CoT; Wei et al. 2022) has become a standard prompting technique for enhancing model performance on complex tasks. The model is instructed to “think step by step” to utilize more test-time computation to decompose hard tasks into smaller and simpler steps. CoT transforms big tasks into multiple manageable tasks and shed lights into an interpretation of the model’s thinking process.\\nTree of Thoughts (Yao et al. 2023) extends CoT by exploring multiple reasoning possibilities at each step. It first decomposes the problem into multiple thought steps and generates multiple thoughts per step, creating a tree structure. The search process can be BFS (breadth-first search) or DFS (depth-first search) with each state evaluated by a classifier (via a prompt) or majority vote.\\nTask decomposition can be done (1) by LLM with simple prompting like \"Steps for XYZ.\\\\n1.\", \"What are the subgoals for achieving XYZ?\", (2) by using task-specific instructions; e.g. \"Write a story outline.\" for writing a novel, or (3) with human inputs.\\nAnother quite distinct approach, LLM+P (Liu et al. 2023), involves relying on an external classical planner to do long-horizon planning. This approach utilizes the Planning Domain Definition Language (PDDL) as an intermediate interface to describe the planning problem. In this process, LLM (1) translates the problem into “Problem PDDL”, then (2) requests a classical planner to generate a PDDL plan based on an existing “Domain PDDL”, and finally (3) translates the PDDL plan back into natural language. Essentially, the planning step is outsourced to an external tool, assuming the availability of domain-specific PDDL and a suitable planner which is common in certain robotic setups but not in many other domains.\\nSelf-Reflection#', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449757808726900737})]"
+ "[Document(page_content='Self-Reflection#\\nSelf-reflection is a vital aspect that allows autonomous agents to improve iteratively by refining past action decisions and correcting previous mistakes. It plays a crucial role in real-world tasks where trial and error are inevitable.\\nReAct (Yao et al. 2023) integrates reasoning and acting within LLM by extending the action space to be a combination of task-specific discrete actions and the language space. The former enables LLM to interact with the environment (e.g. use Wikipedia search API), while the latter prompting LLM to generate reasoning traces in natural language.\\nThe ReAct prompt template incorporates explicit steps for LLM to think, roughly formatted as:\\nThought: ...\\nAction: ...\\nObservation: ...\\n... (Repeated many times)', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449281835035555859})]"
]
},
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"What is self-reflection of an AI Agent?\"\n",
- "vectorstore.similarity_search(query, k=3)"
+ "vectorstore.similarity_search(query, k=1)"
]
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {
"collapsed": false,
"jupyter": {
@@ -317,7 +334,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {
"collapsed": false,
"jupyter": {
@@ -331,10 +348,10 @@
{
"data": {
"text/plain": [
- "\"Self-reflection of an AI agent involves the process of synthesizing memories into higher-level inferences over time to guide the agent's future behavior. It includes recency, importance, and relevance factors to determine the salient high-level questions and optimize believability. This mechanism helps the agent improve iteratively by refining past action decisions and correcting previous mistakes.\""
+ "\"Self-reflection of an AI agent involves the process of synthesizing memories into higher-level inferences over time to guide the agent's future behavior. It serves as a mechanism to create higher-level summaries of past events. One approach to self-reflection involves prompting the language model with the 100 most recent observations and asking it to generate the 3 most salient high-level questions based on those observations. This process helps the AI agent optimize believability in the current moment and over time.\""
]
},
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -357,15 +374,220 @@
},
{
"cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "Congratulations! You have built a basic RAG chain powered by Milvus and LangChain."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "## Metadata filtering\n",
+ "\n",
+ "We can use the [Milvus Scalar Filtering Rules](https://milvus.io/docs/boolean.md) to filter the documents based on metadata. We have loaded the documents from two different sources, and we can filter the documents by the metadata `source`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[Document(page_content='Fig. 1. Overview of a LLM-powered autonomous agent system.\\nComponent One: Planning#\\nA complicated task usually involves many steps. An agent needs to know what they are and plan ahead.\\nTask Decomposition#\\nChain of thought (CoT; Wei et al. 2022) has become a standard prompting technique for enhancing model performance on complex tasks. The model is instructed to “think step by step” to utilize more test-time computation to decompose hard tasks into smaller and simpler steps. CoT transforms big tasks into multiple manageable tasks and shed lights into an interpretation of the model’s thinking process.\\nTree of Thoughts (Yao et al. 2023) extends CoT by exploring multiple reasoning possibilities at each step. It first decomposes the problem into multiple thought steps and generates multiple thoughts per step, creating a tree structure. The search process can be BFS (breadth-first search) or DFS (depth-first search) with each state evaluated by a classifier (via a prompt) or majority vote.\\nTask decomposition can be done (1) by LLM with simple prompting like \"Steps for XYZ.\\\\n1.\", \"What are the subgoals for achieving XYZ?\", (2) by using task-specific instructions; e.g. \"Write a story outline.\" for writing a novel, or (3) with human inputs.\\nAnother quite distinct approach, LLM+P (Liu et al. 2023), involves relying on an external classical planner to do long-horizon planning. This approach utilizes the Planning Domain Definition Language (PDDL) as an intermediate interface to describe the planning problem. In this process, LLM (1) translates the problem into “Problem PDDL”, then (2) requests a classical planner to generate a PDDL plan based on an existing “Domain PDDL”, and finally (3) translates the PDDL plan back into natural language. Essentially, the planning step is outsourced to an external tool, assuming the availability of domain-specific PDDL and a suitable planner which is common in certain robotic setups but not in many other domains.\\nSelf-Reflection#', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449281835035555858})]"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "vectorstore.similarity_search(\n",
+ " \"What is CoT?\",\n",
+ " k=1,\n",
+ " expr=\"source == 'https://lilianweng.github.io/posts/2023-06-23-agent/'\",\n",
+ ")\n",
+ "\n",
+ "# The same as:\n",
+ "# vectorstore.as_retriever(search_kwargs=dict(\n",
+ "# k=1,\n",
+ "# expr=\"source == 'https://lilianweng.github.io/posts/2023-06-23-agent/'\",\n",
+ "# )).invoke(\"What is CoT?\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "If we want to dynamically change the search parameters without rebuilding the chain, we can [configure the runtime chain internals](https://python.langchain.com/v0.2/docs/how_to/configure/) . Let's define a new retriever with this dynamically configure and use it to build a new RAG chain."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[Document(page_content='Self-Reflection#\\nSelf-reflection is a vital aspect that allows autonomous agents to improve iteratively by refining past action decisions and correcting previous mistakes. It plays a crucial role in real-world tasks where trial and error are inevitable.\\nReAct (Yao et al. 2023) integrates reasoning and acting within LLM by extending the action space to be a combination of task-specific discrete actions and the language space. The former enables LLM to interact with the environment (e.g. use Wikipedia search API), while the latter prompting LLM to generate reasoning traces in natural language.\\nThe ReAct prompt template incorporates explicit steps for LLM to think, roughly formatted as:\\nThought: ...\\nAction: ...\\nObservation: ...\\n... (Repeated many times)', metadata={'source': 'https://lilianweng.github.io/posts/2023-06-23-agent/', 'pk': 449281835035555859})]"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "from langchain_core.runnables import ConfigurableField\n",
+ "\n",
+ "# Define a new retriever with a configurable field for search_kwargs\n",
+ "retriever2 = vectorstore.as_retriever().configurable_fields(\n",
+ " search_kwargs=ConfigurableField(\n",
+ " id=\"retriever_search_kwargs\",\n",
+ " )\n",
+ ")\n",
+ "\n",
+ "# Invoke the retriever with a specific search_kwargs which filter the documents by source\n",
+ "retriever2.with_config(\n",
+ " configurable={\n",
+ " \"retriever_search_kwargs\": dict(\n",
+ " expr=\"source == 'https://lilianweng.github.io/posts/2023-06-23-agent/'\",\n",
+ " k=1,\n",
+ " )\n",
+ " }\n",
+ ").invoke(query)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ },
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "# Define a new RAG chain with this dynamically configurable retriever\n",
+ "rag_chain2 = (\n",
+ " {\"context\": retriever2 | format_docs, \"question\": RunnablePassthrough()}\n",
+ " | prompt\n",
+ " | llm\n",
+ " | StrOutputParser()\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
"source": [
- "This tutorial build a vanilla RAG chain powered by Milvus. For more advanced RAG techniques, please refer to the [advanced rag bootcamp](https://github.com/milvus-io/bootcamp/tree/master/bootcamp/RAG/advanced_rag)."
+ "Let's try this dynamically configurable RAG chain with different filter conditions."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\"Self-reflection of an AI agent involves the process of synthesizing memories into higher-level inferences over time to guide the agent's future behavior. It serves as a mechanism to create higher-level summaries of past events. One approach to self-reflection involves prompting the language model with the 100 most recent observations and asking it to generate the 3 most salient high-level questions based on those observations. This process helps the AI agent optimize believability in the current moment and over time.\""
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
],
+ "source": [
+ "# Invoke this RAG chain with a specific question and config\n",
+ "rag_chain2.with_config(\n",
+ " configurable={\n",
+ " \"retriever_search_kwargs\": dict(\n",
+ " expr=\"source == 'https://lilianweng.github.io/posts/2023-06-23-agent/'\",\n",
+ " )\n",
+ " }\n",
+ ").invoke(query)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
"metadata": {
"collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "When we change the search condition to filter the documents by the second source, as the content of this blog source has nothing todo with the query question, we get an answer with no relevant information."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\"I'm sorry, but based on the provided context, there is no specific information or statistical data available regarding the self-reflection of an AI agent.\""
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rag_chain2.with_config(\n",
+ " configurable={\n",
+ " \"retriever_search_kwargs\": dict(\n",
+ " expr=\"source == 'https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/'\",\n",
+ " )\n",
+ " }\n",
+ ").invoke(query)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
"pycharm": {
"name": "#%% md\n"
}
- }
+ },
+ "source": [
+ "----\n",
+ "This tutorial focus the basic usage of Milvus LangChain integration and simple RAG approach. For more advanced RAG techniques, please refer to the [advanced rag bootcamp](https://github.com/milvus-io/bootcamp/tree/master/bootcamp/RAG/advanced_rag)."
+ ]
}
],
"metadata": {
diff --git a/bootcamp/tutorials/integration/rag_with_milvus_and_llamaindex.ipynb b/bootcamp/tutorials/integration/rag_with_milvus_and_llamaindex.ipynb
index 1b96b817f..ba760a89e 100644
--- a/bootcamp/tutorials/integration/rag_with_milvus_and_llamaindex.ipynb
+++ b/bootcamp/tutorials/integration/rag_with_milvus_and_llamaindex.ipynb
@@ -40,7 +40,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"id": "7aa64984",
"metadata": {
"vscode": {
@@ -54,7 +54,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"id": "3e0c18ca",
"metadata": {
"vscode": {
@@ -68,7 +68,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"id": "6b80700a",
"metadata": {
"vscode": {
@@ -101,7 +101,7 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 4,
"id": "0c9f4d21-145a-401e-95ff-ccb259e8ef84",
"metadata": {},
"outputs": [],
@@ -124,13 +124,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"id": "2a2e24d1",
"metadata": {},
"outputs": [],
"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'"
+ "! mkdir -p 'data/'\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_essay.txt'\n",
+ "! wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/10k/uber_2021.pdf' -O 'data/uber_2021.pdf'"
]
},
{
@@ -142,12 +143,12 @@
"## Getting Started\n",
"\n",
"### Generate our data\n",
- "As a first example, lets generate a document from the file found in the `data/paul_graham/` folder. In this folder there is a single essay from Paul Graham titled `What I Worked On`. To generate the documents we will use the SimpleDirectoryReader."
+ "As a first example, lets generate a document from the file `paul_graham_essay.txt`. It is a single essay from Paul Graham titled `What I Worked On`. To generate the documents we will use the SimpleDirectoryReader."
]
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 6,
"id": "68cbd239-880e-41a3-98d8-dbb3fab55431",
"metadata": {},
"outputs": [
@@ -155,7 +156,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Document ID: 11c3a6fe-799e-4e40-8122-2339936c2722\n"
+ "Document ID: 95f25e4d-f270-4650-87ce-006d69d82033\n"
]
}
],
@@ -163,7 +164,9 @@
"from llama_index.core import SimpleDirectoryReader\n",
"\n",
"# load documents\n",
- "documents = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()\n",
+ "documents = SimpleDirectoryReader(\n",
+ " input_files=[\"./data/paul_graham_essay.txt\"]\n",
+ ").load_data()\n",
"\n",
"print(\"Document ID:\", documents[0].doc_id)"
]
@@ -176,32 +179,19 @@
"source": [
"### Create an index across the data\n",
"\n",
- "Now that we have a document, we can can create an index and insert the document. For the index we will use a GPTMilvusIndex. GPTMilvusIndex takes in a few arguments:\n",
- "\n",
- "- `uri (str, optional)`: The URI to connect to, comes in the form of \"https://address:port\" if using Milvus or Zilliz Cloud service, or \"path/to/local/milvus.db\" if using a lite local Milvus. Defaults to \"./milvus_llamaindex.db\".\n",
- "- `token (str, optional)`: The token for log in. Empty if not using rbac, if using rbac it will most likely be \"username:password\". Defaults to \"\".\n",
- "- `collection_name (str, optional)`: The name of the collection where data will be stored. Defaults to \"llamalection\".\n",
- "- `dim (int, optional)`: The dimension of the embeddings. If it is not provided, collection creation will be done on first insert. Defaults to None.\n",
- "- `embedding_field (str, optional)`: The name of the embedding field for the collection, defaults to DEFAULT_EMBEDDING_KEY.\n",
- "- `doc_id_field (str, optional)`: The name of the doc_id field for the collection, defaults to DEFAULT_DOC_ID_KEY.\n",
- "- `similarity_metric (str, optional)`: The similarity metric to use, currently supports IP and L2. Defaults to \"IP\".\n",
- "- `consistency_level (str, optional)`: Which consistency level to use for a newly created collection. Defaults to \"Strong\".\n",
- "- `overwrite (bool, optional)`: Whether to overwrite existing collection with same name. Defaults to False.\n",
- "- `text_key (str, optional)`: What key text is stored in in the passed collection. Used when bringing your own collection. Defaults to None.\n",
- "- `index_config (dict, optional)`: The configuration used for building the Milvus index. Defaults to None.\n",
- "- `search_config (dict, optional)`: The configuration used for searching the Milvus index. Note that this must be compatible with the index type specified by index_config. Defaults to None.\n",
+ "Now that we have a document, we can can create an index and insert the document.\n",
"\n",
"> Please note that **Milvus Lite** requires `pymilvus>=2.4.2`."
]
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 7,
"id": "ba1558b3",
"metadata": {},
"outputs": [],
"source": [
- "# Create an index over the documnts\n",
+ "# Create an index over the documents\n",
"from llama_index.core import VectorStoreIndex, StorageContext\n",
"from llama_index.vector_stores.milvus import MilvusVectorStore\n",
"\n",
@@ -211,6 +201,22 @@
"index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "a75a5773",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "> For the parameters of `MilvusVectorStore`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ]
+ },
{
"attachments": {},
"cell_type": "markdown",
@@ -223,7 +229,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 8,
"id": "35369eda",
"metadata": {},
"outputs": [
@@ -231,27 +237,19 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "The author learned about programming on early computers like the IBM 1401 using Fortran, the\n",
- "limitations of early computing technology, the transition to microcomputers, and the excitement of\n",
- "having a personal computer like the TRS-80. Additionally, the author explored different academic\n",
- "paths, initially planning to study philosophy but eventually switching to AI due to a lack of\n",
- "interest in philosophy courses. Later on, the author pursued art education, attending RISD and the\n",
- "Accademia di Belli Arti in Florence, where they encountered a different approach to teaching art.\n"
+ "The author learned that philosophy courses in college were boring to him, leading him to switch his focus to studying AI.\n"
]
}
],
"source": [
- "import textwrap\n",
- "\n",
- "\n",
"query_engine = index.as_query_engine()\n",
- "response = query_engine.query(\"What did the author learn?\")\n",
- "print(textwrap.fill(str(response), 100))"
+ "res = query_engine.query(\"What did the author learn?\")\n",
+ "print(res)"
]
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 9,
"id": "99212d33",
"metadata": {},
"outputs": [
@@ -259,14 +257,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Dealing with the stress and challenges related to managing Hacker News was a difficult moment for\n",
- "the author.\n"
+ "The disease posed challenges for the author as it affected his mother's health, leading to a stroke caused by colon cancer. This resulted in her losing her balance and needing to be placed in a nursing home. The author and his sister were determined to help their mother get out of the nursing home and back to her house.\n"
]
}
],
"source": [
- "response = query_engine.query(\"What was a hard moment for the author?\")\n",
- "print(textwrap.fill(str(response), 100))"
+ "res = query_engine.query(\"What challenges did the disease pose for the author?\")\n",
+ "print(res)"
]
},
{
@@ -280,7 +277,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 10,
"id": "8d641e24",
"metadata": {},
"outputs": [
@@ -288,7 +285,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Res: The author is the individual who created the content or work in question.\n"
+ "The author is the individual who created the context information.\n"
]
}
],
@@ -304,7 +301,7 @@
")\n",
"query_engine = index.as_query_engine()\n",
"res = query_engine.query(\"Who is the author?\")\n",
- "print(\"Res:\", res)"
+ "print(res)"
]
},
{
@@ -318,7 +315,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 11,
"id": "a5c429a4",
"metadata": {},
"outputs": [
@@ -326,7 +323,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Res: The number is ten.\n"
+ "The number is ten.\n"
]
}
],
@@ -338,26 +335,120 @@
"index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)\n",
"query_engine = index.as_query_engine()\n",
"res = query_engine.query(\"What is the number?\")\n",
- "print(\"Res:\", res)"
+ "print(res)"
]
},
{
"cell_type": "code",
- "execution_count": 10,
- "id": "e5287c2d",
+ "execution_count": 12,
+ "id": "56ac3375-371b-4e5f-bac9-8124b6871429",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Res: Paul Graham\n"
+ "Paul Graham\n"
]
}
],
"source": [
"res = query_engine.query(\"Who is the author?\")\n",
- "print(\"Res:\", res)"
+ "print(res)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## Metadata filtering\n",
+ "\n",
+ "We can generate results by filtering specific sources. The following example illustrates loading all documents from the directory and subsequently filtering them based on metadata."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "2a845c5d-f10b-4fba-9cd2-e62871f836f3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from llama_index.core.vector_stores import ExactMatchFilter, MetadataFilters\n",
+ "\n",
+ "# Load all the two documents loaded before\n",
+ "documents_all = SimpleDirectoryReader(\"./data/\").load_data()\n",
+ "\n",
+ "vector_store = MilvusVectorStore(uri=\"./milvus_demo.db\", dim=1536, overwrite=True)\n",
+ "storage_context = StorageContext.from_defaults(vector_store=vector_store)\n",
+ "index = VectorStoreIndex.from_documents(documents_all, storage_context)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "We want to only retrieve documents from the file `uber_2021.pdf`."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "d9f9bcb5-43de-4983-b754-a822ac7b5278",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The disease posed challenges related to the adverse impact on the business and operations, including reduced demand for Mobility offerings globally, affecting travel behavior and demand. Additionally, the pandemic led to driver supply constraints, impacted by concerns regarding COVID-19, with uncertainties about when supply levels would return to normal. The rise of the Omicron variant further affected travel, resulting in advisories and restrictions that could adversely impact both driver supply and consumer demand for Mobility offerings.\n"
+ ]
+ }
+ ],
+ "source": [
+ "filters = MetadataFilters(\n",
+ " filters=[ExactMatchFilter(key=\"file_name\", value=\"uber_2021.pdf\")]\n",
+ ")\n",
+ "query_engine = index.as_query_engine(filters=filters)\n",
+ "res = query_engine.query(\"What challenges did the disease pose for the author?\")\n",
+ "\n",
+ "print(res)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "We get a different result this time when retrieve from the file `paul_graham_essay.txt`."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "id": "0f134a35-dbd3-49d8-b7d8-48bdd2349701",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The disease posed challenges for the author as it affected his mother's health, leading to a stroke caused by colon cancer. This resulted in his mother losing her balance and needing to be placed in a nursing home. The author and his sister were determined to help their mother get out of the nursing home and back to her house.\n"
+ ]
+ }
+ ],
+ "source": [
+ "filters = MetadataFilters(\n",
+ " filters=[ExactMatchFilter(key=\"file_name\", value=\"paul_graham_essay.txt\")]\n",
+ ")\n",
+ "query_engine = index.as_query_engine(filters=filters)\n",
+ "res = query_engine.query(\"What challenges did the disease pose for the author?\")\n",
+ "\n",
+ "print(res)"
]
}
],
@@ -377,9 +468,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.19"
+ "version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
-}
+}
\ No newline at end of file
diff --git a/bootcamp/tutorials/integration/semantic_search_with_milvus_and_openai.ipynb b/bootcamp/tutorials/integration/semantic_search_with_milvus_and_openai.ipynb
index 85b572545..3b0e9211b 100644
--- a/bootcamp/tutorials/integration/semantic_search_with_milvus_and_openai.ipynb
+++ b/bootcamp/tutorials/integration/semantic_search_with_milvus_and_openai.ipynb
@@ -116,7 +116,7 @@
"# Connect to Milvus, all data is stored in a local file named \"milvus_openai_demo.db\"\n",
"# in current directory. You can also connect to a remote Milvus server following this\n",
"# instruction: https://milvus.io/docs/install_standalone-docker.md.\n",
- "milvus_client = MilvusClient(\"milvus_openai_demo.db\")\n",
+ "milvus_client = MilvusClient(uri=\"milvus_openai_demo.db\")\n",
"COLLECTION_NAME = \"demo_collection\" # Milvus collection name\n",
"# Create a collection to store the vectors and text.\n",
"if milvus_client.has_collection(collection_name=COLLECTION_NAME):\n",
@@ -132,10 +132,24 @@
"outputs": [],
"execution_count": null
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"metadata": {},
"cell_type": "markdown",
- "source": "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search.",
+ "source": [
+ "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search."
+ ],
"id": "180883400043b828"
},
{
diff --git a/bootcamp/tutorials/integration/semantic_search_with_milvus_and_voyageai.ipynb b/bootcamp/tutorials/integration/semantic_search_with_milvus_and_voyageai.ipynb
index 63f909db3..46c4766f5 100644
--- a/bootcamp/tutorials/integration/semantic_search_with_milvus_and_voyageai.ipynb
+++ b/bootcamp/tutorials/integration/semantic_search_with_milvus_and_voyageai.ipynb
@@ -112,7 +112,7 @@
"# Connect to Milvus, all data is stored in a local file named \"milvus_voyage_demo.db\"\n",
"# in current directory. You can also connect to a remote Milvus server following this\n",
"# instruction: https://milvus.io/docs/install_standalone-docker.md.\n",
- "milvus_client = MilvusClient(\"milvus_voyage_demo.db\")\n",
+ "milvus_client = MilvusClient(uri=\"milvus_voyage_demo.db\")\n",
"COLLECTION_NAME = \"demo_collection\" # Milvus collection name\n",
"# Create a collection to store the vectors and text.\n",
"if milvus_client.has_collection(collection_name=COLLECTION_NAME):\n",
@@ -131,10 +131,24 @@
"outputs": [],
"execution_count": null
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"metadata": {},
"cell_type": "markdown",
- "source": "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search.",
+ "source": [
+ "With all data in Milvus vector database, we can now perform semantic search by generating vector embedding for the query and conduct vector search."
+ ],
"id": "d0e23c54d75520a9"
},
{
diff --git a/bootcamp/tutorials/integration/vanna_write_sql.ipynb b/bootcamp/tutorials/integration/vanna_write_sql.ipynb
index 34ce8f969..ca3908e15 100644
--- a/bootcamp/tutorials/integration/vanna_write_sql.ipynb
+++ b/bootcamp/tutorials/integration/vanna_write_sql.ipynb
@@ -141,8 +141,11 @@
},
"source": [
"We initialize the `VannaMilvus` class with the necessary configuration parameters. We use a `milvus_client` instance to store embeddings and the `model.DefaultEmbeddingFunction()` initialized from [milvus_model](https://milvus.io/docs/embeddings.md) to generate embeddings.\n",
- "> Setting the milvus_uri as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
- "If you have large scale of data such as more than a million docs, we recommend setting up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). When using this setup, please use the server URI, e.g.`http://localhost:19530`, as your milvus_uri."
+ "\n",
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
]
},
{
@@ -160,7 +163,6 @@
"outputs": [],
"source": [
"milvus_uri = \"./milvus_vanna.db\"\n",
- "# milvus_uri = \"http://localhost:19530\"\n",
"\n",
"milvus_client = MilvusClient(uri=milvus_uri)\n",
"\n",
diff --git a/bootcamp/tutorials/quickstart/build_RAG_with_milvus.ipynb b/bootcamp/tutorials/quickstart/build_RAG_with_milvus.ipynb
index d61c0be4e..297b964ec 100644
--- a/bootcamp/tutorials/quickstart/build_RAG_with_milvus.ipynb
+++ b/bootcamp/tutorials/quickstart/build_RAG_with_milvus.ipynb
@@ -208,11 +208,23 @@
"source": [
"from pymilvus import MilvusClient\n",
"\n",
- "milvus_client = MilvusClient(\"./milvus_demo.db\")\n",
+ "milvus_client = MilvusClient(uri=\"./milvus_demo.db\")\n",
"\n",
"collection_name = \"my_rag_collection\""
]
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"cell_type": "markdown",
"metadata": {},
diff --git a/bootcamp/tutorials/quickstart/image_search_with_milvus.ipynb b/bootcamp/tutorials/quickstart/image_search_with_milvus.ipynb
index e3daff292..9152a2872 100644
--- a/bootcamp/tutorials/quickstart/image_search_with_milvus.ipynb
+++ b/bootcamp/tutorials/quickstart/image_search_with_milvus.ipynb
@@ -164,6 +164,18 @@
")"
]
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "> As for the argument of `MilvusClient`:\n",
+ "> - Setting the `uri` as a local file, e.g.`./milvus.db`, is the most convenient method, as it automatically utilizes [Milvus Lite](https://milvus.io/docs/milvus_lite.md) to store all data in this file.\n",
+ "> - If you have large scale of data, you can set up a more performant Milvus server on [docker or kubernetes](https://milvus.io/docs/quickstart.md). In this setup, please use the server uri, e.g.`http://localhost:19530`, as your `uri`.\n",
+ "> - If you want to use [Zilliz Cloud](https://zilliz.com/cloud), the fully managed cloud service for Milvus, adjust the `uri` and `token`, which correspond to the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud."
+ ],
+ "metadata": {
+ "collapsed": false
+ }
+ },
{
"cell_type": "markdown",
"metadata": {},