Skip to content
Beta — Truss is in public beta. Documentation is actively updated but may not reflect the latest changes. Report issues on GitHub.

Vectors

Truss includes built-in support for pgvector — the PostgreSQL extension for vector similarity search. Store embeddings, create indexes, and run similarity queries from the dashboard or API.

pgvector must be installed in your PostgreSQL instance. Most managed Postgres providers include it. For self-hosted Postgres:

CREATE EXTENSION IF NOT EXISTS vector;

Or via the Truss dashboard, navigate to Database > Vectors and click “Enable pgvector”.

Terminal window
curl http://localhost:8787/api/vectors/status

Returns whether the vector extension is installed and available.

A “collection” in Truss is a regular Postgres table with a vector column. The dashboard provides a GUI for creating and managing these tables.

Terminal window
curl -X POST http://localhost:8787/api/vectors/collections \
-H "Content-Type: application/json" \
-d '{
"schema": "public",
"table": "documents",
"dimensions": 1536
}'

This creates a table with id, content, embedding (vector), and metadata (jsonb) columns.

Terminal window
curl http://localhost:8787/api/vectors/collections
Terminal window
curl http://localhost:8787/api/vectors/collections/public/documents

Returns column info, row count, indexes, and dimension size.

Terminal window
curl -X DELETE http://localhost:8787/api/vectors/collections/public/documents

Use the Auto-REST API or SQL-over-HTTP to insert embeddings:

Terminal window
# Via Auto-REST
curl -X POST http://localhost:8787/v1/db/documents \
-H "apikey: truss_sk_your_key" \
-H "Content-Type: application/json" \
-d '{
"content": "The quick brown fox",
"embedding": [0.1, 0.2, 0.3, ...],
"metadata": {"source": "wikipedia"}
}'
# Via SQL
curl -X POST http://localhost:8787/v1/sql \
-H "apikey: truss_sk_your_key" \
-H "Content-Type: application/json" \
-d '{
"sql": "INSERT INTO documents (content, embedding, metadata) VALUES ($1, $2::vector, $3)",
"params": ["The quick brown fox", "[0.1, 0.2, 0.3]", {"source": "wikipedia"}]
}'
Terminal window
curl -X POST http://localhost:8787/api/vectors/collections/public/documents/search \
-H "Content-Type: application/json" \
-d '{
"vector": [0.1, 0.2, 0.3, ...],
"limit": 10,
"distance": "cosine"
}'

Supported distance functions:

  • cosine — cosine distance (default, good for normalized embeddings)
  • l2 — Euclidean distance
  • ip — inner product

For large collections, create a vector index to speed up similarity search:

Terminal window
curl -X POST http://localhost:8787/api/vectors/collections/public/documents/indexes \
-H "Content-Type: application/json" \
-d '{
"type": "hnsw",
"column": "embedding",
"options": {"m": 16, "ef_construction": 200}
}'

Index types:

  • HNSW — best for most use cases, good recall/speed tradeoff
  • IVFFlat — faster to build, good for very large datasets

Indexes are included in the collection details response.

Terminal window
curl -X DELETE http://localhost:8787/api/vectors/collections/public/documents/indexes/{index_name}
Terminal window
curl "http://localhost:8787/api/vectors/collections/public/documents/items?limit=50&offset=0"

The Database > Vectors view in the dashboard provides:

  • Extension status and enable/disable
  • Collection browser with row counts
  • Similarity search playground (paste a vector, see results)
  • Index management (create HNSW/IVFFlat, monitor size)
import pg from "pg";
const pool = new pg.Pool({ connectionString: DATABASE_URL });
// 1. Insert a vector embedding
await pool.query(`
INSERT INTO embeddings (content, embedding)
VALUES ($1, $2::vector)
`, ["Hello world", "[0.1, 0.2, 0.3, ...]"]);
// 2. Similarity search (cosine distance)
const { rows } = await pool.query(`
SELECT id, content, embedding <=> $1::vector AS distance
FROM embeddings
ORDER BY embedding <=> $1::vector
LIMIT 10
`, ["[0.1, 0.2, 0.3, ...]"]);
console.log(rows);
// 3. Create an HNSW index for fast approximate search
await pool.query(`
CREATE INDEX ON embeddings
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64)
`);