Skip to content

Commit 882efaf

Browse files
fpagnyjcirinosclwy
andauthored
Apply suggestions from code review
Co-authored-by: Jessica <[email protected]>
1 parent 557f9a9 commit 882efaf

File tree

1 file changed

+13
-12
lines changed
  • tutorials/how-to-implement-rag-generativeapis

1 file changed

+13
-12
lines changed

tutorials/how-to-implement-rag-generativeapis/index.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Create an `embed.py` file and add the following code to it:
9696

9797
### Configure embeddings client
9898

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).
100100

101101
```python
102102
embeddings = OpenAIEmbeddings(
@@ -109,7 +109,7 @@ embeddings = OpenAIEmbeddings(
109109

110110
### Configure vector store client
111111

112-
5. Edit `embed.py` to configure connection to your Managed Database for PostgreSQL Instance storing vectors:
112+
Edit `embed.py` to configure connection to your Managed Database for PostgreSQL Instance storing vectors:
113113

114114
```python
115115
connection_string = f'postgresql+psycopg2://{os.getenv("SCW_DB_USER")}:{os.getenv("SCW_DB_PASSWORD")}@{os.getenv("SCW_DB_HOST")}:{os.getenv("SCW_DB_PORT")}/{os.getenv("SCW_DB_NAME")}'
@@ -122,14 +122,14 @@ embeddings = OpenAIEmbeddings(
122122

123123
## Load and process documents
124124

125-
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).
126126

127127
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.
128128
Then, we will embed them as vectors and store these vectors in your PostgreSQL database.
129129

130130
### Import required modules
131131

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`:
133133

134134
```python
135135
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
138138

139139
### Iterate through objects
140140

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`.
142142

143143
```python
144144
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0, add_start_index=True, length_function=len, is_separator_regex=False)
@@ -158,7 +158,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
158158

159159
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.
160160

161-
9. You can now run you vector embedding script with:
161+
You can now run you vector embedding script with:
162162

163163
```sh
164164
python embed.py
@@ -176,7 +176,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
176176

177177
### Create a new file and import required modules
178178

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:
180180

181181
```python
182182
#rag.py
@@ -195,7 +195,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
195195

196196
### Configure vector store
197197

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:
199199

200200
```python
201201
load_dotenv()
@@ -216,7 +216,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
216216

217217
### Configure the LLM client and create a basic RAG pipeline
218218

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:
220220

221221
```python
222222
llm = ChatOpenAI(
@@ -244,7 +244,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
244244
- `rag_chain` defines a workflow performing the following steps in order: Retrieve relevant documents, Prompt LLM with document as context, and final output parsing.
245245
- `for r in rag_chain.stream("Prompt question")` starts the rag workflow with `Prompt question` as input.
246246

247-
4. You can now execute your RAG pipeline with:
247+
You can now execute your RAG pipeline with the following command:
248248

249249
```sh
250250
python rag.py
@@ -270,7 +270,7 @@ Then, we will embed them as vectors and store these vectors in your PostgreSQL d
270270

271271
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.
272272

273-
5. Replace `rag.py` content with the following:
273+
Replace the `rag.py` content with the following:
274274

275275
```python
276276
#rag.py
@@ -320,7 +320,8 @@ Personalizing your prompt template allows you to tailor the responses from your
320320
- `retriever.invoke` lets you customize which part of the LLM input is used to retrieve documents.
321321
- `create_stuff_documents_chain` provides the prompt template to the LLM.
322322
323-
6. You can now execute your custom RAG pipeline with:
323+
You can now execute your custom RAG pipeline with the following command:
324+
324325
325326
```sh
326327
python rag.py

0 commit comments

Comments
 (0)