Vectors
Collections of embedded items and nearest search, for an agent’s memory, retrieval over documents, or more like this.
A vector collection holds items, each an id, text, JSON metadata and an embedding, and finds the items nearest to an embedding or to a piece of text. Use it for an agent's memory, for retrieval over your documents, or for "more like this".
# a collection whose items are embedded by a model connection (Settings, Connections)
curl -X POST $FORKBASE/vectors/v1/collections -H "apikey: $SERVICE_KEY" -H "Authorization: Bearer $SERVICE_KEY" \
-d '{"name": "docs", "dimension": 1536, "model": "openai/text-embedding-3-small"}'
# items: send text, and Forkbase embeds it; or send your own embedding
curl -X POST $FORKBASE/vectors/v1/collections/docs/items -H "apikey: $SERVICE_KEY" -H "Authorization: Bearer $SERVICE_KEY" \
-d '{"items": [{"id": "refunds", "content": "Refunds are paid within 14 days.", "metadata": {"team": "billing"}}]}'
# the nearest items to a question, among billing's
curl -X POST $FORKBASE/vectors/v1/collections/docs/query -H "apikey: $SERVICE_KEY" -H "Authorization: Bearer $SERVICE_KEY" \
-d '{"text": "how long do refunds take?", "k": 5, "filter": {"team": "billing"}}'Collections
POST /vectors/v1/collections with:
name: lowercase letters, digits and_, starting with a letter. It names the collection's table,vectors.<name>.dimension: how many numbers each embedding has (1536 fortext-embedding-3-small).metric:cosine(the default),l2orinner_product.model, optional:connection/modelof an OpenAI or OpenAI-compatible connection that embeds text sent without an embedding (POST <base_url>/v1/embeddings). Without one, every item and query brings its own embedding.
GET /vectors/v1/collections lists them with their item counts; GET or DELETE /vectors/v1/collections/<name>
reads one or deletes it with all its items.
Items
POST /vectors/v1/collections/<name>/items with {"items": [...]} (up to 500), each:
| Field | |
|---|---|
id | optional; one is made (v_...) if left out. An item with an id already there is replaced. |
content | the text. Embedded by the collection's model when there is no embedding. |
metadata | a JSON object, for filtering and for your app. |
embedding | optional: dimension numbers. |
It answers the ids and how many were embedded. The texts of one call go to the model in batches of 128.
GET /vectors/v1/collections/<name>/items?limit=50&offset=0 pages through them, newest first
(&include=embedding adds the embeddings); GET or DELETE .../items/<id> reads or deletes one.
Search
POST /vectors/v1/collections/<name>/query with:
| Field | |
|---|---|
embedding or text | what to search near; text is embedded by the collection's model |
k | how many items, 1 to 100 (10) |
filter | a JSON object the items' metadata must contain ({"user_id": "u1"}, {"tags": ["a"]}) |
max_distance | leave out items farther than this |
include_embedding | true adds each item's embedding |
Each item comes back with its distance, nearest first: 1 - cosine similarity for cosine, Euclidean distance for
l2, minus the inner product for inner_product. cosine and inner_product also give similarity.
Storage and indexes
Collections use pgvector's vector type and an HNSW index:
- chronos mode: always; vectors are built into the engine.
- postgres mode: when your Postgres has the pgvector extension. Forkbase makes it (
create extension vector) if its database user may. Without it, embeddings are kept asreal[]and each search reads the whole collection: fine for thousands of items, slow for millions.GET /vectors/v1/collectionssays which you have (pgvector), and each collection says whether it isindexed. A collection keeps the storage it was made with.
HNSW indexes cover up to 2,000 dimensions; a bigger collection is searched without one.
It is a table
vectors.<name> has the columns id, content, metadata (jsonb), embedding and created_at. Query it from SQL,
join it to your tables, or serve it to your app with a function over REST, under your
grants and row-level security:
create function match_docs(query vector(1536), k integer default 5)
returns table(id text, content text, similarity double precision)
language sql stable as $$
select id, content, 1 - (embedding <=> query) from vectors.docs order by embedding <=> query limit k
$$;const { data } = await supabase.rpc("match_docs", { query: embedding });Who may use it
The service key, and dashboard members: any member may list, read and search; changes take an admin. Making and deleting collections goes in the audit log.
Something wrong or missing? Edit this page on GitHub or open an issue.