Deploy a vector database (pgvector)
Store embeddings and run similarity search — pgvector is built into the managed database.
For RAG, semantic search, or AI memory you need to store embeddings and find the nearest ones. Dockhold's managed database ships with pgvector enabled, so you get a real vector store with no extra service to run. This recipe is the whole path.
In a hurry? The pgvector-starter template is a working semantic-search API — click Use this template, then deploy it with the database add-on checked. It runs with no API key (a placeholder embedding) so you can see it work, then swap in a real model.
1. Enable the managed database
On the new-app page check "Add a managed
database," or add it later from Settings → Managed database.
Dockhold injects DATABASE_URL (and VECTOR_STORE_URL,
the same database). pgvector is already enabled — you don't install anything.
2. Create a table with a vector column
Embeddings are stored in a vector(N) column, where N is your model's dimension:
CREATE TABLE IF NOT EXISTS documents (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
embedding vector(1536) NOT NULL -- match your embedding model's size
); 3. Store embeddings
Turn text into a vector with your embedding model, then insert it. Use a
parameterized query and cast the array to vector:
// Node (pg) — embed() calls your model (e.g. your LLM provider's embeddings API)
const vec = "[" + (await embed(content)).join(",") + "]";
await pool.query(
"INSERT INTO documents (content, embedding) VALUES ($1, $2::vector)",
[content, vec]
); 4. Search by similarity
Embed the query and order by distance with pgvector's <->
operator (Euclidean; <=> is cosine):
const q = "[" + (await embed(query)).join(",") + "]";
const { rows } = await pool.query(
`SELECT content, (embedding <-> $1::vector) AS distance
FROM documents ORDER BY embedding <-> $1::vector LIMIT 5`,
[q]
);
The connection string, persistence, and isolation work exactly like any
managed database — see Connect a Postgres database.
For large tables, add an index (e.g. ivfflat or
hnsw) on the vector column to speed up search.
Troubleshooting
- "type vector does not exist": you're on a database without
pgvector. Dockhold's managed database has it pre-enabled — make sure the
database add-on is on and you're reading its
DATABASE_URL. - Dimension mismatch on insert: the
vector(N)column size must equal your embedding model's output length. - Results look random: confirm you embed the query with the same model you used for the stored documents.