-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mongodb-developer/langgraph_updates
LangGraph updates
- Loading branch information
Showing
52 changed files
with
446 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 👐 Setup prerequisites | ||
|
||
Fill in any placeholders and run the cells under the **Step 1: Install libraries** and **Step 2: Setup prerequisites** sections in the notebook. |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 📘 Concepts | ||
|
||
Here is a quick overview of concepts that you will come across in this section of the lab: | ||
|
||
## Tool calling | ||
|
||
Tool calling, interchangeably called function calling allows an LLM to use external tools such as APIs, databases, specialized machine learning models etc. | ||
|
||
In AI agents, an LLM can have access to multiple tools. Given a user query, the LLM decides which tool to invoke and the arguments for the tool call. These arguments are used to execute the tool call and the output is returned back to the LLM to inform its next steps. | ||
|
||
The easiest way to define tools in LangChain is using the `@tool` decorator. The decorator makes tools out of functions by using the function name as the tool name by default, and the function's docstring as the tool's description. The tool call inturn consists of a tool name, arguments, and an optional identifier. | ||
|
||
An example of a tool in LangChain is as follows: | ||
|
||
``` | ||
@tool("search-tool", return_direct=True) | ||
def search(query: str) -> str: | ||
"""Look up things online.""" | ||
return "MongoDB" | ||
``` | ||
An example of a tool call is as follows: | ||
|
||
``` | ||
{ | ||
"name": "search-tool", | ||
"args": { | ||
"query": "What is MongoDB?" | ||
}, | ||
"id": "call_H5TttXb423JfoulF1qVfPN3m" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 👐 Import data | ||
|
||
The MongoDB learning assistant has two tools- a vector search tool to retrieve information to answer questions about MongoDB, and another tool to get the content of articles in our Developer Center for summarization. | ||
|
||
Let's import the data required by these tools into two MongoDB collections. This is as simple as making a `GET` request to a serverless function that we have created for you. | ||
|
||
Run the cells under the **Step 3: Import data** section in the notebook to import the data required by our agent's tools, into MongoDB collections. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 👐 Create a vector search index | ||
|
||
To retrieve documents using vector search, you must configure a vector search index on the collection you want to perform vector search against. | ||
|
||
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 4: Create a vector search index** section in the notebook to create a vector search index. | ||
|
||
The answers for code blocks in this section are as follows: | ||
|
||
**CODE_BLOCK_1** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
mongodb_client[DB_NAME][VS_COLLECTION_NAME] | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_2** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
vs_collection.create_search_index(model=model) | ||
``` | ||
</div> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# 👐 Create agent tools | ||
|
||
The easiest way to define custom tools for agents in LangChain is using the `@tool` decorator. The decorator makes tools out of functions by using the function name as the tool name by default, and the function's docstring as the tool's description. | ||
|
||
We want the MongoDB learning assistant to have access to the following tools: | ||
|
||
* `get_information_for_question_answering`: Uses vector search to retrieve information to answer questions | ||
|
||
* `get_article_content_for_summarization`: Gets the content of articles for summarization | ||
|
||
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 5: Create agent tools** section in the notebook to create tools for the agent to use. | ||
|
||
The answers for code blocks in this section are as follows: | ||
|
||
**CODE_BLOCK_3** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
embedding_model.encode(text) | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_4** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
get_embedding(user_query) | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_5** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
[ | ||
{ | ||
"$vectorSearch": { | ||
"index": VS_INDEX_NAME, | ||
"path": "embedding", | ||
"queryVector": query_embedding, | ||
"numCandidates": 150, | ||
"limit": 5, | ||
} | ||
}, | ||
{ | ||
"$project": { | ||
"_id": 0, | ||
"body": 1, | ||
"score": {"$meta": "vectorSearchScore"}, | ||
} | ||
}, | ||
] | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_6** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
vs_collection.aggregate(pipeline) | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_7** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
mongodb_client[DB_NAME][FULL_COLLECTION_NAME] | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_8** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
{"title": user_query} | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_9** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
{"_id": 0, "body": 1} | ||
``` | ||
</div> | ||
</details> | ||
|
||
**CODE_BLOCK_10** | ||
|
||
<details> | ||
<summary>Answer</summary> | ||
<div> | ||
```python | ||
full_collection.find_one(query, projection) | ||
``` | ||
</div> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.