Skip to content

Commit 27c5049

Browse files
docs(store): Integrate supabase into the store package
- Adds documentation for the new store integration
1 parent e1838aa commit 27c5049

File tree

10 files changed

+296
-31
lines changed

10 files changed

+296
-31
lines changed

examples/.env

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,46 @@ LMSTUDIO_HOST_URL=http://127.0.0.1:1234
101101
QDRANT_HOST=http://127.0.0.1:6333
102102
QDRANT_SERVICE_API_KEY=changeMe
103103

104+
# SurrealDB (store)
105+
SURREALDB_HOST=http://127.0.0.1:8000
106+
SURREALDB_USER=symfony
107+
SURREALDB_PASS=symfony
108+
109+
# Neo4J (store)
110+
NEO4J_HOST=http://127.0.0.1:7474
111+
NEO4J_DATABASE=neo4j
112+
NEO4J_USERNAME=neo4j
113+
NEO4J_PASSWORD=symfonyai
114+
115+
# Typesense (store)
116+
TYPESENSE_HOST=http://127.0.0.1:8108
117+
TYPESENSE_API_KEY=changeMe
118+
119+
# Milvus (store)
120+
MILVUS_HOST=http://127.0.0.1:19530
121+
MILVUS_API_KEY=root:Milvus
122+
MILVUS_DATABASE=symfony
123+
124+
# Cloudflare (store)
125+
CLOUDFLARE_ACCOUNT_ID=
126+
CLOUDFLARE_API_KEY=
127+
128+
# Cerebras
129+
CEREBRAS_API_KEY=
130+
131+
CHROMADB_HOST=http://127.0.0.1
132+
CHROMADB_PORT=8001
133+
134+
# For using Clickhouse (store)
135+
CLICKHOUSE_HOST=http://symfony:[email protected]:8123
136+
CLICKHOUSE_DATABASE=symfony
137+
CLICKHOUSE_TABLE=symfony
138+
139+
# Weaviate (store)
140+
WEAVIATE_HOST=http://127.0.0.1:8080
141+
WEAVIATE_API_KEY=symfony
142+
143+
# Supabase (store)
104144
SUPABASE_URL=
105145
SUPABASE_API_KEY=
106146
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ functionName: env('SUPABASE_MATCH_FUNCTION')
5151
}
5252

5353
$platform = PlatformFactory::create(
54-
env('OLLAMA_HOST_URL') ?? 'http://localhost:11434',
54+
env('OLLAMA_HOST_URL'),
5555
http_client()
5656
);
5757

src/ai-bundle/config/options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
->children()
355355
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
356356
->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end()
357-
->scalarNode('table')->isRequired()->cannotBeEmpty()->end()
357+
->scalarNode('table')->end()
358358
->scalarNode('vector_field')->end()
359359
->integerNode('vector_dimension')->end()
360360
->scalarNode('function_name')->end()

src/ai-bundle/doc/index.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Configuration
100100
name: !php/const Symfony\AI\Platform\Bridge\ElevenLabs::TEXT_TO_SPEECH
101101
tools: false
102102
store:
103-
# also azure_search, meilisearch, memory, mongodb, pinecone, qdrant and surrealdb are supported as store type
103+
# also azure_search, meilisearch, memory, mongodb, pinecone, qdrant, surrealdb, and supabase are supported as store type
104104
chroma_db:
105105
# multiple collections possible per type
106106
default:
@@ -131,7 +131,7 @@ Configuration
131131
default:
132132
vectorizer: 'ai.vectorizer.openai_embeddings'
133133
store: 'ai.store.chroma_db.default'
134-
134+
135135
research:
136136
vectorizer: 'ai.vectorizer.mistral_embeddings'
137137
store: 'ai.store.memory.research'
@@ -355,13 +355,13 @@ Vectorizers are defined in the ``vectorizer`` section of your configuration:
355355
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_EMBEDDING_3_SMALL
356356
options:
357357
dimensions: 512
358-
358+
359359
openai_large:
360360
platform: 'ai.platform.openai'
361361
model:
362362
class: 'Symfony\AI\Platform\Bridge\OpenAi\Embeddings'
363363
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_EMBEDDING_3_LARGE
364-
364+
365365
mistral_embed:
366366
platform: 'ai.platform.mistral'
367367
model:
@@ -379,19 +379,19 @@ Once configured, vectorizers can be referenced by name in indexer configurations
379379
documents:
380380
vectorizer: 'ai.vectorizer.openai_small'
381381
store: 'ai.store.chroma_db.documents'
382-
382+
383383
research:
384384
vectorizer: 'ai.vectorizer.openai_large'
385385
store: 'ai.store.chroma_db.research'
386-
386+
387387
knowledge_base:
388388
vectorizer: 'ai.vectorizer.mistral_embed'
389389
store: 'ai.store.memory.kb'
390390
391391
**Benefits of Configured Vectorizers**
392392

393393
* **Reusability**: Define once, use in multiple indexers
394-
* **Consistency**: Ensure all indexers using the same vectorizer have identical embedding configuration
394+
* **Consistency**: Ensure all indexers using the same vectorizer have identical embedding configuration
395395
* **Maintainability**: Change vectorizer settings in one place
396396

397397
Profiler

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)

0 commit comments

Comments
 (0)