Vector
Reference doc for the `sst.aws.Vector` component.
The Vector
component lets you store and retrieve vector data in your app.
- It uses a vector database powered by RDS Postgres Serverless v2.
- Provides a SDK to query, put, and remove the vector data.
Create the database
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
dimension
Type Input
<
number
>
The dimension size of each vector.
The maximum supported dimension is 2000. To store vectors with greater dimension, use dimensionality reduction to reduce the dimension to 2000 or less. OpenAI supports dimensionality reduction automatically when generating embeddings.
transform?
transform.postgres?
Type PostgresArgs
|
(
args
:
PostgresArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the Postgres component.
Properties
clusterID
Type Output
<
string
>
The ID of the RDS Postgres Cluster.
nodes
nodes.postgres
Type Postgres
The Postgres database.
SDK
Use the SDK in your runtime to interact with your infrastructure.
VectorClient
Parameters
-
name
string
Returns VectorClientResponse
Create a client to interact with the Vector database.
Store a vector into the db
Query vectors that are similar to the given vector
PutEvent
PutEvent.metadata
Type Record
<
string
, any
>
Metadata for the event as JSON. This will be used to filter when querying and removing vectors.
PutEvent.vector
Type number
[]
The vector to store in the database.
QueryEvent
Type Object
QueryEvent.count?
Type number
Default 10
The number of results to return.
QueryEvent.exclude?
Type Record
<
string
, any
>
Exclude vectors with metadata that match the provided fields.
Given this filter.
This will match a vector with metadata:
But not a vector with the metadata:
QueryEvent.include
Type Record
<
string
, any
>
The metadata used to filter the vectors. Only vectors that match the provided fields will be returned.
Given this filter.
It will match a vector with the metadata:
But not a vector with this metadata:
QueryEvent.threshold?
Type number
Default 0
The threshold of similarity between the prompt and the queried vectors. Only vectors with a similarity score higher than the threshold will be returned.
This will return values is between 0 and 1.
0
means the prompt and the queried vectors are completely different.1
means the prompt and the queried vectors are identical.
QueryEvent.vector
Type number
[]
The vector used to query the database.
QueryResponse
QueryResponse.results
Type Object
[]
List of results matching the query.
QueryResponse.results[].metadata
Type Record
<
string
, any
>
Metadata for the event that was provided when storing the vector.
QueryResponse.results[].score
Type number
The similarity score between the prompt and the queried vector.
RemoveEvent
Type Object
RemoveEvent.include
Type Record
<
string
, any
>
The metadata used to filter the removal of vectors. Only vectors with metadata that match the provided fields will be removed.
To remove vectors for movie with id movie-123
:
To remove vectors for all movies:
VectorClientResponse
VectorClientResponse.put
Type (event:
PutEvent
) => Promise
<
void
>
Store a vector into the database.
VectorClientResponse.query
Type (event:
QueryEvent
) => Promise
<
QueryResponse
>
Query vectors that are similar to the given vector
VectorClientResponse.remove
Type (event:
RemoveEvent
) => Promise
<
void
>
Remove vectors from the database.
Methods
static get
Parameters
The name of the component.name
string
The RDS cluster id of the existing Vector database.clusterID
Input
<
string
>
Returns Vector
Reference an existing Vector database with the given name. This is useful when you create a Vector database in one stage and want to share it in another. It avoids having to create a new Vector database in the other stage.
Imagine you create a vector database in the dev
stage. And in your personal stage frank
,
instead of creating a new database, you want to share the same database from dev
.
Here app-dev-myvectordb
is the ID of the underlying Postgres cluster created in the dev
stage.
You can find this by outputting the cluster ID in the dev
stage.