All skills
upstash avatar

/upstash-redis-js

@35da719
by upstashupstash/skills27 stars
7

Work with the @upstash/redis TypeScript/JavaScript SDK, a serverless HTTP-based Redis client for Next.js, Vercel, Cloudflare Workers, edge runtimes, and Node.js. Use when adding a cache (cache-aside, write-through, TTL and expiration strategies), session storage and user sessions, a key-value store, leaderboards and rankings with sorted sets, counters, distributed locks, queues with lists, streams and consumer groups, sparse index-addressed arrays and ring buffers (ARSET, ARINSERT, ARRING, ARGREP, AROP), embeddings and nearest-neighbour vector search stored inside Redis (VECTOR commands via redis.vector, separate from @upstash/vector), JSON documents, pipelines and MULTI/EXEC transactions, Lua scripting, read replicas, or full-text search, typo-tolerant search, facets, aggregations, and search over Redis stream entries with Upstash Redis Search (different from regular FT.SEARCH; also available for TCP clients via @upstash/search-redis and @upstash/search-ioredis). Also use when migrating from ioredis or node-redis, when a Redis connection is needed from a serverless function without connection pooling, when integrating @upstash/ratelimit, or when the user says Redis cache, KV store, session store, serverless Redis, or Upstash Redis. Supports automatic serialization/deserialization of JavaScript types.

Use this Skill: https://skilld.dev/gh/upstash/skills/upstash-redis-js

This session only. Nothing lands on disk.

data-structuresvector-indexes.md

≈650 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Vector Indexes

Overview

A vector index stores embeddings under string IDs inside Redis and answers approximate nearest-neighbour queries. It lives at an ordinary Redis key (EXISTS, EXPIRE, DEL work on it). This is the VECTOR.* command family of Upstash Redis, which is separate from the standalone Upstash Vector database and its @upstash/vector SDK (see the upstash-vector-js skill).

Good For

  • Semantic search or RAG next to data already in Redis, without another service
  • Semantic caching of LLM responses
  • Small to medium embedding sets that share a Redis database's lifecycle

Prefer Upstash Vector (@upstash/vector) for metadata filtering, namespaces, hybrid/sparse search, or built-in embedding models.

Examples

import { Redis } from "@upstash/redis";

const redis = Redis.fromEnv();

// dimension (1-32768) and metric are fixed for the life of the index
const index = await redis.vector.createIndex({
  name: "docs",
  dimension: 1536,
  metric: "COSINE", // COSINE | EUCLIDEAN | DOT
  existsOk: true, // idempotent start-up path
});

// Handle to an existing index, no round trip
const same = redis.vector.index("docs");

// Upsert: 1 = added, 0 = replaced
await index.add("doc-1", embedding); // number[]
await index.add("doc-2", new Float32Array(embedding)); // sent as base64 FP32
await index.add("doc-3", { base64: openAiBase64Embedding }); // encoding_format: "base64"

// Nearest neighbours, best first. Scores are normalized to 0..1 for every metric.
const hits = await index.query({ vector: queryEmbedding, topK: 5, profile: "PRECISE" });
// [{ id: "doc-1", score: 0.93 }, ...]

await index.get("doc-1"); // number[] (float32 precision) | null
await index.count(); // 3
await index.info(); // { dimension: 1536, metric: "COSINE" } | null if missing
await index.delete("doc-1"); // 1 | 0
await index.drop(); // 1 | 0

Common Mistakes

  • Importing @upstash/vector for these commands. They are part of @upstash/redis and use the Redis REST URL and token.
  • Changing dimension or metric on an existing index. Drop and recreate it instead.
  • Comparing get() output to the original embedding exactly. Values are stored as 32-bit floats.
  • Expecting redis.pipeline() or redis.multi() to batch vector commands. Like search, the vector namespace is not available on pipelines: every call is its own request, so bulk loads should be chunked and run with Promise.all instead.
  • Checking existence with count(). It returns 0 for both a missing and an empty index; info() returns null only when the index is missing.

Source: SKILL.md on GitHub

1 warning10d3 checks · Risk SAFE
  • Gen Agent Trust Hub10d

    The skill provides a comprehensive set of documentation and code examples for using the Upstash Redis SDK. It covers various data structures, performance optimizations, and search capabilities. No malicious code, obfuscation, or unauthorized data access patterns were detected. The skill uses standard environment variables for secret management and references official Upstash packages.

  • Socket10d

    1 alert: gptSecurity

  • Snyk10d

    Risk: LOW · No issues

Signed by skilld at 35da719. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated 2 weeks ago
metadata
{
  "author": "Upstash",
  "homepage": "https://upstash.com"
}

README badge

README badge for upstash/skills/upstash-redis-js