> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/ai/knowledge-base-overview.md).

# Knowledge base (RAG) overview

DNotifier's **knowledge base** lets you index text documents per app, then retrieve relevant chunks with **semantic search** or inject them automatically into AI prompts via **`useKnowledgeBase: true`**.

{% hint style="info" %}
**Transport:** All knowledge-base APIs (`addDocument`, `search`, etc.) use **HTTP transport**. Connect with `transport: "http"` before calling them.
{% endhint %}

## How RAG fits together

```
  Indexing (write path)                Query (read path)
  ─────────────────────                ─────────────────

  addDocument ──► embed & store        search ──► ranked chunks
       │                                    │
       │                                    ├─► use in sendAI (useKnowledgeBase)
  updateDocument                           └─► use in workflow ctx.search()
  deleteDocument
  listDocuments / getDocument
```

**RAG** (retrieval-augmented generation) means: retrieve relevant documents, then let the AI answer using that context instead of guessing.

## Document model

Each document is keyed by **`recordId`** (your stable id — FAQ slug, article id, ticket attachment id, etc.).

| Field      | Required | Description                                                    |
| ---------- | -------- | -------------------------------------------------------------- |
| `recordId` | Yes      | Unique id within your app                                      |
| `content`  | Yes      | Plain text body to index                                       |
| `type`     | No       | Category label (`text`, `faq`, `policy`, …)                    |
| `metadata` | No       | JSON object — e.g. `{ "source": "help-center" }` for filtering |

```js
await notifier.addDocument({
  senderId: "user-123",
  recordId: "refund-policy",
  content: "Refund requests are processed within 5 business days.",
  type: "text",
  metadata: { source: "help-center", locale: "en" },
});
```

Content is chunked and embedded server-side. You do not manage vectors directly.

## Semantic search

`search` returns chunks ranked by similarity to your query:

```js
const hits = await notifier.search({
  senderId: "user-123",
  query: "how long do refunds take",
  limit: 5,
  minSimilarity: 0.7,
  filterbySource: "help-center",
});
```

→ [Semantic search](/product-docs/ai/semantic-search.md)

## AI with knowledge base

Pass `useKnowledgeBase: true` in a chat-style `sendAI` message. DNotifier retrieves relevant chunks and includes them in the prompt:

```js
const response = await notifier.sendAI({
  senderId: "user-123",
  message: {
    useKnowledgeBase: true,
    messages: [
      { role: "system", content: "Answer using only the provided knowledge." },
      { role: "user", content: "What is the refund timeline?" },
    ],
  },
});
```

→ [Chat-style AI messages](/product-docs/ai/chat-style-messages.md)

## Manage documents

| Operation            | Method           |
| -------------------- | ---------------- |
| Add                  | `addDocument`    |
| Update body/metadata | `updateDocument` |
| Get one + chunks     | `getDocument`    |
| List (paginated)     | `listDocuments`  |
| Delete               | `deleteDocument` |

→ [Manage documents](/product-docs/ai/manage-documents.md)

## Indexing strategies

| Pattern                    | When to use                                |
| -------------------------- | ------------------------------------------ |
| **One record per article** | Help center pages, policy docs             |
| **One record per FAQ**     | Short Q\&A pairs with stable `recordId`    |
| **Re-index on publish**    | `updateDocument` when CMS content changes  |
| **Batch import**           | Loop `addDocument` from a migration script |

{% hint style="warning" %}
Respect **`knowledgeBaseMaxWords`** from `getPlanLimits()`. Split very large manuals into logical `recordId` sections rather than one giant document.
{% endhint %}

## Workflows + RAG

Inside a workflow, agents can call `ctx.search()` and `ctx.sendAI()` with observability labels — useful for intent routers and support bots.

→ [Example: Intent router](/product-docs/workflows-and-agents/example-intent-router.md) · [Example: RAG bot](/product-docs/ai/example-rag-bot.md)

## Next steps

* [**Manage documents**](/product-docs/ai/manage-documents.md) — CRUD operations
* [**Semantic search**](/product-docs/ai/semantic-search.md) — Query tuning
* [**Build a RAG Q\&A bot**](/product-docs/ai/example-rag-bot.md) — End-to-end example
