https://github.com/upstash/search-js
An HTTP/REST based AI Search client built on top of Upstash REST API.
https://github.com/upstash/search-js
Last synced: 7 months ago
JSON representation
An HTTP/REST based AI Search client built on top of Upstash REST API.
- Host: GitHub
- URL: https://github.com/upstash/search-js
- Owner: upstash
- License: mit
- Created: 2025-03-18T12:43:21.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-06-18T07:57:08.000Z (7 months ago)
- Last Synced: 2025-06-18T08:44:06.584Z (7 months ago)
- Language: TypeScript
- Size: 2.5 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - upstash/search-js - An HTTP/REST based AI Search client built on top of Upstash REST API. (TypeScript)
README
# Upstash AI Search   
> [!NOTE]
> **This project is in GA Stage.**
>
> The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
> The Upstash team is committed to maintaining and improving its functionality.
It is a connectionless (HTTP based) AI Search client and designed for:
- Serverless functions (AWS Lambda ...)
- Cloudflare Workers
- Next.js, Jamstack ...
- Client side web/mobile applications
- WebAssembly
- and other environments where HTTP is preferred over TCP.
## Quick Start
### Install
#### Node.js
```bash
npm install @upstash/search
```
### Create Database
Create a new database on [Upstash](https://console.upstash.com/search)
## Basic Usage:
```ts
import { Search } from "@upstash/search";
type Content = {
title: string;
genre: "sci-fi" | "fantasy" | "horror" | "action";
category: "classic" | "modern";
};
type Metadata = {
director: string;
};
// Initialize Search client
const client = new Search({
url: "",
token: "",
});
// Create or access a index
const index = client.index("movies");
// Upsert data into the index
await index.upsert([
{
id: "star-wars",
content: { title: "Star Wars", genre: "sci-fi", category: "classic" },
metadata: { director: "George Lucas" },
},
{
id: "inception",
content: { title: "Inception", genre: "action", category: "modern" },
metadata: { director: "Christopher Nolan" },
},
]);
// Fetch documents by IDs
const documents = await index.fetch({
ids: ["star-wars", "inception"],
});
console.log(documents);
// AI search with reranking:
const searchResults = await index.search({
query: "space opera",
limit: 2,
reranking: true,
});
console.log(searchResults);
// AI search without reranking:
const searchResults = await index.search({
query: "space opera",
limit: 2,
});
console.log(searchResults);
// AI search with filter:
const searchResults = await index.search({
query: "space",
limit: 2,
filter: "category = 'classic'",
});
// Delete a document by ID
await index.delete({
ids: ["star-wars"],
});
// Search within a document range
const { nextCursor, documents: rangeDocuments } = await index.range({
cursor: 0,
limit: 1,
prefix: "in",
});
console.log(rangeDocuments);
// Reset the index (delete all documents)
await index.reset();
// Get index and namespace info
const info = await search.info();
console.log(info);
```