Overview
Upstash Vector Node.js Client
This is the official Node.js client for Upstash, written in TypeScript.
Installation
Usage
Initializing the client
There are two pieces of configuration required to use the Upstash vector client: an REST token and REST URL. These values can be passed using environment variables or in code through a configuration object. Find your configuration values in the console dashboard at https://console.upstash.com/.
Using environment variables
The environment variables used to configure the client are the following:
When these environment variables are set, the client constructor does not require any additional arguments.
Using a configuration object
If you prefer to pass configuration in code, the constructor accepts a config object containing the url
and token
values. This
could be useful if your application needs to interact with multiple projects, each with a different configuration.
Index operations
Upstash vector indexes support operations for working with vector data using operations such as upsert, query, fetch, delete, stats and reset.
Accessing an index
To perform data operations on an index, access it using the index
method.
Accessing an index, with metadata typing
If you are storing metadata alongside your vector values, you can pass a type parameter to index()
in order to get proper TypeScript typechecking.
Upsert records
Upstash vector expects records inserted into indexes to have the following form:
Querying
Querying with vector values
The query method accepts a large number of options. The dimension of the query vector must match the dimension of your index.
For example, to query by vector values you would pass the vector
param in the options configuration. For brevity sake this example query vector is tiny (dimension 2), but in a more realistic use case this query vector would be an embedding outputted by a model. Look at the Example code to see more realistic examples of how to use query
.
You include options to includeMetadata: true
or includeVectors: true
if you need this information. By default these are not returned to keep the response payload small.
Update a record
You may want to update vector vector
or metadata
. Specify the id and the attribute value you want to update.
Fetch records by their IDs
Delete records
For convenience there are several delete-related options. You can verify the results of a delete operation by trying to fetch()
a record.
Stats
To get statistics of your index, you can use the client like so:
Reset
To delete everything related with that index:
Contributing
Was this page helpful?