Skip to content

Commit e962da1

Browse files
docs(store): Integrate supabase into the store package
- Adds documentation for the new store integration
1 parent 6a9c393 commit e962da1

File tree

11 files changed

+302
-39
lines changed

11 files changed

+302
-39
lines changed

examples/.env

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,46 @@ LMSTUDIO_HOST_URL=http://127.0.0.1:1234
105105
QDRANT_HOST=http://127.0.0.1:6333
106106
QDRANT_SERVICE_API_KEY=changeMe
107107

108+
# SurrealDB (store)
109+
SURREALDB_HOST=http://127.0.0.1:8000
110+
SURREALDB_USER=symfony
111+
SURREALDB_PASS=symfony
112+
113+
# Neo4J (store)
114+
NEO4J_HOST=http://127.0.0.1:7474
115+
NEO4J_DATABASE=neo4j
116+
NEO4J_USERNAME=neo4j
117+
NEO4J_PASSWORD=symfonyai
118+
119+
# Typesense (store)
120+
TYPESENSE_HOST=http://127.0.0.1:8108
121+
TYPESENSE_API_KEY=changeMe
122+
123+
# Milvus (store)
124+
MILVUS_HOST=http://127.0.0.1:19530
125+
MILVUS_API_KEY=root:Milvus
126+
MILVUS_DATABASE=symfony
127+
128+
# Cloudflare (store)
129+
CLOUDFLARE_ACCOUNT_ID=
130+
CLOUDFLARE_API_KEY=
131+
132+
# Cerebras
133+
CEREBRAS_API_KEY=
134+
135+
CHROMADB_HOST=http://127.0.0.1
136+
CHROMADB_PORT=8001
137+
138+
# For using Clickhouse (store)
139+
CLICKHOUSE_HOST=http://symfony:[email protected]:8123
140+
CLICKHOUSE_DATABASE=symfony
141+
CLICKHOUSE_TABLE=symfony
142+
143+
# Weaviate (store)
144+
WEAVIATE_HOST=http://127.0.0.1:8080
145+
WEAVIATE_API_KEY=symfony
146+
147+
# Supabase (store)
108148
SUPABASE_URL=
109149
SUPABASE_API_KEY=
110150
SUPABASE_TABLE=

examples/commands/stores.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Symfony\AI\Store\Bridge\Neo4j\Store as Neo4jStore;
2525
use Symfony\AI\Store\Bridge\Postgres\Store as PostgresStore;
2626
use Symfony\AI\Store\Bridge\Qdrant\Store as QdrantStore;
27-
use Symfony\AI\Store\Bridge\Supabase\Store as SupabaseStore;
2827
use Symfony\AI\Store\Bridge\SurrealDb\Store as SurrealDbStore;
2928
use Symfony\AI\Store\Bridge\Typesense\Store as TypesenseStore;
3029
use Symfony\AI\Store\Bridge\Weaviate\Store as WeaviateStore;
@@ -89,15 +88,6 @@
8988
env('QDRANT_SERVICE_API_KEY'),
9089
'symfony',
9190
),
92-
'supabase' => static fn (): SupabaseStore => new SupabaseStore(
93-
http_client(),
94-
env('SUPABASE_URL'),
95-
env('SUPABASE_API_KEY'),
96-
env('SUPABASE_TABLE'),
97-
env('SUPABASE_VECTOR_FIELD'),
98-
env('SUPABASE_VECTOR_DIMENSION'),
99-
env('SUPABASE_MATCH_FUNCTION'),
100-
),
10191
'surrealdb' => static fn (): SurrealDbStore => new SurrealDbStore(
10292
httpClient: http_client(),
10393
endpointUrl: env('SURREALDB_HOST'),

examples/rag/supabase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
require_once dirname(__DIR__).'/bootstrap.php';
3030

31-
echo "Make sure you've run the SQL setup from SUPABASE_SETUP.md first!\n\n";
32-
3331
$store = new Store(
3432
http: http_client(),
3533
url: env('SUPABASE_URL'),
@@ -51,7 +49,7 @@ functionName: env('SUPABASE_MATCH_FUNCTION')
5149
}
5250

5351
$platform = PlatformFactory::create(
54-
env('OLLAMA_HOST_URL') ?? 'http://localhost:11434',
52+
env('OLLAMA_HOST_URL'),
5553
http_client()
5654
);
5755

src/ai-bundle/config/options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
->children()
382382
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
383383
->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end()
384-
->scalarNode('table')->isRequired()->cannotBeEmpty()->end()
384+
->scalarNode('table')->end()
385385
->scalarNode('vector_field')->end()
386386
->integerNode('vector_dimension')->end()
387387
->scalarNode('function_name')->end()

src/ai-bundle/doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Configuration
109109
name: !php/const Symfony\AI\Platform\Bridge\ElevenLabs::TEXT_TO_SPEECH
110110
tools: false
111111
store:
112-
# also azure_search, meilisearch, memory, mongodb, pinecone, qdrant and surrealdb are supported as store type
112+
# also azure_search, meilisearch, memory, mongodb, pinecone, qdrant, surrealdb, and supabase are supported as store type
113113
chroma_db:
114114
# multiple collections possible per type
115115
default:

src/store/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ CHANGELOG
4545
- Pinecone
4646
- PostgreSQL with pgvector extension
4747
- Qdrant
48+
- Supabase
4849
- SurrealDB
4950
- Typesense
5051
- Weaviate

src/store/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"pinecone",
1818
"postgres",
1919
"qdrant",
20+
"supabase",
2021
"surrealdb",
2122
"typesense",
2223
"weaviate"

src/store/doc/bridges/supabase.rst

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
Supabase Bridge
2+
===============
3+
4+
The Supabase bridge provides vector storage capabilities using Supabase's pgvector extension through the REST API.
5+
6+
.. note::
7+
8+
* Unlike the Postgres Store, the Supabase Store requires manual setup of the database schema
9+
* because Supabase doesn't allow arbitrary SQL execution via REST API.
10+
11+
Installation
12+
------------
13+
14+
The Supabase bridge requires the pgvector extension and pre-configured database objects.
15+
16+
Requirements
17+
~~~~~~~~~~~~
18+
19+
* Supabase project with pgvector extension enabled
20+
* Pre-configured table with vector column
21+
* Pre-configured RPC function for similarity search
22+
23+
Database Setup
24+
--------------
25+
26+
Execute the following SQL commands in your Supabase SQL Editor:
27+
28+
Enable ``pgvector`` extension
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
.. code-block:: sql
32+
33+
CREATE EXTENSION IF NOT EXISTS vector;
34+
35+
Create the `documents` table
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
38+
.. code-block:: sql
39+
40+
CREATE TABLE IF NOT EXISTS documents (
41+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
42+
embedding vector(1536) NOT NULL,
43+
metadata JSONB
44+
);
45+
46+
Create the similarity search function
47+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
49+
.. code-block:: sql
50+
51+
CREATE OR REPLACE FUNCTION match_documents(
52+
query_embedding vector(1536),
53+
match_count int DEFAULT 10,
54+
match_threshold float DEFAULT 0.0
55+
)
56+
RETURNS TABLE (
57+
id UUID,
58+
embedding vector,
59+
metadata JSONB,
60+
score float
61+
)
62+
LANGUAGE sql
63+
AS $$
64+
SELECT
65+
documents.id,
66+
documents.embedding,
67+
documents.metadata,
68+
1- (documents.embedding <=> query_embedding) AS score
69+
FROM documents
70+
WHERE 1- (documents.embedding <=> query_embedding) >= match_threshold
71+
ORDER BY documents.embedding <=> query_embedding ASC
72+
LIMIT match_count;
73+
$$;
74+
75+
Create an index for better performance
76+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77+
78+
.. code-block:: sql
79+
80+
CREATE INDEX IF NOT EXISTS documents_embedding_idx
81+
ON documents USING ivfflat (embedding vector_cosine_ops);
82+
83+
Configuration
84+
-------------
85+
86+
Basic Configuration
87+
~~~~~~~~~~~~~~~~~~~
88+
89+
.. code-block:: php
90+
91+
use Symfony\AI\Store\Bridge\Supabase\Store;
92+
use Symfony\Component\HttpClient\HttpClient;
93+
94+
$store = new Store(
95+
HttpClient::create(),
96+
'https://your-project.supabase.co',
97+
'your-anon-key',
98+
'documents', // table name
99+
'embedding', // vector field name
100+
1536, // vector dimension
101+
'match_documents' // function name
102+
);
103+
104+
Bundle Configuration
105+
~~~~~~~~~~~~~~~~~~~~
106+
107+
.. code-block:: yaml
108+
109+
# config/packages/ai.yaml
110+
ai:
111+
store:
112+
supabase:
113+
my_supabase_store:
114+
url: 'https://your-project.supabase.co'
115+
api_key: '%env(SUPABASE_API_KEY)%'
116+
table: 'documents'
117+
vector_field: 'embedding'
118+
vector_dimension: 1536
119+
function_name: 'match_documents'
120+
121+
Environment Variables
122+
~~~~~~~~~~~~~~~~~~~~~
123+
124+
.. code-block:: bash
125+
126+
# .env.local
127+
SUPABASE_URL=https://your-project.supabase.co
128+
SUPABASE_API_KEY=your-supabase-anon-key
129+
130+
Usage
131+
-----
132+
133+
Adding Documents
134+
~~~~~~~~~~~~~~~~
135+
136+
.. code-block:: php
137+
138+
use Symfony\AI\Platform\Vector\Vector;
139+
use Symfony\AI\Store\Document\Metadata;
140+
use Symfony\AI\Store\Document\VectorDocument;
141+
use Symfony\Component\Uid\Uuid;
142+
143+
$document = new VectorDocument(
144+
Uuid::v4(),
145+
new Vector([0.1, 0.2, 0.3, /* ... 1536 dimensions */]),
146+
new Metadata(['title' => 'My Document', 'category' => 'example'])
147+
);
148+
149+
$store->add($document);
150+
151+
Querying Documents
152+
~~~~~~~~~~~~~~~~~~
153+
154+
.. code-block:: php
155+
156+
$queryVector = new Vector([0.1, 0.2, 0.3, /* ... 1536 dimensions */]);
157+
158+
$results = $store->query($queryVector, [
159+
'max_items' => 10,
160+
'min_score' => 0.7
161+
]);
162+
163+
foreach ($results as $document) {
164+
echo "ID: " . $document->id . "\n";
165+
echo "Score: " . $document->score . "\n";
166+
echo "Metadata: " . json_encode($document->metadata->getArrayCopy()) . "\n";
167+
}
168+
169+
Customization
170+
-------------
171+
172+
You can customize the Supabase setup for different requirements:
173+
174+
Table Name
175+
~~~~~~~~~~
176+
177+
Change ``documents`` to your preferred table name in both the SQL setup and configuration.
178+
179+
Vector Field Name
180+
~~~~~~~~~~~~~~~~~
181+
182+
Change ``embedding`` to your preferred field name in both the SQL setup and configuration.
183+
184+
Vector Dimension
185+
~~~~~~~~~~~~~~~~
186+
187+
Change ``1536`` to match your embedding model's dimensions in both the SQL setup and configuration.
188+
189+
Distance Metric
190+
~~~~~~~~~~~~~~~
191+
192+
* Cosine: ``<=>`` (default, recommended for most embeddings)
193+
* Euclidean: ``<->``
194+
* Inner Product: ``<#>``
195+
196+
Index Type
197+
~~~~~~~~~~
198+
199+
* ``ivfflat``: Good balance of speed and accuracy
200+
* ``hnsw``: Better for high-dimensional vectors (requires PostgreSQL 14+)
201+
202+
Limitations
203+
-----------
204+
205+
* Manual schema setup required (no automatic table creation)
206+
* Limited to Supabase's REST API capabilities
207+
* Requires pre-configured RPC functions for complex queries
208+
* Vector dimension must be consistent across all documents
209+
210+
Performance Considerations
211+
--------------------------
212+
213+
* Use appropriate index types based on your vector dimensions
214+
* Consider using ``hnsw`` indexes for high-dimensional vectors
215+
* Batch document insertions when possible (up to 200 documents per request)
216+
* Monitor your Supabase usage limits and quotas
217+
218+
Security Considerations
219+
-----------------------
220+
221+
* Use row-level security (RLS) policies if needed
222+
* Consider using service role keys for server-side operations
223+
* Validate vector dimensions in your application code
224+
* Implement proper error handling for API failures
225+
226+
Additional Resources
227+
--------------------
228+
229+
* [Supabase Vector Documentation](https://supabase.com/docs/guides/ai/vector-columns)
230+
* [pgvector Documentation](https://github.com/pgvector/pgvector)
231+
* [Symfony AI Store Documentation](../../../README.md)

src/store/doc/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ You can find more advanced usage in combination with an Agent using the store fo
5050
* `Similarity Search with Symfony Cache (RAG)`_
5151
* `Similarity Search with Typesense (RAG)`_
5252
* `Similarity Search with Weaviate (RAG)`_
53+
* `Similarity Search with Supabase (RAG)`_
5354

5455
.. note::
5556

@@ -72,6 +73,7 @@ Supported Stores
7273
* `Pinecone`_ (requires `probots-io/pinecone-php` as additional dependency)
7374
* `Postgres`_ (requires `ext-pdo`)
7475
* `Qdrant`_
76+
* `Supabase`_ (requires manual database setup)
7577
* `SurrealDB`_
7678
* `Symfony Cache`_
7779
* `Typesense`_
@@ -141,6 +143,7 @@ This leads to a store implementing two methods::
141143
.. _`Similarity Search with Qdrant (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/qdrant.php
142144
.. _`Similarity Search with SurrealDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/surrealdb.php
143145
.. _`Similarity Search with Typesense (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/typesense.php
146+
.. _`Similarity Search with Supabase (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/supabase.php
144147
.. _`Similarity Search with Weaviate (RAG)`: https://github.com/symfony/ai/blob/main/examples/rag/weaviate.php
145148
.. _`Azure AI Search`: https://azure.microsoft.com/products/ai-services/ai-search
146149
.. _`Chroma`: https://www.trychroma.com/
@@ -159,3 +162,4 @@ This leads to a store implementing two methods::
159162
.. _`GitHub`: https://github.com/symfony/ai/issues/16
160163
.. _`Symfony Cache`: https://symfony.com/doc/current/components/cache.html
161164
.. _`Weaviate`: https://weaviate.io/
165+
.. _`Supabase`: https://https://supabase.com/

0 commit comments

Comments
 (0)