MantisDocs

Vector search

Store embeddings with pgvector, declare HNSW indexes, and run typed hybrid similarity queries.

Every Mantis branch database runs Postgres 17 with pgvector enabled. Declare vector columns and HNSW indexes right in mantis/schema.ts, then run semantic or hybrid search through the typed SDK.

Define a vector column and index

Use t.vector(dimensions) for the embedding column and .vectorIndex(column, metric) to create an HNSW index:

mantis/schema.ts
import { defineSchema, t, table } from "@shipmantis/sdk";

export default defineSchema({
  documents: table({
    title: t.text(),
    body: t.text(),
    workspaceId: t.uuid(),
    published: t.boolean().default(true),
    embedding: t.vector(1536),
  })
    .index("workspaceId")
    .vectorIndex("embedding", "cosine"),
});
MetricPostgres opclassOperatorBest for
"cosine" (default)vector_cosine_ops<=>Text embeddings (OpenAI, Gemini, Cohere, Voyage)
"l2"vector_l2_ops<->Euclidean distance on unnormalized vectors
"inner"vector_ip_ops<#>Normalized vectors where dot product matches similarity

Push the schema with npx shipmantis push. Mantis enables the vector extension automatically and creates the HNSW index.

Changing vector dimensions

Changing the dimension count of an existing t.vector(dims) column is treated as a destructive change_type step and held on main for human approval. Try dimension changes on a branch first.

Insert embeddings

Pass a plain JavaScript number[] matching the column's declared dimensions:

await mantis.from("documents").insert({
  title: "Rewinding production writes",
  body: "Mantis records every write so any table or row can be rewound.",
  workspaceId,
  embedding: queryVector, // number[] of length 1536
});

Hybrid similarity search with similarTo

Pass similarTo to select(). Combine it with where, columns, and limit for filtered hybrid search — Mantis orders results by ascending distance and includes a typed _distance: number field on every returned row:

const matches = await mantis.from("documents").select({
  columns: ["id", "title", "body"],
  where: { workspaceId, published: true },
  similarTo: {
    column: "embedding",
    vector: queryVector,
    metric: "cosine",
  },
  limit: 10,
});

for (const doc of matches) {
  console.log(doc.title, doc._distance);
  //                     ^? number
}

Via MCP or raw HTTP

Your agent can run vector queries through run_query or POST /v1/query using the same shape:

{
  "op": "select",
  "table": "documents",
  "columns": ["id", "title"],
  "where": { "published": true },
  "similarTo": {
    "column": "embedding",
    "vector": [0.012, -0.044, 0.098],
    "metric": "cosine"
  },
  "limit": 5
}

Edge cases

CaseWhat happens
Vector length does not match t.vector(dims)Refused with 422; nothing is changed.
similarTo combined with access rulesPublishable-key requests still enforce row-level read rules before ranking results.
Branches & rewindEmbeddings are regular Postgres data — branches copy them, snapshots capture them, and rewinds restore them.

On this page