AI SDK
Moss + Vercel AI SDK: In-Browser Semantic Search
The @moss-tools/vercel-sdk package exposes Moss operations as standard AI SDK tools. Language models can search indexes, create indexes, and manage documents as part of agentic workflows using generateText() or streamText(). Mutating tools set needsApproval: true for user confirmation.
Benefits
Why Use Moss with Vercel AI SDK
Standard AI SDK tool() definitions - mossSearchTool, mossAddDocsTool, mossCreateIndexTool, and more
Prebind tools to a specific index for simpler schemas, or let the LLM choose dynamically
Mutating tools (addDocs, createIndex, deleteDocs) set needsApproval: true for safety
Works with any AI SDK provider: OpenAI, Anthropic, Google, and more
TypeScript-native with typed input/output schemas via Zod
Integration
Quick Start
import { MossClient } from '@moss-dev/moss'
import {
mossSearchTool,
mossAddDocsTool,
mossCreateIndexTool,
mossListIndexesTool,
} from '@moss-tools/vercel-sdk'
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
const client = new MossClient(PROJECT_ID, PROJECT_KEY)
// Prebind tools to a specific index
const tools = {
search: mossSearchTool({ client, indexName: 'docs' }),
addDocs: mossAddDocsTool({ client, indexName: 'docs' }),
createIndex: mossCreateIndexTool({ client }),
listIndexes: mossListIndexesTool({ client }),
}
const result = await generateText({
model: openai('gpt-4o'),
tools,
maxSteps: 5,
prompt: 'Search the docs for return policy info.',
})Setup
Get Started in 3 Steps
Install the packages
Run npm install @moss-tools/vercel-sdk @moss-dev/moss ai zod to add Moss tools to your project.
Initialize tools
Create a MossClient and pass it to the tool factories. Optionally prebind an indexName for simpler LLM schemas.
Use with generateText or streamText
Pass the tools object to generateText() or streamText(). The LLM can now search your knowledge base, create indexes, and manage documents autonomously.
FAQ
Frequently asked questions
Explore