upstash-vector-db-skills by gocallum/nextjs16-agent-skills
npx skills add https://github.com/gocallum/nextjs16-agent-skills --skill upstash-vector-db-skillsUPSTASH_VECTOR_REST_URL 和 UPSTASH_VECTOR_REST_TOKEN 复制到 .env 文件中广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
pnpm add @upstash/vector
UPSTASH_VECTOR_REST_URL=your_url
UPSTASH_VECTOR_REST_TOKEN=your_token
import { Index } from "@upstash/vector";
const index = new Index({
url: process.env.UPSTASH_VECTOR_REST_URL,
token: process.env.UPSTASH_VECTOR_REST_TOKEN,
});
当索引中配置了嵌入模型时,文本会自动被嵌入:
// 单文档
await index.upsert({
id: "doc-1",
data: "Upstash provides serverless vector database solutions.",
metadata: { source: "docs", category: "intro" },
});
// 批量
await index.upsert([
{ id: "doc-2", data: "Vector search powers semantic similarity.", metadata: { source: "docs" } },
{ id: "doc-3", data: "MixBread AI provides high-quality embeddings.", metadata: { source: "blog" } },
]);
// 带自动嵌入的语义搜索
const results = await index.query({
data: "What is semantic search?",
topK: 5,
includeMetadata: true,
});
results.forEach((result) => {
console.log(`ID: ${result.id}, Score: ${result.score}, Metadata:`, result.metadata);
});
命名空间将单个索引划分为隔离的子集。适用于多租户或多领域应用。
// 在 "blog" 命名空间中插入/更新
await index.namespace("blog").upsert({
id: "post-1",
data: "Next.js tutorial for Vercel deployment",
metadata: { author: "user-123" },
});
// 仅查询 "blog" 命名空间
const blogResults = await index.namespace("blog").query({
data: "Vercel deployment",
topK: 3,
includeMetadata: true,
});
// 列出所有命名空间
const namespaces = await index.listNamespaces();
console.log(namespaces);
// 删除命名空间
await index.deleteNamespace("blog");
// api/search.ts (Vercel Edge Function 或 Serverless Function)
import { Index } from "@upstash/vector";
export const config = {
runtime: "nodejs", // 或 "edge"
};
const index = new Index({
url: process.env.UPSTASH_VECTOR_REST_URL,
token: process.env.UPSTASH_VECTOR_REST_TOKEN,
});
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method not allowed" });
}
const { query, namespace = "", topK = 5 } = req.body;
try {
const searchIndex = namespace ? index.namespace(namespace) : index;
const results = await searchIndex.query({
data: query,
topK,
includeMetadata: true,
});
return res.status(200).json({ results });
} catch (error) {
console.error("Search error:", error);
return res.status(500).json({ error: "Search failed" });
}
}
// 重置(清除索引或命名空间中的所有向量)
await index.reset();
// 或重置特定命名空间
await index.namespace("old-data").reset();
// 删除单个向量
await index.delete("doc-1");
// 删除多个向量
await index.delete(["doc-1", "doc-2", "doc-3"]);
BAAI/bge-large-en-v1.5(1024 维,最佳性能,约 64.23 MTEB 分数)BAAI/bge-base-en-v1.5(768 维,良好平衡)BAAI/bge-small-en-v1.5(384 维,轻量级)BAAI/bge-m3(1024 维,稀疏 + 稠密混合模型)如果使用 MixBread 作为您的嵌入提供商:
index.upsert() / index.query() 处理文本即可。.env.local)中。namespace("user-123") 用于按用户搜索。topK 值合理(通常 5–10 足够)。try {
const results = await index.query({
data: userQuery,
topK: 5,
includeMetadata: true,
});
} catch (error) {
if (error.status === 401) {
console.error("Invalid credentials");
} else if (error.status === 429) {
console.error("Rate limited");
} else {
console.error("Query error:", error);
}
}
const docs = await index.query({ data: userQuestion, topK: 3 });
const context = docs.map((d) => d.metadata?.text).join("\n");
// 将上下文传递给 LLM
使用命名空间隔离每个租户的向量:
const userNamespace = `tenant-${userId}`;
await index.namespace(userNamespace).upsert({ id, data, metadata });
// 查询仅能看到该租户的数据
对于批量导入,分批进行插入/更新:
const batchSize = 100;
for (let i = 0; i < documents.length; i += batchSize) {
const batch = documents.slice(i, i + batchSize);
await index.upsert(batch);
console.log(`Indexed batch ${i / batchSize + 1}`);
}
""。每周安装量
146
代码仓库
GitHub Stars
18
首次出现
2026年1月20日
安全审计
安装于
opencode108
gemini-cli106
codex106
github-copilot101
cursor99
claude-code90
UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN to .envpnpm add @upstash/vector
UPSTASH_VECTOR_REST_URL=your_url
UPSTASH_VECTOR_REST_TOKEN=your_token
import { Index } from "@upstash/vector";
const index = new Index({
url: process.env.UPSTASH_VECTOR_REST_URL,
token: process.env.UPSTASH_VECTOR_REST_TOKEN,
});
When using an embedding model in the index, text is embedded automatically:
// Single document
await index.upsert({
id: "doc-1",
data: "Upstash provides serverless vector database solutions.",
metadata: { source: "docs", category: "intro" },
});
// Batch
await index.upsert([
{ id: "doc-2", data: "Vector search powers semantic similarity.", metadata: { source: "docs" } },
{ id: "doc-3", data: "MixBread AI provides high-quality embeddings.", metadata: { source: "blog" } },
]);
// Semantic search with auto-embedding
const results = await index.query({
data: "What is semantic search?",
topK: 5,
includeMetadata: true,
});
results.forEach((result) => {
console.log(`ID: ${result.id}, Score: ${result.score}, Metadata:`, result.metadata);
});
Namespaces partition a single index into isolated subsets. Useful for multi-tenant or multi-domain apps.
// Upsert in namespace "blog"
await index.namespace("blog").upsert({
id: "post-1",
data: "Next.js tutorial for Vercel deployment",
metadata: { author: "user-123" },
});
// Query only "blog" namespace
const blogResults = await index.namespace("blog").query({
data: "Vercel deployment",
topK: 3,
includeMetadata: true,
});
// List all namespaces
const namespaces = await index.listNamespaces();
console.log(namespaces);
// Delete namespace
await index.deleteNamespace("blog");
// api/search.ts (Vercel Edge Function or Serverless Function)
import { Index } from "@upstash/vector";
export const config = {
runtime: "nodejs", // or "edge"
};
const index = new Index({
url: process.env.UPSTASH_VECTOR_REST_URL,
token: process.env.UPSTASH_VECTOR_REST_TOKEN,
});
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method not allowed" });
}
const { query, namespace = "", topK = 5 } = req.body;
try {
const searchIndex = namespace ? index.namespace(namespace) : index;
const results = await searchIndex.query({
data: query,
topK,
includeMetadata: true,
});
return res.status(200).json({ results });
} catch (error) {
console.error("Search error:", error);
return res.status(500).json({ error: "Search failed" });
}
}
// Reset (clear all vectors in index or namespace)
await index.reset();
// Or reset a specific namespace
await index.namespace("old-data").reset();
// Delete a single vector
await index.delete("doc-1");
// Delete multiple vectors
await index.delete(["doc-1", "doc-2", "doc-3"]);
BAAI/bge-large-en-v1.5 (1024 dim, best performance, ~64.23 MTEB score)BAAI/bge-base-en-v1.5 (768 dim, good balance)BAAI/bge-small-en-v1.5 (384 dim, lightweight)BAAI/bge-m3 (1024 dim, sparse + dense hybrid)If using MixBread as your embedding provider:
index.upsert() / index.query() with text directly..env.local).namespace("user-123") for per-user search.topK reasonable (5–10 typically sufficient).try {
const results = await index.query({
data: userQuery,
topK: 5,
includeMetadata: true,
});
} catch (error) {
if (error.status === 401) {
console.error("Invalid credentials");
} else if (error.status === 429) {
console.error("Rate limited");
} else {
console.error("Query error:", error);
}
}
const docs = await index.query({ data: userQuestion, topK: 3 });
const context = docs.map((d) => d.metadata?.text).join("\n");
// Pass context to LLM
Use namespaces to isolate each tenant's vectors:
const userNamespace = `tenant-${userId}`;
await index.namespace(userNamespace).upsert({ id, data, metadata });
// Queries only see that tenant's data
For bulk imports, upsert in batches:
const batchSize = 100;
for (let i = 0; i < documents.length; i += batchSize) {
const batch = documents.slice(i, i + batchSize);
await index.upsert(batch);
console.log(`Indexed batch ${i / batchSize + 1}`);
}
"".Weekly Installs
146
Repository
GitHub Stars
18
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode108
gemini-cli106
codex106
github-copilot101
cursor99
claude-code90
Azure 配额管理指南:服务限制、容量验证与配额增加方法
107,600 周安装
OpenAI电子表格技能:自动化创建、编辑、分析Excel/CSV文件,支持公式与可视化
1,300 周安装
Wycheproof 密码学测试工具:验证实现正确性,检测已知漏洞
1,400 周安装
Trail of Bits 测试手册技能生成器 - 自动化创建安全测试AI技能工具
1,400 周安装
DWARF调试信息专家:解析、验证与处理DWARF标准文件的技术指南
1,400 周安装
Cairo/StarkNet 智能合约漏洞扫描器 | 6大安全模式检测与静态分析
1,400 周安装
OSS-Fuzz 开源模糊测试工具:Google 免费分布式安全测试平台使用指南
1,400 周安装