Skip to Content
unii.docs
Guides

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

  1. Create a knowledge base and give it a name.
  2. Upload documents — text files, markdown, PDFs, or structured data.
  3. 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

create-kb.ts
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:

add-document.ts
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:

chat-with-kb.ts
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

On this page