Docs

Vector search and embeddings

Store embeddings with pgvector or let Sovaria keep them up to date for chosen text columns, then search by meaning, exact words or both (hybrid) with filters and row-level security — plus the collections API.

Updated Oct 17, 2026

An embedding is a list of numbers that captures what a piece of text (or an image) means; similar meanings give nearby vectors. Storing embeddings and searching for the nearest ones powers semantic search, recommendations and retrieval-augmented generation (RAG).

store / searchYour textarticles, tickets,productsA questionEmbedding modelOpenAI, Cohere, alocal model…Postgres + pgvectorvector column ·HNSW indexNearest rowsfiltered by yourrules

#In your database (recommended)

  1. Turn on vectors

    Vectors › Turn it on (or create extension vector).

  2. Create a table

    Vectors › Create table makes a ready table (content, metadata, embedding vector(<dimensions>)), optionally owner-only. Or write it yourself:

    create table documents (
      id bigint generated always as identity primary key,
      owner_id uuid default auth.uid(),
      content text not null,
      metadata jsonb default '{}',
      embedding vector(1536)          -- your model's dimension
    );
    create index on documents using hnsw (embedding vector_cosine_ops);
  3. Insert rows with their embedding

    Compute the embedding with your model on your server or in a function, then insert it.

    const embedding = await embedWithYourModel(text)          // number[1536]
    await sovaria.data.sql(
      'insert into documents (content, metadata, embedding) values ($1, $2, $3::vector)',
      [text, { lang: 'en' }, JSON.stringify(embedding)],
    )
  4. Search

    Order by distance; filter with ordinary SQL.

    select id, content, embedding <=> $1::vector as distance
      from documents
     where metadata->>'lang' = 'en'
     order by embedding <=> $1::vector
     limit 5;
MetricOperatorIndex operator class
Cosine distance<=>vector_cosine_ops
Euclidean (L2)<->vector_l2_ops
Inner product<#>vector_ip_ops

Indexes and tuning

Vectors › Add index…, sov vector sql-index or sqlCreateIndex builds an index with the options you choose. It is built CONCURRENTLY in the background, so writes keep working; the Vectors page (and sqlStatus) shows it building until it is ready.

MethodOptionsWhen
HNSW (default)m links per node (default 16), ef_construction build candidates (default 64, at least 2 × m)Best recall; works on an empty table and as rows arrive.
IVFFlatlists clusters (default rows ÷ 1,000, at least 10)Smaller and faster to build on big tables; build it after loading the data.

Columns with more than 2,000 numbers (OpenAI text-embedding-3-large is 3,072) are indexed in half precision (halfvec, up to 4,000) and searches use the same expression automatically. Per query, ef_search (HNSW) and probes (IVFFlat) trade speed for recall.

sov vector sql-index documents --m 24 --ef-construction 128
sov vector sql-index events --method ivfflat --lists 300 --metric l2
sov vector sql-status
sov vector sql-search documents --text "reset password" --ef-search 100
  • Vectors can have up to 16,000 dimensions; indexes work up to 2,000 (vector) and 4,000 (half precision).
  • Searches run as the caller, so row-level security applies: users only find rows they may read. The search endpoint (/api/v1/data/rel/vector/search) still returns the number of results asked for — the index keeps scanning past rows the caller can't see (pgvector iterative scans) — so a user who owns 5% of a table gets their 10 closest rows.
  • Inserting through /api/v1/data/rel/vector/rows takes up to 500 rows per request; vectors are bound as parameters. With embed: true, rows of a table with automatic embeddings that come without a vector are embedded in the same request (small batches, ai.sync_embed_max_rows), so they are searchable at once.
  • Equal-value filters are compared in the column's own type (a uuid filter uses the uuid index); filter_in matches any of several values.
  • A dimension mismatch fails with an error naming the expected size — re-embed with the right model.
  • Hybrid search (meaning + exact words) is built in: pass text and mode to the search endpoint — see Search by meaning, words or both.

#Automatic embeddings

Instead of embedding rows yourself, pick a table's text columns once. Sovaria adds the vector column (sized for the project's model) and an HNSW index if they are missing, embeds every row in the background, and embeds a row again when one of its text columns really changes — a trigger clears the stale vector, so it is never searched as current. Vectors › Automatic embeddings › Turn on for a table, or:

await sovaria.api.vector.sqlAutoEnable({ tableName: 'articles', sourceColumns: ['title', 'body'] })

// Then just write rows; new and edited ones are embedded within seconds
await sovaria.data.sql('insert into articles (title, body) values ($1, $2)', ['Reset your password', 'Forgot your login? …'])

const { tables, model } = await sovaria.api.vector.sqlAutoStatus()   // embedded / waiting rows, last error
  • A row's text is its source columns joined by new lines (up to 6,000 characters). Rows with no text are skipped.
  • A background pass runs every few seconds and embeds up to 128 rows per table; Embed now (sqlAutoSync) runs one at once, and the first batch is embedded when you turn it on.
  • A vector is only written to the version of the row it was computed from: an edit made while embedding is never overwritten with an old vector, the row is just embedded again.
  • Turning it off keeps the column and its vectors (search keeps working); new and edited rows are no longer embedded.
  • When every source column is text, a full-text (GIN) index is added for keyword and hybrid search, in the table's language (default simple; pass e.g. english when turning it on). Searches on the table use that language.
  • A row the embedding provider refuses (too long, invalid input) doesn't stop the table: the batch is retried row by row, the refused row is skipped (counted as skipped) until its text changes, and the rest is embedded. Vectors are written in one statement per batch.
  • Embedding keeps going after a restart or a cache flush: the list of projects to embed is kept durably and rebuilt within minutes.
  • Only the project team and the service key manage it; the settings live in sov_auto_embed, which apps can't read.

#Search by meaning, words or both

The search endpoint takes a vector, a text, or both. Text is embedded with the project's model for meaning-based ranking and matched word by word with Postgres full text:

const { results } = await sovaria.api.vector.sqlSearch({
  tableName: 'articles',
  text: 'how do I reset my password',
  mode: 'hybrid',            // 'vector' | 'keyword' | 'hybrid' (default when you pass text)
  k: 5,
  filter: { lang: 'en' },
})
// [{ id, title, body, score, vector_rank, keyword_rank, distance }, …]
ModeRanks byGood for
vectorDistance between the embeddings (cosine, L2 or inner product).Natural-language questions, synonyms, other phrasings.
keywordPostgres full text (websearch_to_tsquery, ts_rank_cd) over text_columns.Exact names, codes, SKUs, "quoted phrases", -excluded words.
hybridBoth rankings fused by reciprocal rank (score = Σ 1 / (60 + rank)); each row reports vector_rank and keyword_rank.Most search boxes.

Reranking

With rerank: true the search fetches more candidates (4 × k, or rerank_candidates) and reorders them with the platform's managed reranker (a cross-encoder set in the Control Center). Each result gets rerank_score and its retrieval_rank. It counts against ai.rerank_month; when no reranker is set up the answer says reranked: false and keeps the retrieval order.

FreeProUltraTeamEnterprise
Search results reranked with a managed reranker per month20010,00050,000200,0001,000,000
Text searches per app user per minute (embedding the query)2060120300600
Rows embedded in the insert request (embed on write)83264128256

App users' text searches (they make Sovaria embed the query on your quota) are limited per user, and per IP for the anon key and anonymous users: ai.app_embed_searches_per_min, then 429 with Retry-After. Searches with your own vector, and the team's searches, are not limited this way. The status endpoint is for the team only.

text_columns defaults to the table's automatic-embedding columns, else content. language picks the text search configuration (default simple, any language; english also matches "invoices" for "invoice"). Row-level security applies to every mode. Under row policies Postgres checks the policy before the full-text match, so the keyword index mostly speeds up team and service-key searches; give app users a selective filter on very large tables.

#Which model, and limits

The Vectors page shows the project's embedding model, and every search that embeds text returns it (model). With a real model (Gemini gemini-embedding-001 at 768 dimensions, or OpenAI) results match by meaning. Where none is configured Sovaria uses a built-in model labelled local-hash-… that matches shared words, not meaning: fine for trying things and for hybrid search, not for semantic search — collections then default to hybrid ranking and say semantic: false.

PlanTexts embedded per month (real model)
Free10,000
Pro500,000
Ultra2,000,000
Team10,000,000
Enterprise50,000,000

Use your own embedding key

Project owners and admins can switch the project to their own provider key on the Vectors or Knowledge page (Embedding model › Use your own key), with the SDK (sovaria.api.embeddings.setSettings) or PUT /api/v1/embeddings/settings: OpenAI, Gemini or any OpenAI-compatible /embeddings API (Voyage, Mistral, Together, a self-hosted server) with an optional dimension count (512 keeps almost all of the quality for most models and halves storage). The key is tested with one tiny embedding, encrypted, and never shown again. Those calls are billed by your provider and don't count against your plan. Use Sovaria's switches back and deletes the key.

Every embedding call records texts, tokens and an estimated cost from list prices, per month, model and who paid: the panel shows this month's total, and GET /api/v1/embeddings/usage returns the rows. Changing the model means stored vectors no longer match: rebuild automatic embeddings and re-add knowledge base documents.

Every text embedded with a real model counts: rows, collection texts and search queries (ai.embeddings_month). At the limit embedding stops until next month — automatic embeddings show the error and pick up again by themselves; staff can raise an organization's limit in the Control Center. Vectors from different models never mix: after a model change a collection is re-embedded on its next use (large ones with reembedCollection), and a table asks you to Re-embed it.

#The collections API (legacy)

FreeProUltraTeamEnterprise
Records per vector collection (legacy collections)2,00020,00050,00050,000100,000

sovaria.vector keeps text in named collections and searches them by text, embedding it for you:

await sovaria.vector.upsert('help-articles', [
  { id: 'a1', text: 'How to reset your password', metadata: { lang: 'en' } },
])
await sovaria.vector.setCollection('help-articles', { appSearch: true })   // let your apps search it
const hits = await sovaria.vector.search('help-articles', 'I forgot my login', { topK: 3, mode: 'hybrid', metadataFilter: { lang: 'en' } })

Managing collections (upsert, list, read, delete) is for the project team and the service key. Apps (anon key, signed-in users) may only search, and only collections opened with setCollection(name, { appSearch: true }) — the anon key ships in every app, so it can never write or list them. Search takes mode like the SQL endpoint; each collection records the model that embedded it. After a model change only the team re-embeds a collection: an app's search gets 409 REEMBED_REQUIRED instead of spending your quota.

#Retrieval-augmented generation

For documents, files and web pages, use a knowledge base (Knowledge bases (RAG)): Sovaria splits, embeds and keeps them current, answers come with citations, and agents use it directly. To build it yourself on your own tables:

  1. Embed the question

    With the same model as your documents — or pass text and let Sovaria embed it (hybrid search).

  2. Find the nearest rows

    Top 3–10 by distance, filtered to what the user may see.

  3. Answer with context

    Send the question and those rows to your language model from a function, so keys stay on the server (Functions).

In a function, embed with the SDK and the service key: await sovaria.vector.embed([text]) (JavaScript) or await client.vector_embed([text]) (Python) uses the project's model and counts like any embedding.

#Coming from Firebase or Supabase?

PlatformWhat this is called there
FirebaseFirestore vector search
SupabaseSupabase Vector (pgvector)
SovariaVector search and embeddings

Moving an existing app? Migrate from Supabase or Firebase imports users (with their passwords), data, files and rules.