Skip to content

Vector

Reference doc for the `sst.aws.Vector` component.

The Vector component lets you store and retrieve vector data in your app.

  • It uses an LLM to generate the embedding.
  • Stores it in a vector database powered by RDS Postgres Serverless v2.
  • Provides a SDK to ingest, retrieve, and remove the vector data.

Create the database

const vector = new sst.aws.Vector("MyVectorDB");

Change the model

Optionally, use a different model, like OpenAI’s text-embedding-3-small model. You’ll need to pass in your OpenAI API key.

new sst.aws.Vector("MyVectorDB", {
openAiApiKey: new sst.aws.Secret("OpenAiApiKey").value,
model: "text-embedding-3-small"
});

You can link it to other resources, like a function or your Next.js app.

new sst.aws.Nextjs("MyWeb", {
link: [vector]
});

Once linked, you can query it in your function code using the SDK.

app/page.tsx
import { VectorClient } from "sst";
const vector = VectorClient("MyVectorDB");
await vector.retrieve({
text: "Some text to search for"
});

Constructor

new Vector(name, args?, opts?)

Parameters

Properties

ingestor

Type Output<string>

The name of the ingestor Lambda function.

remover

Type Output<string>

The name of the remover Lambda function.

retriever

Type Output<string>

The name of the retriever Lambda function.

The following are accessible through the SDK at runtime.

ingestor

Type string

The name of the ingestor Lambda function.

remover

Type string

The name of the remover Lambda function.

retriever

Type string

The name of the retriever Lambda function.

VectorArgs

model?

Type Input<amazon.titan-embed-text-v1 | amazon.titan-embed-image-v1 | text-embedding-ada-002 | text-embedding-3-small | text-embedding-3-large>

Default “amazon.titan-embed-text-v1”

The model used for generating the vectors. Supports AWS’ and OpenAI’s models.

To use OpenAI’s text-embedding-ada-002, text-embedding-3-small, or text-embedding-3-large model, you’ll need to pass in an openAiApiKey.

OpenAI’s text-embedding-3-large model produces embeddings with 3072 dimensions. This is scaled down to 2000 dimensions to store it in Postgres. The Postgres database in this component can store up to 2000 dimensions with a pgvector HNSW index.

{
model: "amazon.titan-embed-image-v1"
}

openAiApiKey?

Type Input<string>

Your OpenAI API key. This is needed only if you’re using the text-embedding-ada-002, text-embedding-3-small, or text-embedding-3-small model.

{
openAiApiKey: "<your-api-key>"
}

transform?

Type Object

Transform how this component creates its underlying resources.

transform.postgres?

Type PostgresArgs | (args: PostgresArgs => PostgresArgs | void)

Transform the Postgres component.