@upstash/search is a TypeScript SDK for Upstash AI Search.
Using @upstash/search you can:
- Perform AI-powered search queries
- Upsert documents to an index
- Fetch documents by their IDs
- Delete documents from a database
- Access database stats
- Reset databases
You can find the GitHub Repository here.
Installation#
Usage#
Initializing the client#
There are two pieces of configuration required to use the Upstash search client:
- a REST token
- a REST URL
These values can be passed using environment variables or through a configuration object. Find these connection details in the console dashboard.
Using environment variables (recommended)#
You can follow this guide to retrieve the following credentials.
When these environment variables are set, the client constructor does not require any additional arguments.
Using a configuration object#
The Search class accepts a config object containing the url and token values. This
could be useful if your application needs to interact with multiple databases, each with a different configuration.
Typescript#
The Search SDK supports defining your content and metadata types at the index level for complete type-safety.
Passing a Content type at the index level will provide type safety for the content coming back from or required for the following commands:
searchupsertfetchrange
In cases you don't want to define a content type at the index level, you can override the index level type definition for a specific command:
Telemetry#
This sdk sends anonymous telemetry data to help us improve your experience. We collect the following:
- SDK version
- Platform (Cloudflare, AWS or Vercel)
- Runtime version (node@18.x)
You can opt out by setting the UPSTASH_DISABLE_TELEMETRY environment variable
to any truthy value.
Alternatively, you can disable telemetry programmatically: