You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/how-to-implement-rag-generativeapis/index.mdx
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,7 +96,7 @@ Create an `embed.py` file and add the following code to it:
96
96
97
97
### Configure embeddings client
98
98
99
-
4.Edit `embed.py` to configure [OpenAIEmbeddings](https://api.python.langchain.com/en/latest/embeddings/langchain_openai.embeddings.base.OpenAIEmbeddings.html) class from LangChain to use your API Secret Key, Generative APIs Endpoint URL and a supported model (`bge-multilingual-gemma2` in our example).
99
+
Edit `embed.py` to configure [OpenAIEmbeddings](https://api.python.langchain.com/en/latest/embeddings/langchain_openai.embeddings.base.OpenAIEmbeddings.html) class from LangChain to use your API Secret Key, Generative APIs Endpoint URL, and a supported model (`bge-multilingual-gemma2`, in our example).
6.At this stage, you need to have data (e.g. PDF files) stored in your Scaleway Object storage bucket. As examples, you can download our [Instance CLI cheatsheet](https://www-uploads.scaleway.com/Instances_CLI_Cheatsheet_7ae4ed5564.pdf) and our[Kubernetes cheatsheets](https://www.scaleway.com/en/docs/static/be9a6e5821a4e8e268c7c5bd3624e256/scaleway-kubernetes-cheatsheet.pdf) and store them into your [Object Storage bucket](https://console.scaleway.com/object-storage/buckets).
125
+
At this stage, you need to have data (e.g. PDF files) stored in your Scaleway Object storage bucket. As examples, you can download our [Instance CLI cheatsheet](https://www-uploads.scaleway.com/Instances_CLI_Cheatsheet_7ae4ed5564.pdf) and [Kubernetes cheatsheets](https://www.scaleway.com/en/docs/static/be9a6e5821a4e8e268c7c5bd3624e256/scaleway-kubernetes-cheatsheet.pdf) and store them into your [Object Storage bucket](https://console.scaleway.com/object-storage/buckets).
126
126
127
127
Below we will use LangChain's [`S3DirectoryLoader`](https://api.python.langchain.com/en/latest/document_loaders/langchain_community.document_loaders.s3_file.S3FileLoader.html) to load documents, and split them into chunks.
128
128
Then, we will embed them as vectors and store these vectors in your PostgreSQL database.
129
129
130
130
### Import required modules
131
131
132
-
7.Edit the beginning of `embed.py` to import `S3DirectoryLoader` and `RecursiveCharacterTextSplitter`:
132
+
Edit the beginning of `embed.py` to import `S3DirectoryLoader` and `RecursiveCharacterTextSplitter`:
133
133
134
134
```python
135
135
from langchain_community.document_loaders import S3DirectoryLoader
@@ -138,7 +138,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
138
138
139
139
### Iterate through objects
140
140
141
-
8.Edit `embed.py` to load all files in your bucket using `S3DirectoryLoader`, split them into chunks of 500 characters using `RecursiveCharacterTextSplitter` and embed them and store them into your PostgreSQL database using `PGVector`.
141
+
Edit `embed.py` to load all files in your bucket using `S3DirectoryLoader`, split them into chunks of 500 characters using `RecursiveCharacterTextSplitter` and embed them and store them into your PostgreSQL database using `PGVector`.
@@ -158,7 +158,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
158
158
159
159
The chunk size of 500 characters is chosen to fit within the context size limit of the embedding model used in this tutorial, but could be raised to up to 4096 characters for `bge-multilingual-gemma2` model (or slightly more as context size is counted in tokens). Keeping chunks small also optimizes performance during inference.
160
160
161
-
9.You can now run you vector embedding script with:
161
+
You can now run you vector embedding script with:
162
162
163
163
```sh
164
164
python embed.py
@@ -176,7 +176,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
176
176
177
177
### Create a new file and import required modules
178
178
179
-
1.Create a new file called `rag.py` and add the following content to it:
179
+
Create a new file called `rag.py` and add the following content to it:
180
180
181
181
```python
182
182
#rag.py
@@ -195,7 +195,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
195
195
196
196
### Configure vector store
197
197
198
-
2.Edit `rag.py` to load `.env` file, and configure Embeddings format and Vector store:
198
+
Edit `rag.py` to load `.env` file, and configure Embeddings format and Vector store:
199
199
200
200
```python
201
201
load_dotenv()
@@ -216,7 +216,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
216
216
217
217
### Configure the LLM client and create a basic RAG pipeline
218
218
219
-
3.Edit `rag.py` to configure LLM client using `ChatOpenAI` and create a simple RAG pipeline:
219
+
Edit `rag.py` to configure the LLM client using `ChatOpenAI` and create a simple RAG pipeline:
220
220
221
221
```python
222
222
llm = ChatOpenAI(
@@ -244,7 +244,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
244
244
-`rag_chain` defines a workflow performing the following steps in order: Retrieve relevant documents, Prompt LLM with document as context, and final output parsing.
245
245
-`for r in rag_chain.stream("Prompt question")` starts the rag workflow with `Prompt question` as input.
246
246
247
-
4.You can now execute your RAG pipeline with:
247
+
You can now execute your RAG pipeline with the following command:
248
248
249
249
```sh
250
250
python rag.py
@@ -270,7 +270,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
270
270
271
271
Personalizing your prompt template allows you to tailor the responses from your RAG (Retrieval-Augmented Generation) system to better fit your specific needs. This can significantly improve the relevance and tone of the answers you receive. Below is a detailed guide on how to create a custom prompt for querying the system.
272
272
273
-
5. Replace `rag.py` content with the following:
273
+
Replace the`rag.py` content with the following:
274
274
275
275
```python
276
276
#rag.py
@@ -320,7 +320,8 @@ Personalizing your prompt template allows you to tailor the responses from your
320
320
- `retriever.invoke` lets you customize which part of the LLM input is used to retrieve documents.
321
321
- `create_stuff_documents_chain` provides the prompt template to the LLM.
322
322
323
-
6. You can now execute your custom RAG pipeline with:
323
+
You can now execute your custom RAG pipeline with the following command:
0 commit comments