Installation
Install the SDK along with the required peer dependencies:- npm
- pnpm
- yarn
- bun
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
ThecreateOrchataTools function creates these tools for your AI model:
| Tool | Description |
|---|---|
queryKnowledge | Search the knowledge base for relevant information |
findRelevantSpaces | Discover which spaces are most relevant for a query |
listSpaces | List all available knowledge spaces |
getDocumentContent | Get the full content of a specific document |
uploadDocument | Upload new content (disabled by default) |
createSpace | Create a new space (disabled by default) |
Simple Query Tool
For simple use cases where you want to query a specific space, use thecreateQueryTool helper:
Configuration Options
Customize the tools with configuration options:Configuration Options
Restrict which spaces the AI can access. If not provided, all spaces are accessible.
Default number of results to return from queries.
Enable the
uploadDocument tool. Keep disabled unless you want AI to modify your knowledge base.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”
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.