Skip to content

Commit 92760e0

Browse files
authored
Merge pull request #20 from mongodb-developer/add_voyageai
Voyage AI doc update
2 parents 40a3f2b + 6bea17f commit 92760e0

28 files changed

+191
-125
lines changed

docs/10-key-concepts/3-components-of-rag.mdx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,47 @@ RAG systems have two main components: **Retrieval** and **Generation**.
66

77
Retrieval mainly involves processing your data and constructing a knowledge base in a way that you are able to efficiently retrieve relevant information from it. It typically involves three main steps:
88

9-
* **Chunking**: Break down large pieces of information into smaller segments or chunks.
9+
### Chunking
1010

11-
* **Embedding**: Convert a piece of information such as text, images, audio, video, etc. into an array of numbers a.k.a. vectors.
11+
Chunking is the process of breaking down large pieces of mainly text into smaller segments or chunks. At retrieval time, only the chunks that are most relevant to the user queries are retrieved. This helps reduce generation costs since fewer tokens are used. It also helps reduce hallucinations by focusing the attention of LLMs on the most relevant information, rather than having them sift through a large body of text to identify the relevant parts.
1212

13-
* **Vector Search**: Retrieve the most relevant documents from the knowledge base based on embedding similarity with the query vector.
13+
There are several common chunking methodologies for RAG:
14+
* **Fixed token with overlap**: Splits text into chunks consisting of a fixed number of tokens, with some overlap between chunks to avoid context loss at chunk boundaries.
15+
16+
![](/img/screenshots/10-key-concepts/fixed-token.png)
17+
18+
* **Recursive with overlap**: First splits text on a set of characters and recursively merges them into tokens until the desired chunk size is reached. This has the effect of keeping related text in the same chunk to the extent possible.
19+
20+
![](/img/screenshots/10-key-concepts/recursive.png)
21+
22+
* **Semantic**: Creates splits at semantic boundaries, typically identified using an LLM.
23+
24+
25+
![](/img/screenshots/10-key-concepts/semantic.png)
26+
27+
28+
### Embedding
29+
30+
Convert a piece of information such as text, images, audio, video, etc. into an array of numbers a.k.a. vectors. Read more about embeddings [here](https://mongodb-developer.github.io/vector-search-lab/docs/key-concepts/embeddings).
31+
32+
### Vector Search:
33+
34+
Retrieve the most relevant documents from a knowledge base based on their similarity to the embedding of the query vector. Read more about vector search and how it works in MongoDB [here](https://mongodb-developer.github.io/vector-search-lab/docs/key-concepts/vector-search).
1435

1536
## Generation
1637

17-
Generation involves crafting a prompt that contains all the instructions and information required by the LLM to generate accurate answers to user queries.
38+
Generation involves passing the information retrieved using vector search, system prompts, the user query and information from past interactions (memory) to the LLM for it to generate context-aware responses to user questions.
39+
40+
Here's an example of what a RAG prompt might look like:
41+
42+
```
43+
# System prompt
44+
Answer the question based on the context below. If no context is provided, respond with I DON’T KNOW.
45+
# Retrieved context
46+
Context: <CONTEXT>
47+
# Memory
48+
User: Give me a summary of Q4 earnings for ABMD.
49+
Assistant: <ANSWER>
50+
# User question
51+
Question: What were some comments made by the CEO?
52+
```

docs/20-dev-env/1-dev-env-setup.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Screenshot from "@site/src/components/Screenshot";
1414

1515
<Screenshot url="https://play.instruqt.com" src="img/screenshots/20-dev-env/1-dev-env-setup/instruqt/1-resume-sandbox.png" alt="Resume sandbox" />
1616

17-
In the Explorer menu, navigate to `genai-devday-notebooks` > `notebooks` > `ai-rag-lab.ipynb` This is the Jupyter Notebook you will be using throughout this lab.
17+
In the Explorer menu, navigate to `genai-devday-notebooks` > `labs` > `ai-rag-lab.ipynb` This is the Jupyter Notebook you will be using throughout this lab.
1818

1919
<Screenshot url="https://play.instruqt.com" src="img/screenshots/20-dev-env/1-dev-env-setup/instruqt/2-nav-notebook.png" alt="Navigate to the notebook" />
2020

@@ -29,7 +29,7 @@ import Screenshot from "@site/src/components/Screenshot";
2929

3030
<Screenshot url="https://github.com/codespaces" src="img/screenshots/20-dev-env/1-dev-env-setup/codespaces/1-resume-codespace.png" alt="Resume codespace" />
3131

32-
Give the codespace a few seconds to restart. When files appear in the Explorer tab, click on the file named `ai-rag-lab.ipynb` under `notebooks`. This is the Jupyter Notebook you will be using throughout this lab.
32+
Give the codespace a few seconds to restart. When files appear in the Explorer tab, click on the file named `ai-rag-lab.ipynb` under `labs`. This is the Jupyter Notebook you will be using throughout this lab.
3333

3434
<Screenshot url="https://github.com/codespaces" src="img/screenshots/20-dev-env/1-dev-env-setup/codespaces/2-nav-notebook.png" alt="Navigate to the notebook" />
3535
</TabItem>
@@ -89,7 +89,7 @@ You will also see the default databases in the cluster appear under **Connection
8989

9090
You will be filling code in a Jupyter Notebook during this lab, so let's get set up with that next!
9191

92-
Within the sandbox, click on the files icon in the left navigation bar of the IDE. In the Explorer menu, navigate to `genai-devday-notebooks` > `notebooks` > `ai-rag-lab.ipynb` to open the Jupyter Notebook for this lab.
92+
Within the sandbox, click on the files icon in the left navigation bar of the IDE. In the Explorer menu, navigate to `genai-devday-notebooks` > `labs` > `ai-rag-lab.ipynb` to open the Jupyter Notebook for this lab.
9393

9494
<Screenshot url="https://play.instruqt.com" src="img/screenshots/20-dev-env/1-dev-env-setup/instruqt/2-nav-notebook.png" alt="Navigate to the notebook" />
9595

@@ -143,7 +143,7 @@ You will also see the default databases in the cluster appear under **Connection
143143

144144
You will be filling code in a Jupyter Notebook during this lab, so let's get set up with that next!
145145

146-
Within the codespace, click on the files icon in the left navigation bar of the IDE. In the Explorer menu, under `notebooks`, click on the file named `ai-rag-lab.ipynb` to open the Jupyter Notebook for this lab.
146+
Within the codespace, click on the files icon in the left navigation bar of the IDE. In the Explorer menu, under `labs`, click on the file named `ai-rag-lab.ipynb` to open the Jupyter Notebook for this lab.
147147

148148
<Screenshot url="https://github.com/codespaces" src="img/screenshots/20-dev-env/1-dev-env-setup/codespaces/2-nav-notebook.png" alt="Navigate to the notebook" />
149149

@@ -161,10 +161,10 @@ To run the lab locally, follow the steps below:
161161
git clone https://github.com/mongodb-developer/genai-devday-notebooks.git
162162
```
163163

164-
* `cd` into the `notebooks` directory of the cloned repository:
164+
* `cd` into the `labs` directory of the cloned repository:
165165

166166
```
167-
cd genai-devday-notebooks/notebooks
167+
cd genai-devday-notebooks/labs
168168
```
169169

170170
* Create and activate a Python virtual environment:
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
# 👐 Setup prerequisites
22

3-
Run the cells under **Step 1: Setup prerequisites** section in the notebook.
3+
Set the passkey provided by your workshop instructor, and run the cells under the **Step 1: Setup prerequisites** section in the notebook.
44

5-
:::info
5+
### Expired passkey OR don't have a passkey
66

7-
Additional steps **if you are running the lab locally**:
7+
Passkeys are provided to you at MongoDB Developer Days to easily get API keys for LLM and embedding APIs that are used in the workshop. These passkeys are valid for 3 days after the workshop.
88

9-
* Spin up a MongoDB Atlas cluster and obtain its connection string:
9+
Once the passkey expires, or if you weren't at a MongoDB Developer Day recently, you will need to obtain the following API keys for the workshop:
10+
11+
**VoyageAI**
12+
13+
* Follow the steps here to [obtain a Voyage AI API key](https://docs.voyageai.com/docs/api-key-and-installation#authentication-with-api-keys).
14+
* Set the `VOYAGE_API_KEY` environment variable in the notebook as follows:
15+
16+
```python
17+
os.environ["VOYAGE_API_KEY"] = "your-voyageai-api-key"
18+
```
19+
20+
### If you are running the lab locally
21+
22+
If you aren't using Instruqt or GitHub Codespaces to run the lab and instead running it locally, you will need to do the following additional steps:
23+
24+
* Spin up a free MongoDB Atlas cluster and obtain its connection string:
1025

1126
* Register for a [free MongoDB Atlas account](https://www.mongodb.com/cloud/atlas/register) if you don't already have one
1227
* [Create a new database cluster](https://www.mongodb.com/docs/guides/atlas/cluster)
1328
* [Obtain the connection string](https://www.mongodb.com/docs/guides/atlas/connection-string) for your database cluster
1429

15-
* Set the `MONGODB_URI` variable to the connection string for your cluster as follows:
30+
* Set the `MONGODB_URI` variable in the notebook as follows:
1631

1732
```python
18-
MONGODB_URI = "<your_connection_string>"
33+
MONGODB_URI = "your_connection_string"
1934
```
2035

21-
* Manually set the value of the `SERVERLESS_URL` variable as follows:
36+
* Manually set the `PROXY_ENDPOINT` variable in the notebook as follows:
2237

2338
```python
24-
SERVERLESS_URL = "https://vtqjvgchmwcjwsrela2oyhlegu0hwqnw.lambda-url.us-west-2.on.aws/"
25-
```
26-
:::
39+
PROXY_ENDPOINT = "https://vtqjvgchmwcjwsrela2oyhlegu0hwqnw.lambda-url.us-west-2.on.aws/"
40+
```

docs/30-prepare-the-data/2-chunk-data.mdx

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 👐 Chunk and embed the data
2+
3+
Since we are working with large documents, we first need to break them up into smaller chunks. Then, to make each chunk searchable using vector search, we need to add embeddings to them.
4+
5+
In this workshop, we will use _voyage-context-3_ from Voyage AI to produce contextualized embeddings for the chunks.
6+
7+
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 3: Chunk and embed the data** section in the notebook to chunk and embed the articles we loaded.
8+
9+
The answers for code blocks in this section are as follows:
10+
11+
**CODE_BLOCK_1**
12+
13+
<details>
14+
<summary>Answer</summary>
15+
<div>
16+
```python
17+
text_splitter.split_text(text)
18+
```
19+
</div>
20+
</details>
21+
22+
**CODE_BLOCK_2**
23+
24+
<details>
25+
<summary>Answer</summary>
26+
<div>
27+
```python
28+
vo.contextualized_embed(inputs=[content], model="voyage-context-3", input_type=input_type)
29+
```
30+
</div>
31+
</details>
32+
33+
**CODE_BLOCK_3**
34+
35+
<details>
36+
<summary>Answer</summary>
37+
<div>
38+
```python
39+
get_chunks(doc, "body")
40+
```
41+
</div>
42+
</details>
43+
44+
**CODE_BLOCK_4**
45+
46+
<details>
47+
<summary>Answer</summary>
48+
<div>
49+
```python
50+
get_embeddings(chunks, "document")
51+
```
52+
</div>
53+
</details>
54+
55+
**CODE_BLOCK_5**
56+
57+
<details>
58+
<summary>Answer</summary>
59+
<div>
60+
```python
61+
chunk_doc["body"] = chunk
62+
```
63+
</div>
64+
</details>
65+
66+
**CODE_BLOCK_6**
67+
68+
<details>
69+
<summary>Answer</summary>
70+
<div>
71+
```python
72+
chunk_doc["embedding"] = embedding
73+
```
74+
</div>
75+
</details>

docs/30-prepare-the-data/3-embed-data.mdx

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/30-prepare-the-data/4-ingest-data.mdx renamed to docs/30-prepare-the-data/3-ingest-data.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 5:
88

99
The answers for code blocks in this section are as follows:
1010

11-
**CODE_BLOCK_5**
11+
**CODE_BLOCK_7**
1212

1313
<details>
1414
<summary>Answer</summary>

docs/40-perform-vector-search/2-create-vector-index.mdx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,4 @@
22

33
To retrieve documents from MongoDB using vector search, you must configure a vector search index on the collection into which you ingested your data. In this lab, you will programmatically create vector search indexes using MongoDB's Python driver.
44

5-
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 6: Create a vector search index** section in the notebook to create a vector search index.
6-
7-
The answers for code blocks in this section are as follows:
8-
9-
**CODE_BLOCK_6**
10-
11-
<details>
12-
<summary>Answer</summary>
13-
<div>
14-
15-
```python
16-
create_index(collection, ATLAS_VECTOR_SEARCH_INDEX_NAME, model)
17-
```
18-
19-
</div>
20-
</details>
5+
Run the cells under the **Step 5: Create a vector search index** section in the notebook to create a vector search index.

docs/40-perform-vector-search/3-vector-search.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
Now let's run some vector search queries against the data present in MongoDB.
44

5-
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 7: Perform vector search on your data** section in the notebook to run vector search queries against your data.
5+
Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 6: Perform vector search on your data** section in the notebook to run vector search queries against your data.
66

77
The answers for code blocks in this section are as follows:
88

9-
**CODE_BLOCK_7**
9+
**CODE_BLOCK_8**
1010

1111
<details>
1212
<summary>Answer</summary>
1313
<div>
1414
```python
15-
get_embedding(user_query)
15+
get_embeddings([user_query], "query")
1616
```
1717
</div>
1818
</details>
1919

20-
**CODE_BLOCK_8**
20+
**CODE_BLOCK_9**
2121

2222
<details>
2323
<summary>Answer</summary>
@@ -37,6 +37,9 @@ get_embedding(user_query)
3737
"$project": {
3838
"_id": 0,
3939
"body": 1,
40+
"metadata.productName": 1,
41+
"metadata.contentType": 1,
42+
"updated": 1,
4043
"score": {"$meta": "vectorSearchScore"}
4144
}
4245
}
@@ -45,7 +48,7 @@ get_embedding(user_query)
4548
</div>
4649
</details>
4750

48-
**CODE_BLOCK_9**
51+
**CODE_BLOCK_10**
4952

5053
<details>
5154
<summary>Answer</summary>

0 commit comments

Comments
 (0)