Vector quickstart

Set up a first vector index against a pgvector-backed Postgres database.

This quickstart uses Postgres because it is the most direct way to see one index, one write, and one query behind the shared Vector API.

Install the package

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/vector@main pg

This quickstart assumes you already have a Postgres database with pgvector available through DATABASE_URL.

Configure Vector

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/vector/nuxt'],
  vector: {
    provider: 'postgres',
    connectionString: process.env.DATABASE_URL,
    schema: 'public',
    tablePrefix: 'vitehub_vector_',
  },
})

Define a vector

server/vectors/docs.ts
import { defineVector } from '@vitehub/vector'

export default defineVector({
  dimensions: 1536,
  metric: 'cosine',
  filterable: ['kind'],
})

Query the vector

server/api/vectors/query.post.ts
import { getVector } from '@vitehub/vector'

export default defineEventHandler(async () => {
  const vector = getVector('docs')

  return await vector.query({
    topK: 5,
    vector: Array.from({ length: 1536 }, () => 0),
  })
})

Verify that it worked

Trigger the query route once:

Terminal
curl -X POST http://localhost:3000/api/vectors/query

The important success signal is that the app resolves the named vector handle and the provider accepts the query without a configuration error.

Next steps