# Knowledge Base

The knowledge base is the information your chatbot can draw on when answering questions. You can add sources as crawled websites, individual URLs, or manually written question-and-answer pairs. Elaras indexes the content and retrieves the most relevant chunks at inference time.

## Source types

| Type | Best for |
|---|---|
| **URL** | A single page — FAQ, pricing page, terms, product documentation |
| **Crawl** | An entire website or section of a site — Elaras follows internal links up to the depth you set |
| **Q&A** | Hand-crafted answers to specific questions the AI should always answer a particular way |

## Adding a URL source

In the Elaras dashboard, open your chatbot and go to **Knowledge > Add source > URL**.

Paste the URL and click **Add**. Elaras fetches the page, strips navigation and boilerplate, and indexes the content. Indexing usually completes within a few seconds for a single page.

Via the API:

```bash
curl -X POST "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"type": "url", "url": "https://example.com/faq"}'
```

## Adding a crawl source

Go to **Knowledge > Add source > Website crawl**. Enter the start URL and configure the crawl depth (how many links deep to follow from the starting page). A depth of `1` only indexes the start page; `2` follows links on the start page; and so on.

Large crawls run in the background — the dashboard shows indexing progress. You can start using the chatbot while the crawl completes; the knowledge base updates incrementally.

Via the API:

```bash
curl -X POST "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "crawl",
    "url": "https://example.com",
    "depth": 3
  }'
```

## Adding Q&A pairs

Go to **Knowledge > Add source > Q&A**. Enter a question and the exact answer you want the AI to give. Use Q&A for answers that need to be precise — pricing, legal disclaimers, support contact details — where you do not want the AI to paraphrase.

Via the API:

```bash
curl -X POST "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "qa",
    "question": "What is your refund policy?",
    "answer": "We offer a full refund within 30 days of purchase. No questions asked."
  }'
```

## Resyncing sources

URL and crawl sources are not automatically updated when your website changes. To pull in the latest content, resync the source from the dashboard (**Knowledge > source menu > Resync**) or via the API:

```bash
curl -X POST "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge/{knowledge_id}/resync" \
  -H "Authorization: Bearer sk_live_your_key_here"
```

A resync re-fetches the original URL or re-crawls the site and re-indexes the content. The previous version remains active until indexing completes.

## Listing and deleting sources

```bash
# List all knowledge sources
curl "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge" \
  -H "Authorization: Bearer sk_live_your_key_here"

# Delete a source
curl -X DELETE "https://api.elaras.ai/api/developer/v1/chatbots/{chatbot_id}/knowledge/{knowledge_id}" \
  -H "Authorization: Bearer sk_live_your_key_here"
```

Deleting a source removes its indexed content immediately. The chatbot will no longer draw on that source for new conversations.

## Tips

- **Be specific with URLs.** Adding the exact page that answers a question (e.g. `/pricing`) is more effective than crawling the whole site if only that page is relevant.
- **Use Q&A for invariants.** Facts that must never be paraphrased — prices, legal copy, contact details — should be Q&A pairs, not crawled pages.
- **Crawl depth vs. breadth.** A depth of 2–3 covers most documentation sites. Very large crawls slow indexing and can include irrelevant pages like blog archives.
- **Resync on publish.** Add a resync call to your deployment pipeline so the knowledge base stays current whenever your website is updated.
