# Knowledge Base

Open your agent in the console and select **Knowledge Base**. This panel has two tabs:

- **Documents**
- **Jobs**

Related pages:

- [Instructions](instructions.md)
- [Functions](functions.md)

## What the Knowledge Base does

Leilani's Knowledge Base gives an agent a searchable store of reference material it can use when callers ask factual questions or when the agent needs background information before answering.

At a high level, the Knowledge Base does three things:

- stores uploaded documents for an agent
- lets jobs crawl URI-based content and ingest it as documents
- exposes both sources through the built-in `knowledge_base_search` tool during calls

Knowledge Base content is separate from custom [Functions](functions.md). Functions perform actions. The Knowledge Base supplies retrieval context.

## How Knowledge Base search behaves

During a call, Leilani can call `knowledge_base_search` whenever it needs factual grounding or supporting context.

In practice:

- the caller's question is embedded and matched against stored document chunks
- search returns up to three of the closest matches
- each match includes the source document name, media type, matching content chunk, and score
- uploaded documents and job-created documents are searched together

This means jobs do not create a separate index. They create documents that join the same Knowledge Base.

## Documents tab

The Documents tab lists all documents for the agent, including documents created manually and documents created by Jobs.

The Documents table has these columns:

- `Name`
- `Media Type`
- `Size (MiB)`
- `Checksum`
- `Created At`

Available actions:

- `Create` (upload a file)
- `Delete`

## Uploading a document

Select **Create** to choose a file from your computer.

Current document upload behavior:

- the console reads the selected file as text and sends that text to the API
- the document name is stored in lowercase
- the uploaded text is split into overlapping chunks and embedded for search
- documents are unique by name within an agent

Text-based files work best, such as:

- `.md`
- `.txt`
- `.csv`
- `.json`
- `.html`

Binary formats such as PDF, DOCX, or images are not parsed by this upload path. For website content, use a Job instead.

### Document best practices

- keep each document focused on one topic, policy, or FAQ area
- use stable, descriptive filenames
- prefer cleaned reference text over raw exports
- split very large reference sets into smaller files when possible
- avoid uploading the same content under multiple names unless you want duplicate retrieval candidates

## Jobs tab

The Jobs table has these columns:

- `ID`
- `URI`
- `Created At`
- `Updated At`

Available actions:

- `Create`
- `Run`
- `Edit`
- `Delete`

## Create or edit a Job

A Job stores a fully qualified URI that Leilani can process in the background.

Current job requirements and behavior:

- `URI` is required
- the URI must be fully qualified, such as `https://example.com/docs`
- `HTTP` and `HTTPS` URIs are currently supported
- each agent can only have one Job per URI

## How Jobs run

When a Job runs, Leilani:

1. starts at the configured URI
2. crawls reachable pages from that starting point
3. respects `robots.txt`
4. converts crawled HTML into markdown
5. stores each crawled page as a document in the Knowledge Base

Job-created documents use:

- the final page URL as the document name
- `text/markdown` as the media type

Before a Job writes new documents, Leilani deletes the documents previously created by that same Job. A rerun is therefore a replace operation, not a merge.

You can run a Job manually from the console with **Run**.

Leilani also reruns all Knowledge Base Jobs automatically every 24 hours.

### Relationship between Jobs and Documents

Jobs do not bypass Documents. They create Documents.

That means:

- job-created pages appear in the Documents tab
- deleting a Job also deletes the documents created by that Job
- deleting a job-created document does not delete the Job itself
- the next Job run can recreate any deleted job-owned documents

### Job best practices

- use Jobs for public or web-hosted reference content that changes over time
- start from a narrow documentation section rather than a broad homepage
- prefer stable help-center or docs URLs over marketing pages
- expect best results from pages that render as normal HTML without authentication
- use uploaded Documents for private internal material that is not available by URI

## Choosing between Documents and Jobs

Use **Documents** when the source is curated, internal, or already available as clean text.

Typical examples:

- internal SOPs
- pricing notes
- policy summaries
- office-specific answers
- agent scripts or escalation references

Use **Jobs** when the source lives on a website and should be refreshed automatically.

Typical examples:

- public help-center articles
- product documentation
- knowledge base sections on your own site
- reference pages that change over time

Many agents should use both:

- Documents for private or curated material
- Jobs for public or frequently updated web content

## Instruction guidance

Knowledge Base quality depends on both content and prompt design.

In your [Instructions](instructions.md), tell the agent when it should:

- use the Knowledge Base before answering factual questions
- summarize retrieved content conservatively
- admit uncertainty when results are weak or missing
- fall back to web search or another workflow only when appropriate
