Skip to content

Commit 5873156

Browse files
committed
Added the creation of an agent with tools to LangChain lab
1 parent ffdc62a commit 5873156

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"source": [
1616
"import os\n",
1717
"import json\n",
18+
"import pymongo\n",
1819
"from typing import List\n",
1920
"from dotenv import load_dotenv\n",
2021
"from pymongo import MongoClient\n",
@@ -74,7 +75,7 @@
7475
"\n",
7576
"In the previous lab, the `pymongo` library was used to perform a vector search through a db command to find product documents that were most similar to the user's input. In this lab, you will use the `langchain` library to perform the same search. LangChain has a vector store class named **AzureCosmosDBVectorSearch**, a community contribution, that supports vector search in Azure CosmosDB for MongoDB API vCore.\n",
7677
"\n",
77-
"When establishing the connection to the vector store (MongoDB vCore), remember that in previous labs the products collection was populated and a contentVector field added that contains the vectorized embeddings of the document itself. Finally, a vector index was also created on the contentVector field to enable vector search.\n",
78+
"When establishing the connection to the vector store (MongoDB vCore), recall that in previous labs the products collection was populated and a contentVector field added that contains the vectorized embeddings of the document itself. Finally, a vector index was also created on the contentVector field to enable vector search. The vector index in each collection is named `VectorSearchIndex`.\n",
7879
"\n",
7980
"The return value of a vector search in LangChain is a list of `Document` objects. The LangChain `Document` class contains two properties: `page_content`, that represents the textual content that is typically used to augment the prompt, and `metadata` that contains all other attributes of the document. In the cell below, we'll use the `_id` field as the page_content, and the rest of the fields are returned as metadata.\n",
8081
"\n",
@@ -206,6 +207,33 @@
206207
"response = rag_chain.invoke(question)\n",
207208
"print(response)"
208209
]
210+
},
211+
{
212+
"cell_type": "markdown",
213+
"metadata": {},
214+
"source": [
215+
"## LangChain Agent"
216+
]
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": null,
221+
"metadata": {},
222+
"outputs": [],
223+
"source": [
224+
"client = pymongo.MongoClient(CONNECTION_STRING)\n",
225+
"db = client.cosmic_works"
226+
]
227+
},
228+
{
229+
"cell_type": "code",
230+
"execution_count": null,
231+
"metadata": {},
232+
"outputs": [],
233+
"source": [
234+
"# Create custom code lookup tools that retrieves documents from the customers, products, and salesorders collections by ID.\n",
235+
"def"
236+
]
209237
}
210238
],
211239
"metadata": {

0 commit comments

Comments
 (0)