Skip to content

Commit 6ba5ea2

Browse files
committed
Managed database setup
1 parent 73f71c2 commit 6ba5ea2

File tree

1 file changed

+65
-34
lines changed

1 file changed

+65
-34
lines changed
+65-34
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
meta:
33
title: How to implement RAG with managed inference
4-
description:
4+
description: Learn how to implement Retrieval-Augmented Generation (RAG) using Scaleway's managed inference, PostgreSQL, pgvector, and object storage.
55
content:
66
h1: How to implement RAG with managed inference
7-
tags: inference managed postgresql pgvector object storage
7+
tags: inference, managed, postgresql, pgvector, object storage
88
categories:
99
- inference
1010
---
@@ -14,47 +14,78 @@ Scaleway's robust infrastructure makes it easier than ever to implement RAG, as
1414
By utilizing our managed inference services, managed databases, and object storage, you can effortlessly build and deploy a customized model tailored to your specific needs.
1515

1616
<Macro id="requirements" />
17+
1718
- A Scaleway account logged into the [console](https://console.scaleway.com)
1819
- [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization
1920
- [Inference Deployment](/ai-data/managed-inference/how-to/create-deployment/): Set up an inference deployment using [sentence-transformers/sentence-t5-xxl](/ai-data/managed-inference/reference-content/sentence-t5-xxl/) on an L4 instance to efficiently process embeddings.
2021
- [Inference Deployment](/ai-data/managed-inference/how-to/create-deployment/) with the model of your choice.
2122
- [Object Storage Bucket](/storage/object/how-to/create-a-bucket/) to store all the data you want to inject into your LLM model.
2223
- [Managed Database](/managed-databases/postgresql-and-mysql/how-to/create-a-database/) to securely store all your embeddings.
2324

24-
## Configure your developement environnement
25+
## Configure your development environment
26+
2527
1. Install necessary packages: run the following command to install the required packages:
28+
2629
```sh
2730
pip install langchain psycopg2 python-dotenv scaleway
2831
```
29-
2. Configure your environnement variables: create a .env file and add the following variables. These will store your API keys, database connection details, and other configuration values.
32+
2. Configure your environment variables: create a .env file and add the following variables. These will store your API keys, database connection details, and other configuration values.
33+
3034
```sh
31-
# .env file
32-
33-
# Scaleway API credentials
34-
SCW_ACCESS_KEY=your_scaleway_access_key
35-
SCW_SECRET_KEY=your_scaleway_secret_key
36-
SCW_API_KEY=your_scaleway_api_key
37-
38-
# Scaleway project and region
39-
SCW_DEFAULT_PROJECT_ID=your_scaleway_project_id
40-
SCW_DEFAULT_REGION=your_scaleway_region
41-
42-
# Scaleway managed database (PostgreSQL) credentials
43-
SCW_DB_NAME=your_scaleway_managed_db_name
44-
SCW_DB_USER=your_scaleway_managed_db_username
45-
SCW_DB_PASSWORD=your_scaleway_managed_db_password
46-
SCW_DB_HOST=your_scaleway_managed_db_host # The IP address of your database instance
47-
SCW_DB_PORT=your_scaleway_managed_db_port # The port number for your database instance
48-
49-
# Scaleway S3 bucket configuration
50-
SCW_BUCKET_NAME=your_scaleway_bucket_name
51-
SCW_BUCKET_ENDPOINT=your_scaleway_bucket_endpoint # S3 endpoint, e.g., https://s3.fr-par.scw.cloud
52-
53-
# Scaleway Inference API configuration (Embeddings)
54-
SCW_INFERENCE_EMBEDDINGS_ENDPOINT=your_scaleway_inference_embeddings_endpoint # Endpoint for sentence-transformers/sentence-t5-xxl deployment
55-
SCW_INFERENCE_API_KEY_EMBEDDINGS=your_scaleway_api_key_for_embeddings
56-
57-
# Scaleway Inference API configuration (LLM deployment)
58-
SCW_INFERENCE_DEPLOYMENT_ENDPOINT=your_scaleway_inference_endpoint # Endpoint for your LLM deployment
59-
SCW_INFERENCE_API_KEY=your_scaleway_api_key_for_inference_deployment
60-
```
35+
# .env file
36+
37+
# Scaleway API credentials
38+
SCW_ACCESS_KEY=your_scaleway_access_key
39+
SCW_SECRET_KEY=your_scaleway_secret_key
40+
SCW_API_KEY=your_scaleway_api_key
41+
42+
# Scaleway project and region
43+
SCW_DEFAULT_PROJECT_ID=your_scaleway_project_id
44+
SCW_DEFAULT_REGION=your_scaleway_region
45+
46+
# Scaleway managed database (PostgreSQL) credentials
47+
SCW_DB_NAME=your_scaleway_managed_db_name
48+
SCW_DB_USER=your_scaleway_managed_db_username
49+
SCW_DB_PASSWORD=your_scaleway_managed_db_password
50+
SCW_DB_HOST=your_scaleway_managed_db_host # The IP address of your database instance
51+
SCW_DB_PORT=your_scaleway_managed_db_port # The port number for your database instance
52+
53+
# Scaleway S3 bucket configuration
54+
SCW_BUCKET_NAME=your_scaleway_bucket_name
55+
SCW_BUCKET_ENDPOINT=your_scaleway_bucket_endpoint # S3 endpoint, e.g., https://s3.fr-par.scw.cloud
56+
57+
# Scaleway Inference API configuration (Embeddings)
58+
SCW_INFERENCE_EMBEDDINGS_ENDPOINT=your_scaleway_inference_embeddings_endpoint # Endpoint for sentence-transformers/sentence-t5-xxl deployment
59+
SCW_INFERENCE_API_KEY_EMBEDDINGS=your_scaleway_api_key_for_embeddings
60+
61+
# Scaleway Inference API configuration (LLM deployment)
62+
SCW_INFERENCE_DEPLOYMENT_ENDPOINT=your_scaleway_inference_endpoint # Endpoint for your LLM deployment
63+
SCW_INFERENCE_API_KEY=your_scaleway_api_key_for_inference_deployment
64+
```
65+
66+
### Set Up Managed Database
67+
68+
1. Connect to your PostgreSQL instance and install the pg_vector extension.
69+
70+
```python
71+
conn = psycopg2.connect(
72+
database="your_database_name",
73+
user="your_db_user",
74+
password=os.getenv("SCW_DB_PASSWORD"),
75+
host="your_db_host",
76+
port="your_db_port"
77+
)
78+
79+
cur = conn.cursor()
80+
81+
# Install pg_vector extension
82+
cur.execute("CREATE EXTENSION IF NOT EXISTS vector;")
83+
conn.commit()
84+
```
85+
2. Create a table to keep track of the documents loaded from your object storage bucket. So you can add new object to your bucket and they won't be download and vectorize twice
86+
87+
```python
88+
cur.execute("CREATE TABLE IF NOT EXISTS object_loaded (id SERIAL PRIMARY KEY, object_key TEXT)")
89+
conn.commit()
90+
```
91+

0 commit comments

Comments
 (0)