Deploy and run
Vector search
Turn on pgvector for a Postgres database, make embeddings through the AI gateway, and search your data by meaning.
Vector search lets your app find things by meaning rather than exact words: similar products, relevant documents, the right answer from your help articles. CLI gives you both parts: a Postgres extension for it and AI embeddings.
How to do it: open your Postgres database and press Turn on vector search. Then make embeddings through CLI's AI models (see /docs/ai-gateway).
"Add semantic search over our help articles."
Vector search lets your app find things by meaning rather than exact words: similar products, relevant documents, the right answer from a knowledge base. CLI gives you both halves: pgvector in your Postgres database, and embeddings from the AI gateway.
Turn it on
Open the Postgres database, then choose Turn on vector search under its backups. Or:
POST /v1/services/:id/vectorCLI restarts the database on the pgvector image of the same Postgres version (your data stays), then creates the vector extension. It takes about as long as a restart.
Store embeddings
CREATE TABLE docs (id bigserial PRIMARY KEY, body text, embedding vector(1536));
CREATE INDEX ON docs USING hnsw (embedding vector_cosine_ops);Make the vectors with the AI gateway, using an embedding model from GET /v1/ai/models:
const r = await openai.embeddings.create({ model: "<embedding model>", input: "How do I reset my password?" });
// insert r.data[0].embedding into docs.embeddingThe vector size must match the model's, so check its documentation. Embeddings are charged per input token from the project's credit (/docs/ai-gateway).
Search
SELECT id, body FROM docs ORDER BY embedding <=> $1 LIMIT 5;<=> is cosine distance, <-> is Euclidean distance and <#> is negative inner product. Embed the user's question with the same model, pass it as $1, and you get the five closest documents.
For agents
Agents can turn it on with cli_vector and make embeddings with cli_ai or the embeddings endpoint. A good default for a knowledge base: chunk documents into a few paragraphs each, embed every chunk, and store the chunk text next to its vector so the search result can be shown or passed to a model.