FeaturesSearchOverview

Search

Aerostack Search provides vector similarity search powered by Cloudflare Vectorize. Store embeddings alongside your content, then find the most semantically similar results for any query.

Quick start

import { sdk } from '@aerostack/sdk'
 
// 1. Store content with embeddings
const text = 'Cloudflare Workers run V8 isolates at 300+ edge locations.'
const vector = await sdk.ai.embed(text)
 
await sdk.db.query(
  'INSERT INTO knowledge (id, text, embedding) VALUES (?, ?, ?)',
  [crypto.randomUUID(), text, JSON.stringify(vector)]
)
 
// 2. Search
const queryVector = await sdk.ai.embed('How does Cloudflare edge work?')
const results = await sdk.search.query(queryVector, {
  table: 'knowledge',
  limit: 5,
  threshold: 0.7,   // minimum similarity score (0–1)
})
 
results.forEach(r => {
  console.log(`Score: ${r.score.toFixed(3)} — ${r.text}`)
})

Methods

MethodDescription
sdk.search.query(vector, options)Find similar items by vector
sdk.search.upsert(id, vector, metadata?)Insert or update a vector
sdk.search.delete(id)Remove a vector

Full RAG pipeline

app.post('/api/ask', async (c) => {
  const { question } = await c.req.json()
 
  // 1. Embed the question
  const queryVector = await sdk.ai.embed(question)
 
  // 2. Find relevant context
  const results = await sdk.search.query(queryVector, {
    table: 'knowledge',
    limit: 5,
  })
 
  // 3. Format context
  const context = results.map(r => r.text).join('\n\n')
 
  // 4. Generate answer with context
  const answer = await sdk.ai.complete({
    model: 'gpt-4o-mini',
    system: 'Answer questions based only on the provided context.',
    prompt: `Context:\n${context}\n\nQuestion: ${question}`,
  })
 
  return c.json({
    answer: answer.text,
    sources: results.map(r => ({ id: r.id, score: r.score })),
  })
})

Search options

await sdk.search.query(vector, {
  table: 'documents',    // D1 table with an embedding column
  limit: 10,             // max results (default: 10)
  threshold: 0.5,        // min cosine similarity (default: none)
  filter: {              // metadata filters
    category: 'engineering',
    published: true,
  }
})

The embedding column in your D1 table stores vectors as JSON arrays. Aerostack automatically indexes them in Vectorize — no extra configuration needed.