Skip to content

Commit c4b9b17

Browse files
author
ajosh0504
committed
Adding concepts
1 parent 1915dc1 commit c4b9b17

File tree

13 files changed

+119
-11
lines changed

13 files changed

+119
-11
lines changed

docs/10-rag/1-what-is-rag.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# 📘 What is RAG?
22

3-
TO-DO
3+
![](/img/screenshots/10-rag/rag.png)
4+
5+
RAG, short for Retrieval Augmented Generation, is a technique to enhance the quality of responses generated by a large language model (LLM), by augmenting its pre-trained knowledge with information retrieved from external sources. This results is more accurate responses from the LLM by grounding them in real, contextually relevant data.

docs/10-rag/2-rag-usecases.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1-
# 📘 RAG use cases
1+
# 📘 When to use RAG?
22

3-
TO-DO
3+
RAG is best suited for the following:
4+
* Tasks that require very specific information that you don’t think will be present in the LLMs parametric knowledge i.e. information that is not widely available on the internet
5+
* Tasks that require information from multiple different data sources
6+
* Tasks that involve basic question-answering or summarization on a piece of information
7+
8+
Do not expect success on complex multi-step tasks involving deductive reasoning or long-term planning. These are more suited for agentic workflows.
9+
10+
Here are some examples of tasks/questions that **DO NOT** require or cannot be achieved with RAG:
11+
12+
> Who was the first president of the United States?
13+
14+
The information required to answer this question is very likely present in the parametric knowledge of most LLMs. Hence, this question can be answered using a simple prompt to an LLM.
15+
16+
> How has the trend in the average daily calorie intake among adults changed over the last decade in the United States, and what impact might this have on obesity rates? Additionally, can you provide a graphical representation of the trend in obesity rates over this period?
17+
18+
This question involves multiple sub-tasks such as data aggregation, visualization, and reasoning. Hence, this is a good use case for an AI agent rather than RAG.
19+
20+
Here are some use cases for RAG:
21+
22+
> What is the travel reimbursement policy for meals for my company?
23+
24+
The information required to answer this question is most likely not present in the parametric knowledge of available LLMs. However, this question can easily be answered using RAG on a knowledge base consisting of your company's data.
25+
26+
> Hi, I'm having trouble installing your software on my Windows 10 computer. It keeps giving me an error message saying 'Installation failed: Error code 1234'. How can I resolve this issue?
27+
28+
Again, this question requires troubleshooting information for a specific software, the documentation for which might not be widely available, but can be solved using RAG.

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# 📘 Components of a RAG system
22

3-
TO-DO
3+
RAG systems have two main components: **Retrieval** and **Generation**.
4+
5+
## Retrieval
6+
7+
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:
8+
9+
* **Chunking**: Break down large pieces of information into smaller segments or chunks.
10+
11+
* **Embedding**: Convert a piece of information such as text, images, audio, video, etc. into an array of numbers a.k.a. vectors.
12+
13+
* **Semantic Search**: Retrieve the most relevant documents from the knowledge base based on embedding similarity with the query vector.
14+
15+
## Generation
16+
17+
Generation involves crafting a prompt that contains all the instructions and information required by the LLM to generate accurate answers to user queries.
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# 📘 Tools, libraries, and concepts
22

3-
TO-DO
3+
## [datasets](https://huggingface.co/docs/datasets/en/index)
4+
5+
Library used to download a dataset of MongoDB Developer center tutorials from Hugging Face.
6+
7+
## [RecursiveCharacterTextSplitter](https://python.langchain.com/v0.1/docs/modules/data_connection/document_transformers/split_by_token/)
8+
9+
A LangChain text splitter that first splits documents by a list of characters and then recursively merges characters into tokens until the specified chunk size is reached.
10+
11+
## [Sentence Transformers](https://sbert.net/)
12+
13+
Python library for accessing, using, and training open-source embedding models.
14+
15+
## [PyMongo](https://pymongo.readthedocs.io/en/stable/)
16+
17+
Python driver for MongoDB. Used to connect to MongoDB databases, delete and insert documents into a MongoDB collection.
Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1-
# 📘 Tools, libraries, and concepts
1+
# 📘 Semantic search in MongoDB
22

3-
TO-DO
3+
In MongoDB, you can semantically search through your data using MongoDB Atlas Vector Search.
4+
5+
To perform vector search on your data in MongoDB, you need to create a vector search index. An example of a vector search index definition looks as follows:
6+
7+
```
8+
{
9+
"fields":[
10+
{
11+
"type": "vector",
12+
"path": "embedding",
13+
"numDimensions": 1536,
14+
"similarity": "euclidean | cosine | dotProduct"
15+
},
16+
{
17+
"type": "filter",
18+
"path": "symbol"
19+
},
20+
...
21+
]
22+
}
23+
```
24+
25+
In the index definition, you specify the path to the embedding field (`path`), the number of dimensions in the embedding vectors (`numDimensions`), and a similarity metric that specifies how to determine nearest neighbors (`similarity`). You can also index filter fields that allow you to pre-filter on certain metadata to narrow the scope of the vector search.
26+
27+
Vector search in MongoDB takes the form of an aggregation pipeline stage. It always needs to be the first stage in the pipeline and can be followed by other stages to further process the semantic search results. An example pipeline including the `$vectorSearch` stage is as follows:
28+
29+
```
30+
[
31+
{
32+
"$vectorSearch": {
33+
"index": "vector_index",
34+
"path": "embedding",
35+
"filter": {"symbol": "ABMD"},
36+
"queryVector": [0.02421053, -0.022372592,...],
37+
"numCandidates": 150,
38+
"limit": 10
39+
}
40+
},
41+
{
42+
"$project": {
43+
"_id": 0,
44+
"Content": 1,
45+
"score": {"$meta": "vectorSearchScore"}
46+
}
47+
}
48+
]
49+
```
50+
51+
In this example, you can see a vector search query with a pre-filter. The `limit` field in the query definition specifies how many documents to return from the vector search.
52+
53+
The `$project` stage that follows only returns documents with the `Content` field and the similarity score from the vector search.

docs/70-build-rag-app/1-concepts.mdx

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

docs/80-add-memory/1-concepts.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# 📘 Tools, libraries, and concepts
22

3-
TO-DO
3+
Memory is important for the LLM to have multi-turn conversations with the user.
4+
5+
In this lab, you will persist chat messages in a separate MongoDB collection, indexed by session ID.
6+
7+
For each new user query, you will fetch previous messages for that session from the collection and pass them to the LLM.
8+
9+
Then once the LLM has generated a response to the query, you will write the query and the LLM's answer to the collection as two separate entries but having the same session ID.
Binary file not shown.
-757 KB
Binary file not shown.

static/img/screenshots/10-rag/rag.png

111 KB
Loading

0 commit comments

Comments
 (0)