Skip to main content
The Orchata SDK includes tools for the Vercel AI SDK v5+, allowing AI models to query your knowledge base directly.

Installation

Install the SDK along with the required peer dependencies:
The AI tools require ai v5.0.0+ and zod v3.22.0+ as peer dependencies. If you don’t need AI SDK integration, you can use the core SDK without them.

Basic Usage

Create Orchata tools and use them with the AI SDK:

Available Tools

The createOrchataTools function creates these tools for your AI model:

Simple Query Tool

For simple use cases where you want to query a specific space, use the createQueryTool helper:

Configuration Options

Customize the tools with configuration options:

Configuration Options

string[]
Restrict which spaces the AI can access. If not provided, all spaces are accessible.
integer
default:"5"
Default number of results to return from queries.
boolean
default:"false"
Enable the uploadDocument tool. Keep disabled unless you want AI to modify your knowledge base.
boolean
default:"false"
Enable the createSpace tool. Keep disabled unless you want AI to create new spaces.

Streaming

Use streaming for real-time responses:

Complete Example

Here’s a complete example of an AI-powered chatbot that queries your knowledge base:

Tool Descriptions

Each tool includes a description that helps the AI understand when to use it:
  • queryKnowledge: “Search the knowledge base for information relevant to a query”
  • findRelevantSpaces: “Find which knowledge spaces are most relevant for a query”
  • listSpaces: “List all available knowledge spaces”
  • getDocumentContent: “Get the full content of a specific document”
  • uploadDocument: “Upload a new document to a knowledge space”
  • createSpace: “Create a new knowledge space”
The AI model uses these descriptions to decide which tools to call based on the user’s request.

Best Practices

Restrict Access

Use allowedSpaceIds to limit which spaces the AI can access. Don’t give AI access to sensitive data.

Disable Writes

Keep enableUpload and enableSpaceCreation disabled unless you specifically need AI to modify your knowledge base.

Set Limits

Use defaultTopK to control how many results the AI receives. Too many results can be overwhelming.

Provide Context

Use system prompts to guide the AI on how to use the knowledge base and cite sources.

Next Steps

Usage Guide

Learn about Spaces, Documents, and Queries APIs.

Error Handling

Handle errors gracefully with typed error classes.

Quickstart

Review the quickstart guide.

API Reference

Explore the REST API documentation.