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

# Knowledge Base

> Ground AI generation in your documents — upload PDFs, URLs, and text to give agents and carousels proprietary context instead of generic LLM output.

Upload your research, brand guidelines, and domain expertise. Autoposting indexes everything with vector embeddings and a knowledge graph — so every AI agent and carousel generation stays grounded in your content, not generic training data.

## Create a Knowledge Base

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://app.autoposting.ai/api-proxy/kb \
    -H "Authorization: Bearer sk_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Product Research",
      "slug": "product-research",
      "description": "Competitive analysis, customer interviews, and positioning docs."
    }'
  ```

  ```typescript TypeScript theme={null}
  const res = await fetch("https://app.autoposting.ai/api-proxy/kb", {
    method: "POST",
    headers: {
      Authorization: "Bearer sk_your_api_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: "Product Research",
      slug: "product-research",
      description: "Competitive analysis, customer interviews, and positioning docs.",
    }),
  });
  const { data } = await res.json();
  // data.kb._id — use as kbId when configuring agents
  ```
</CodeGroup>

## Add Documents

<Steps>
  <Step title="Request a presigned URL">
    Call `POST /kb/:kbId/docs/upload` with the filename and MIME type to receive a presigned upload URL.
  </Step>

  <Step title="Upload directly to storage">
    PUT the file to the presigned URL. No data passes through the Autoposting backend — uploads are fast regardless of file size.
  </Step>

  <Step title="Confirm and ingest">
    Call `POST /kb/:kbId/docs/complete` with the storage key to trigger the ingestion pipeline.
  </Step>
</Steps>

## Supported Formats

| Type        | Formats             | Description                                   |
| ----------- | ------------------- | --------------------------------------------- |
| File upload | PDF, DOCX, TXT      | Text extracted automatically during ingestion |
| URL ingest  | Any public web page | Backend crawls and extracts page text         |
| Raw text    | —                   | Paste content directly via the API            |

<Note>
  Large PDFs (100+ pages) can take 30–90 seconds to fully index. The KB `status` returns to `active` when all pending ingestion jobs complete.
</Note>

## Ingest a URL

```bash theme={null}
curl -X POST https://app.autoposting.ai/api-proxy/kb/:kbId/docs/ingest-url \
  -H "Authorization: Bearer sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/report", "label": "Q2 Market Research" }'
```

## Search the Knowledge Base

Find semantically relevant content across all indexed documents:

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://app.autoposting.ai/api-proxy/kb/:kbId/search?q=competitive+pricing&limit=10" \
    -H "Authorization: Bearer sk_your_api_key"
  ```

  ```typescript TypeScript theme={null}
  const res = await fetch(
    `https://app.autoposting.ai/api-proxy/kb/${kbId}/search?q=competitive+pricing&limit=10`,
    { headers: { Authorization: "Bearer sk_your_api_key" } }
  );
  const { data } = await res.json();
  // data.results = [{ docId, title, snippet, score, chunkIndex }]
  ```
</CodeGroup>

## KB Status

| Status     | Description                                  |
| ---------- | -------------------------------------------- |
| `active`   | Ready for queries                            |
| `building` | Ingestion job running                        |
| `error`    | Last ingestion failed — check `errorMessage` |

## Connect to an Agent

Attach a KB to an agent via the `kbId` field. Set `contentSource: "both"` to combine KB grounding with real-time news signals.

```json theme={null}
{
  "name": "Weekly Insights Agent",
  "kbId": "kb_id",
  "contentSource": "kb"
}
```

<Tip>
  Designate one KB as `isOrgDefault: true` — agents without an explicit `kbId` automatically use the org default KB.
</Tip>

<CardGroup cols={2}>
  <Card title="AI Agents" icon="robot" href="/concepts/agents">
    Connect a KB to an agent for grounded content generation.
  </Card>

  <Card title="Carousels" icon="images" href="/concepts/carousels">
    Use KB content as the source for AI carousel copy.
  </Card>

  <Card title="Posts" icon="paper-plane" href="/concepts/posts">
    KB-powered agent ideas become post drafts in the publish pipeline.
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/overview">
    Full endpoint reference for KB management and document ingestion.
  </Card>
</CardGroup>
