mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Context Lots of links that initially go to 301's within docs / kb. Updates these to their resolved target. Ask your Claude Code to review the new destinations programmatically. --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
71 lines
2.9 KiB
Plaintext
71 lines
2.9 KiB
Plaintext
---
|
|
id: 'ai-integration-llamaindex'
|
|
title: 'Learn how to integrate Supabase with LlamaIndex, a data framework for your LLM applications.'
|
|
subtitle: 'Learn how to integrate Supabase with LlamaIndex, a data framework for your LLM applications.'
|
|
breadcrumb: 'AI Integrations'
|
|
---
|
|
|
|
This guide will walk you through a basic example using the LlamaIndex [`SupabaseVectorStore`](https://github.com/supabase/supabase/blob/master/examples/ai/llamaindex/llamaindex.ipynb).
|
|
|
|
<$Partial path="database_setup.mdx" />
|
|
|
|
## Launching a notebook
|
|
|
|
Launch our [LlamaIndex](https://github.com/supabase/supabase/blob/master/examples/ai/llamaindex/llamaindex.ipynb) notebook in Colab:
|
|
|
|
<a
|
|
className="w-64"
|
|
href="https://colab.research.google.com/github/supabase/supabase/blob/master/examples/ai/llamaindex/llamaindex.ipynb"
|
|
>
|
|
<img src="/docs/img/ai/colab-badge.svg" alt="Open in Colab" />
|
|
</a>
|
|
|
|
At the top of the notebook, you'll see a button `Copy to Drive`. Click this button to copy the notebook to your Google Drive.
|
|
|
|
## Fill in your OpenAI credentials
|
|
|
|
Inside the Notebook, add your `OPENAI_API_KEY` key. Find the cell which contains this code:
|
|
|
|
```py
|
|
import os
|
|
os.environ['OPENAI_API_KEY'] = "[your_openai_api_key]"
|
|
```
|
|
|
|
## Connecting to your database
|
|
|
|
Inside the Notebook, find the cell which specifies the `DB_CONNECTION`. It will contain some code like this:
|
|
|
|
```python
|
|
DB_CONNECTION = "postgresql://<user>:<password>@<host>:<port>/<db_name>"
|
|
|
|
# create vector store client
|
|
vx = vecs.create_client(DB_CONNECTION)
|
|
```
|
|
|
|
Replace the `DB_CONNECTION` with your own connection string. You can find the connection string on your project dashboard by clicking [Connect](/dashboard/project/_?showConnect=true).
|
|
|
|
<Admonition type='note'>
|
|
|
|
SQLAlchemy requires the connection string to start with `postgresql://` (instead of `postgres://`). Don't forget to rename this after copying the string from the dashboard.
|
|
|
|
</Admonition>
|
|
|
|
<Admonition type='note'>
|
|
|
|
You must use the "connection pooling" string (domain ending in `*.pooler.supabase.com`) with Google Colab since [Colab does not support IPv6](/kb/troubleshooting/supabase--your-network-ipv4-and-ipv6-compatibility-cHe3BP).
|
|
|
|
</Admonition>
|
|
|
|
## Stepping through the notebook
|
|
|
|
Now all that's left is to step through the notebook. You can do this by clicking the "execute" button (`ctrl+enter`) at the top left of each code cell. The notebook guides you through the process of creating a collection, adding data to it, and querying it.
|
|
|
|
You can view the inserted items in the [Table Editor](/dashboard/project/_/editor/), by selecting the `vecs` schema from the schema dropdown.
|
|
|
|

|
|
|
|
## Resources
|
|
|
|
- Visit the LlamaIndex + `SupabaseVectorStore` [docs](https://developers.llamaindex.ai/python/framework/integrations/vector_stores/supabasevectorindexdemo/)
|
|
- Visit the official LlamaIndex [repo](https://github.com/run-llama/llama_index)
|