mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 22:18:00 +08:00
docs: Update vecs references from create_collection to get_or_create_collection (#17707)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,7 +4,7 @@ node_modules
|
||||
out
|
||||
.docz
|
||||
tmp
|
||||
.swp
|
||||
*.swp
|
||||
|
||||
coverage
|
||||
allure-results
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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=[
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user