Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs: Update vecs references from `create_collection` to `get_or_create_collection` (#17707)

Oliver Rice392b3fc46005
diff --git a/.gitignore b/.gitignore
index de5d7122e93..3c9c2471b71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,7 @@ node_modules
out
.docz
tmp
-.swp
+*.swp
coverage
allure-results
diff --git a/apps/docs/pages/guides/ai/examples/image-search-openai-clip.mdx b/apps/docs/pages/guides/ai/examples/image-search-openai-clip.mdx
index 1090f4eedfe..7b783db0122 100644
--- a/apps/docs/pages/guides/ai/examples/image-search-openai-clip.mdx
+++ b/apps/docs/pages/guides/ai/examples/image-search-openai-clip.mdx
@@ -83,8 +83,8 @@ def seed():
# create vector store client
vx = vecs.create_client(DB_CONNECTION)
- # create a collection of vectors with 512 dimensions
- images = vx.create_collection(name="image_vectors", dimension=512)
+ # create a collection of vectors with 3 dimensions
+ images = vx.get_or_create_collection(name="image_vectors", dimension=512)
# Load CLIP model
model = SentenceTransformer('clip-ViT-B-32')
diff --git a/apps/docs/pages/guides/ai/google-colab.mdx b/apps/docs/pages/guides/ai/google-colab.mdx
index d6edee7ba26..94445cf582f 100644
--- a/apps/docs/pages/guides/ai/google-colab.mdx
+++ b/apps/docs/pages/guides/ai/google-colab.mdx
@@ -61,7 +61,7 @@ Now we're going to create a new collection and insert some documents.
Create a new code block below the install block (`ctrl+m b`). Add the following code to the code block and execute it (`ctrl+enter`):
```py
-collection = vx.create_collection(name="colab_collection", dimension=3)
+collection = vx.get_or_create_collection(name="colab_collection", dimension=3)
collection.upsert(
vectors=[
diff --git a/apps/docs/pages/guides/ai/structured-unstructured.mdx b/apps/docs/pages/guides/ai/structured-unstructured.mdx
index 04b35b5b4cb..6bd3795d35f 100644
--- a/apps/docs/pages/guides/ai/structured-unstructured.mdx
+++ b/apps/docs/pages/guides/ai/structured-unstructured.mdx
@@ -63,7 +63,7 @@ Client libraries like python's [vecs](https://github.com/supabase/vecs) use this
#!/usr/bin/env python3
import vecs
-docs = vx.create_collection(name="docs", dimension=1536)
+docs = vx.get_or_create_collection(name="docs", dimension=1536)
docs.upsert(vectors=[
('79409372-7556-4ccc-ab8f-5786a6cfa4f7', [100, 200, 300], { url: '/hello-world' })
@@ -71,7 +71,7 @@ docs.upsert(vectors=[
```
-automatically creates the unstructured SQL table during the call to `create_collection`.
+automatically creates the unstructured SQL table during the call to `get_or_create_collection`.
Note that when working with client libraries that emit SQL DDL, like `create table ...`, you should add that SQL to your migrations when moving to production to maintain a single source of truth for your database's schema.
diff --git a/apps/docs/pages/guides/ai/vecs-python-client.mdx b/apps/docs/pages/guides/ai/vecs-python-client.mdx
index ce7e5a7517c..87023b373e2 100644
--- a/apps/docs/pages/guides/ai/vecs-python-client.mdx
+++ b/apps/docs/pages/guides/ai/vecs-python-client.mdx
@@ -37,7 +37,7 @@ import vecs
vx = vecs.create_client("postgresql://postgres:postgres@localhost:54322/postgres")
# create a collection of vectors with 3 dimensions
-docs = vx.create_collection(name="docs", dimension=3)
+docs = vx.get_or_create_collection(name="docs", dimension=3)
```
### Add embeddings
@@ -48,7 +48,7 @@ Now we can insert some embeddings into our "docs" collection using the `upsert()
import vecs
# create vector store client
-docs = vecs.get_collection(name="docs")
+docs = vecs.get_or_create_collection(name="docs", dimension=3)
# a collection of vectors with 3 dimensions
vectors=[
@@ -67,7 +67,7 @@ You can now query the collection to retrieve a relevant match:
```py
import vecs
-docs = vecs.get_collection(name="docs")
+docs = vecs.get_or_create_collection(name="docs", dimension=3)
# query the collection filtering metadata for "year" = 2012
docs.query(
diff --git a/apps/www/_blog/2023-05-31-vecs.mdx b/apps/www/_blog/2023-05-31-vecs.mdx
index 87950200566..77f6e782ce6 100644
--- a/apps/www/_blog/2023-05-31-vecs.mdx
+++ b/apps/www/_blog/2023-05-31-vecs.mdx
@@ -45,10 +45,10 @@ DB_CONNECTION = "postgresql://<user>:<password>@<host>:<port>/<db_name>"
vx = vecs.create_client(DB_CONNECTION)
# create a collection of vectors with 3 dimensions
-docs = vx.create_collection(name="docs", dimension=3)
+docs = vx.get_or_create_collection(name="docs", dimension=3)
```
-The `create_collection` call sets up a table in the Postgres database specified by `DB_CONNECTION` in a schema named `vecs` with the user defined name `docs`.
+The `get_or_create_collection` call sets up a table in the Postgres database specified by `DB_CONNECTION` in a schema named `vecs` with the user defined name `docs`.
Or, more specifically:
@@ -166,7 +166,7 @@ One option we're exploring is to optionally assign transformation pipelines to c
```python
# This is mock code only, not currently functional
-docs: Collection =vx.create_collection(
+docs: Collection =vx.get_or_create_collection(
docs='docs',
dimension=512,
transform = TextPreprocessor( # this is new
diff --git a/examples/ai/face_similarity.ipynb b/examples/ai/face_similarity.ipynb
index c3c87b749f2..5a6d22a7844 100644
--- a/examples/ai/face_similarity.ipynb
+++ b/examples/ai/face_similarity.ipynb
@@ -206,7 +206,7 @@
"vx = vecs.create_client(DB_CONNECTION)\n",
"\n",
"# create a PostgreSQL/pgvector table named \"faces\" to contain the face embeddings\n",
- "faces = vx.create_collection(name=\"faces\", dimension=128)"
+ "faces = vx.get_or_create_collection(name=\"faces\", dimension=128)"
]
},
{
diff --git a/examples/ai/semantic_text_deduplication.ipynb b/examples/ai/semantic_text_deduplication.ipynb
index 7f080846362..04ce6bf30d8 100644
--- a/examples/ai/semantic_text_deduplication.ipynb
+++ b/examples/ai/semantic_text_deduplication.ipynb
@@ -157,7 +157,7 @@
"vx = vecs.create_client(DB_CONNECTION)\n",
"\n",
"# create a PostgreSQL/pgvector table named \"reviews\" to contain the review embeddings\n",
- "reviews = vx.create_collection(name=\"reviews\", dimension=384)"
+ "reviews = vx.get_or_create_collection(name=\"reviews\", dimension=384)"
]
},
{
diff --git a/examples/ai/vector_hello_world.ipynb b/examples/ai/vector_hello_world.ipynb
index 002ceb8efe7..461dd5670c0 100644
--- a/examples/ai/vector_hello_world.ipynb
+++ b/examples/ai/vector_hello_world.ipynb
@@ -82,9 +82,9 @@
"id": "zbwuFOgQgog6"
},
"source": [
- "###Create collection\n",
+ "###Get or Create Collection\n",
"\n",
- "You can create a collection to store vectors specifying the collections name and the number of dimensions in the vectors you intend to store."
+ "You can get or create a collection to store vectors specifying the collections name and the number of dimensions in the vectors you intend to store."
]
},
{
@@ -95,29 +95,7 @@
},
"outputs": [],
"source": [
- "docs = vx.create_collection(name=\"docs\", dimension=3)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "djKCRhbbhAQ8"
- },
- "source": [
- "###Get an existing collection\n",
- "\n",
- "To access a previously created collection, use `get_collection` to retrieve it by name"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "id": "71IyRUbDhEGz"
- },
- "outputs": [],
- "source": [
- "docs = vx.get_collection(name=\"docs\")"
+ "docs = vx.get_or_create_collection(name=\"docs\", dimension=3)"
]
},
{