> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usehasp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Knowledge Base & RAG

> Upload documents for the Assistant to search and cite — PHI redacted at ingestion, per-org isolation, signed audit trail.

The Knowledge Base lets your team upload documents — policies, contracts, reference material — for the Assistant to search and cite during chat. HASP owns the entire retrieval pipeline: extraction, PHI redaction, embedding, and vector search all happen inside HASP's infrastructure. No document content is ever sent to a third party for indexing.

Document RAG is off by default for every org. An admin turns it on and configures it under **Settings → Knowledge Base**.

## How it works

1. **Upload** — an admin or member uploads a document (PDF, DOCX, TXT, Markdown, HTML, or a scanned image) from the Knowledge Base page. Upload returns immediately; ingestion runs in the background.
2. **Extract** — text is pulled from the file. Scanned or image-only pages go through HASP's self-hosted OCR sidecar — no third-party OCR provider is involved.
3. **Redact** — the extracted text is scanned for PHI and redacted before anything is stored. This step is unconditional: there is no setting that disables it, and there is no path to re-identify a retrieved chunk later.
4. **Chunk & embed** — the redacted text is split into passages and embedded into your org's isolated vector index.
5. **Search** — during a chat turn, the Assistant can call its knowledge-base search tool to retrieve the most relevant passages and cite them in its response.

A document's status moves through `pending` → `extracting` → `chunking` → `embedding` → `ready` (or `failed`, with a reason shown in the UI). Uploading the same file content again is a no-op — HASP deduplicates by content hash and does not re-embed or re-bill for it.

## Per-org isolation

Every organization's documents, chunks, and vector index are isolated from every other organization at the database layer (row-level security), not just at the application layer. A search can never return another org's content, even if application code has a bug — this is enforced as a backstop independent of any query HASP's code issues.

## Citations

When the Assistant answers using knowledge-base content, the response includes numbered citations pointing back to the source document. Unlike a web citation, a document citation has no external link — it names the source document only, since the underlying content lives inside your org's own knowledge base. Citations persist across page refresh and are recorded in your [audit chain](/platform/audit-chain).

## Settings

| Setting                      | Description                                                           |
| ---------------------------- | --------------------------------------------------------------------- |
| **Enabled**                  | Turns knowledge-base retrieval on or off for the org. Off by default. |
| **Max chunks per retrieval** | Caps how many passages are returned per search (1–20).                |

## Public API access

Programmatic upload, listing, and deletion are available on the [Public API](/ai-api/quickstart) under the Knowledge Base endpoints, gated by the `knowledge:read` (list) and `ai:embeddings` (upload, delete) scopes. The model-facing retrieval tool is documented at [`knowledge.search`](/ai-api/tools/knowledge-search).

## Billing

Document RAG has no dedicated per-search fee. Cost is metered through your existing allotments — **Storage** for uploaded documents and their embeddings, and **AI Credits** for the embedding step at ingestion and the token cost of retrieved passages injected into a chat turn.
