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
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.
Link to a resource
You can link it to other resources, like a function or your Next.js app.
Once linked, you can query it in your function code using the SDK.
Constructor
Parameters
-
name
string
-
args?
VectorArgs
-
opts?
ComponentResourceOptions
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.
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.
transform?
transform.postgres?
Type PostgresArgs
|
(
args
:
PostgresArgs
=>
void
)
Transform the Postgres component.
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.
SDK
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.
VectorClient
IngestEvent
IngestEvent.image?
Type string
The base64 representation of the image used to generate the embedding vector.
At least one of text
or image
must be provided.
IngestEvent.metadata
Type Record
<
string
, any
>
Metadata for the event in JSON format. This metadata will be used to filter when retrieving and removing embeddings.
IngestEvent.text?
Type string
The text used to generate the embedding vector.
At least one of text
or image
must be provided.
RemoveEvent
Type Object
RemoveEvent.include
Type Record
<
string
, any
>
The metadata used to filter the removal of embeddings. Only embeddings with metadata that match the provided fields will be removed.
To remove embeddings for movie with id “movie-123”:
To remove embeddings for all movies:
RetrieveEvent
RetrieveEvent.count?
Type number
Default 10
The number of results to return.
RetrieveEvent.exclude?
Type Record
<
string
, any
>
Exclude embeddings with metadata that match the provided fields.
This will match the embedding with metadata:
But not the embedding with metadata:
RetrieveEvent.image?
Type string
The base64 representation of the image prompt used to retrive embeddings.
At least one of text
or image
must be provided.
RetrieveEvent.include
Type Record
<
string
, any
>
The metadata used to filter the retrieval of embeddings. Only embeddings with metadata that match the provided fields will be returned.
This will match the embedding with metadata:
But not the embedding with metadata:
RetrieveEvent.text?
Type string
The text prompt used to retrieve embeddings.
At least one of text
or image
must be provided.
RetrieveEvent.threshold?
Type number
Default 0
The threshold of similarity between the prompt and the retrieved embeddings. Only embeddings with a similarity score higher than the threshold will be returned. Expected value is between 0 and 1.
- 0 means the prompt and the retrieved embeddings are completely different.
- 1 means the prompt and the retrieved embeddings are identical.
RetrieveResponse
RetrieveResponse.metadata
Type Record
<
string
, any
>
Metadata for the event in JSON format that was provided when ingesting the embedding.
RetrieveResponse.score
Type number
The similarity score between the prompt and the retrieved embedding.
VectorClientResponse
VectorClientResponse.ingest
Type (event:
IngestEvent
) => Promise
<
void
>
VectorClientResponse.remove
Type (event:
RemoveEvent
) => Promise
<
void
>
VectorClientResponse.retrieve
Type (event:
RetrieveEvent
) => Promise
<
RetrieveResponse
>