cloudflare-vectorize

Cloudflare Vectorize 提供的边缘无服务器向量数据库。适用于在 Cloudflare Workers 上构建语义搜索、边缘 RAG 管道、低延迟向量相似性搜索,或在无需管理独立向量数据库的情况下存储和查询嵌入向量。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "cloudflare-vectorize":https://skillpi.com/zh/skills/deepskill-3ce971b088caaf4809dda0afe283d05aae69555c33493f5c5f4c547a4115ce0d。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

Cloudflare Vectorize 提供的边缘无服务器向量数据库。适用于在 Cloudflare Workers 上构建语义搜索、边缘 RAG 管道、低延迟向量相似性搜索,或在无需管理独立向量数据库的情况下存储和查询嵌入向量。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: cloudflare-vectorize
description: >-
  Serverless vector database at the edge with Cloudflare Vectorize. Use when:
  building semantic search on Cloudflare Workers, RAG pipelines at the edge,
  low-latency vector similarity search, or storing and querying embeddings
  without managing a separate vector database.
license: Apache-2.0
compatibility: "Requires Cloudflare Workers with Vectorize binding. Use wrangler 3+."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: data-ai
  tags: ["cloudflare", "vectorize", "vector-database", "edge", "semantic-search"]
  use-cases:
    - "Build semantic search for a documentation site using Cloudflare Workers + Vectorize"
    - "Implement RAG at the edge combining Vectorize with Workers AI embeddings"
    - "Store and query product embeddings for recommendation systems on Cloudflare"
  agents: [claude-code, openai-codex, gemini-cli, cursor]

Cloudflare Vectorize

Overview

Cloudflare Vectorize is a globally distributed vector database built into the Cloudflare Workers platform. It stores high-dimensional vectors (embeddings) and supports fast approximate nearest-neighbor search — all at the edge, with no separate infrastructure to manage.

Key features:

  • Create and query indexes directly from Workers
  • Metadata filtering alongside vector similarity
  • Namespace support for multi-tenant isolation
  • Native integration with Workers AI for end-to-end RAG
  • Scales automatically with zero configuration

Setup

1. Create a Vectorize index

Use Wrangler CLI to create an index. Specify the embedding dimensions and distance metric:

# For BAAI/bge-base-en-v1.5 (768 dims, cosine similarity)
npx wrangler vectorize create my-index \
  --dimensions=768 \
  --metric=cosine

# For OpenAI text-embedding-3-small (1536 dims)
npx wrangler vectorize create my-index \
  --dimensions=1536 \
  --metric=cosine

# Euclidean and dot-product are also supported
npx wrangler vectorize create my-index \
  --dimensions=384 \
  --metric=euclidean

2. Bind the index in wrangler.toml

name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-09-23"

[[vectorize]]
binding = "VECTORIZE_INDEX"
index_name = "my-index"

3. TypeScript types

export interface Env {
  VECTORIZE_INDEX: VectorizeIndex
}

Instructions

Step 1: Insert vectors

Each vector needs a unique string id and a values array matching the index dimensions:

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const vectors: VectorizeVector[] = [
      {
        id: "doc-001",
        values: [0.1, 0.2, 0.3, /* ... 768 total */],
        metadata: { title: "Introduction to Cloudflare", url: "/docs/intro" },
      },
      {
        id: "doc-002",
        values: [0.4, 0.5, 0.6, /* ... */],
        metadata: { title: "Workers AI Overview", url: "/docs/workers-ai" },
      },
    ]

    const result = await env.VECTORIZE_INDEX.insert(vectors)
    // result.count = number of vectors inserted

    return Response.json({ inserted: result.count })
  },
}

Step 2: Query for similar vectors

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const { queryVector, topK = 5 } = await request.json() as {
      queryVector: number[]
      topK?: number
    }

    const results = await env.VECTORIZE_INDEX.query(queryVector, {
      topK,
      returnMetadata: true,   // include metadata in results
      returnValues: false,    // skip returning raw vector values
    })

    // results.matches is sorted by score (highest = most similar)
    return Response.json({
      matches: results.matches.map(m => ({
        id: m.id,
        score: m.score,
        metadata: m.metadata,
      }))
    })
  },
}

Step 3: Metadata filtering

Filter results to a subset before computing similarity — useful for multi-tenant or categorized data:

const results = await env.VECTORIZE_INDEX.query(queryVector, {
  topK: 10,
  returnMetadata: true,
  filter: {
    category: { $eq: "documentation" },
  },
})

// Compound filter
const filtered = await env.VECTORIZE_INDEX.query(queryVector, {
  topK: 5,
  returnMetadata: true,
  filter: {
    language: { $eq: "en" },
    published: { $eq: true },
  },
})

Supported filter operators: $eq, $ne, $lt, $lte, $gt, $gte, $in

Step 4: Namespace support

Use namespaces to isolate data for different tenants or categories within a single index:

// Insert with namespace
await env.VECTORIZE_INDEX.insert([{
  id: "tenant-a-doc-1",
  values: embedding,
  metadata: { text: "Document content..." },
  namespace: "tenant-a",
}])

// Query within a namespace
const results = await env.VECTORIZE_INDEX.query(queryVector, {
  topK: 5,
  returnMetadata: true,
  namespace: "tenant-a",
})

Step 5: Get, update, and delete vectors

// Get vectors by ID
const vectors = await env.VECTORIZE_INDEX.getByIds(["doc-001", "doc-002"])

// Upsert (insert or update)
await env.VECTORIZE_INDEX.upsert([{
  id: "doc-001",
  values: newEmbedding,
  metadata: { updated: true },
}])

// Delete by ID
await env.VECTORIZE_INDEX.deleteByIds(["doc-001", "doc-002"])

Step 6: End-to-end RAG with Workers AI

Complete RAG pipeline — embed query, search Vectorize, generate answer with LLM:

export interface Env {
  AI: Ai
  VECTORIZE_INDEX: VectorizeIndex
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const { question } = await request.json() as { question: string }

    // 1. Embed the user's question
    const embeddingResult = await env.AI.run("@cf/baai/bge-base-en-v1.5", {
      text: [question],
    })
    const queryVector = embeddingResult.data[0]

    // 2. Find relevant documents
    const searchResults = await env.VECTORIZE_INDEX.query(queryVector, {
      topK: 3,
      returnMetadata: true,
    })

    const context = searchResults.matches
      .map(m => m.metadata?.text as string)
      .filter(Boolean)
      .join("\n\n")

    // 3. Generate answer with context
    const answer = await env.AI.run("@cf/meta/llama-3-8b-instruct", {
      messages: [
        {
          role: "system",
          content: `Answer the question using only the provided context.\n\nContext:\n${context}`,
        },
        { role: "user", content: question },
      ],
      max_tokens: 512,
    })

    return Response.json({
      answer: answer.response,
      sources: searchResults.matches.map(m => ({
        id: m.id,
        score: m.score,
        url: m.metadata?.url,
      })),
    })
  },
}

Step 7: Bulk indexing pipeline

For indexing large document collections, batch inserts for efficiency:

async function indexDocuments(
  documents: Array<{ id: string; text: string; metadata: Record<string, unknown> }>,
  env: Env,
  batchSize = 100
) {
  for (let i = 0; i < documents.length; i += batchSize) {
    const batch = documents.slice(i, i + batchSize)

    // Embed batch
    const embeddingResult = await env.AI.run("@cf/baai/bge-base-en-v1.5", {
      text: batch.map(d => d.text),
    })

    // Prepare vectors
    const vectors: VectorizeVector[] = batch.map((doc, idx) => ({
      id: doc.id,
      values: embeddingResult.data[idx],
      metadata: { ...doc.metadata, text: doc.text },
    }))

    // Insert batch
    await env.VECTORIZE_INDEX.insert(vectors)
    console.log(`Indexed ${i + batch.length}/${documents.length} documents`)
  }
}

Manage indexes via Wrangler

# List all indexes
npx wrangler vectorize list

# Describe an index (dimensions, metric, vector count)
npx wrangler vectorize info my-index

# Delete an index
npx wrangler vectorize delete my-index

# Get vectors by ID (for debugging)
npx wrangler vectorize get-vectors my-index --ids=doc-001,doc-002

Guidelines

  • Dimensions must match exactly what your embedding model produces — mismatches cause errors at insert time.
  • Use cosine distance for normalized text embeddings (BAAI, OpenAI); use euclidean or dot-product only when your model specifically recommends it.
  • Store the original text in metadata so you can return it with search results without a separate database lookup.
  • Vectorize supports up to 100 vectors per insert() call — batch larger datasets.
  • Metadata values must be strings, numbers, or booleans; nested objects are not supported in filters.
  • Use namespaces for multi-tenant apps instead of separate indexes — it's cheaper and simpler.
  • Vectorize indexes have eventual consistency; newly inserted vectors may not appear in queries for a few seconds.
  • Combine with Workers AI for fully serverless RAG — no external embedding API keys required.

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供完整的 Cloudflare Vectorize 向量数据库端到端解决方案
  • 涵盖从索引创建到 RAG 实现的完整工作流
  • 适用于边缘计算场景下的语义搜索和向量检索需求
触发精准95/100

亮点

  • 触发词精准覆盖语义搜索、边缘 RAG、向量相似性搜索等核心场景
  • 明确界定适用边界,避免误触发
结构规范90/100

亮点

  • 分步骤清晰展示操作流程,易于理解和执行
  • 包含完整的 TypeScript 示例代码和配置说明
  • frontmatter 信息完整,文档结构规范
执行可靠92/100

亮点

  • 基于 Cloudflare 官方服务,工具来源可靠
  • 参数说明准确,覆盖批量处理和异常场景
  • 提供完整的错误处理和使用指南
证据可验 (前四项均值)92/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。