|
15 | 15 | "source": [ |
16 | 16 | "import os\n", |
17 | 17 | "import json\n", |
| 18 | + "import pymongo\n", |
18 | 19 | "from typing import List\n", |
19 | 20 | "from dotenv import load_dotenv\n", |
20 | 21 | "from pymongo import MongoClient\n", |
|
74 | 75 | "\n", |
75 | 76 | "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", |
76 | 77 | "\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", |
78 | 79 | "\n", |
79 | 80 | "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", |
80 | 81 | "\n", |
|
206 | 207 | "response = rag_chain.invoke(question)\n", |
207 | 208 | "print(response)" |
208 | 209 | ] |
| 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 | + ] |
209 | 237 | } |
210 | 238 | ], |
211 | 239 | "metadata": { |
|
0 commit comments