Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/greathayat/supabase-edge-functions-rag

This is a repository to let you know the implementation of a basic RAG pipeline using LangChain in Supabase Edge Functions.
https://github.com/greathayat/supabase-edge-functions-rag

ai edge-functions embeddings langchain rag supabase vector-database

Last synced: 26 days ago
JSON representation

This is a repository to let you know the implementation of a basic RAG pipeline using LangChain in Supabase Edge Functions.

Awesome Lists containing this project

README

        

# LangChain in Supabase Edge Functions

Installing NPM Packages in Supabase Edge Functions
If you're familiar with Supabase Edge Functions, you may know that installing npm packages is not as straightforward as in a typical Node.js or Express application. However, there are several methods to include npm packages in Supabase Edge Functions. In this guide, I'll demonstrate how to use the import_map.json file to achieve this.

---

## Initialize & Start Supabase Project

> Ensure Docker is installed on your machine.

### Step 1: Initialize the Project

Choose your directory and run the following command:

```sh
npx supabase init
```

This will create a `supabase` folder in your directory.

### Step 2: Start the Supabase Project

Run the following command to start the project:

```sh
npx supabase start
```

This process may take a few minutes as it pulls Docker images and starts the containers.

### Step 3: Create a Supabase Edge Function

Open the directory in your favorite code editor and run the following command to create a new Supabase Edge Function:

```sh
npx supabase functions new
```

This will create a folder with the name of your function inside the `functions` directory.

## Install NPM Packages

> You can install any npm package. For this example, we'll install LangChain packages to create a basic RAG pipeline.

### Step 4: Create `import_map.json`

Create a file named `import_map.json` in your `functions` folder and add the following JSON block:

```json
{
"imports": {
"@supabase/supabase-js": "npm:@supabase/[email protected]",
"langchain/": "https://esm.sh/[email protected]/",
"@langchain/openai/": "https://esm.sh/@langchain/[email protected]/",
"@langchain/core/": "https://esm.sh/@langchain/[email protected]/",
"@langchain/community/": "https://esm.sh/@langchain/[email protected]/"
}
}
```

### Important Instructions

> If you want to use submodules of an npm package, ensure you add a `/` at the end of the package name. For reference, see the import of `@supabase/supabase-js` and the remaining `langchain` packages.

## Deploy Your Edge Function to Production

> Ensure your project is linked with your Supabase cloud project.

To deploy your edge function to Supabase, run the following command:

```sh
npx supabase functions deploy
```

This command will deploy all functions.

To deploy a specific function, use:

```sh
npx supabase functions deploy
```