Knowledge bases
Create and manage knowledge bases to ground AI responses in your own data.
Overview
Knowledge bases let you index your own documents so the Unii API can ground chat completions in your content. Instead of relying on the model's training data, responses are based on the documents you provide — reducing hallucinations and improving accuracy.
How knowledge bases work
- Create a knowledge base and give it a name.
- Upload documents — text files, markdown, PDFs, or structured data.
- Query — reference the knowledge base in your chat completion requests. Unii handles chunking, embedding, and retrieval automatically.
Note
Knowledge base processing may take a few seconds for large documents. The API returns a status you can poll to check when indexing is complete.
Creating a knowledge base
import { UniiClient } from "@unii/sdk";const client = new UniiClient({apiKey: process.env.UNII_API_KEY,});const kb = await client.knowledgeBases.create({name: "Product Documentation",description: "Technical docs for our product",});console.log(kb.id); // "kb_abc123"Adding documents
After creating a knowledge base, add documents:
const document = await client.knowledgeBases.documents.create(kb.id, {filename: "getting-started.md",content: fs.readFileSync("./docs/getting-started.md", "utf-8"),});console.log(document.status); // "indexing" → "ready"Using a knowledge base in chat
Reference the knowledge base when creating a chat completion:
const response = await client.createChatCompletion({model: "unii-latest",knowledgeBaseId: "kb_abc123",messages: [ { role: "user", content: "How do I reset my password?" },],});console.log(response.choices[0].message.content);The response is grounded in the documents you indexed, not the model's general training data.
Supported formats
Knowledge bases accept the following document formats:
- Markdown (
.md,.mdx) - Plain text (
.txt) - PDF (
.pdf) - HTML (
.html) - JSON (
.json)
Important
The exact supported formats and size limits depend on your plan. Check the API Reference for current limits.
Next steps
- Try chat completions to send grounded requests.
- Enable streaming for real-time responses.
- Read the API Reference for the full knowledge base API.