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

# Knowledge base

> Query your product's golden paths from Autoplay's vector database to give your support AI agent structured adoption context.

<Warning>
  This feature is coming soon. The endpoint and SDK helper described on this page are not yet available. This page documents the planned interface.
</Warning>

***

## What it is

When you onboard with Autoplay, your product's **golden paths** are indexed in Autoplay's managed vector database.

A golden path is a curated sequence of steps that represents the ideal journey a user takes to successfully adopt a feature — for example, the optimal path from sign-up to first meaningful action in your product.

Your support AI agent can query this knowledge base at inference time to retrieve the most relevant adoption guidance for any question a user asks.

***

## Why it matters

Real-time session data (delivered via the SDK) tells your support AI agent **what a user is doing right now**. The knowledge base tells it **what they should be doing** — and how to bridge the gap.

Together, they give the support AI agent two sources of structured context:

| Source                   | What it contains                             | How it's delivered                                     |
| ------------------------ | -------------------------------------------- | ------------------------------------------------------ |
| Real-time session stream | Live UI actions + session summaries          | `ActionsPayload` / `SummaryPayload` via SSE or webhook |
| Knowledge base           | Golden paths, feature guides, adoption steps | `GET /knowledge-base/{product_id}?query=...`           |

***

## How it fits in the pipeline

```
User asks: "How do I set up my first dashboard?"
         ↓
Support AI agent retrieves two sources in parallel:
  1. Real-time session context  ←  EventBuffer / RedisEventBuffer
  2. Relevant golden paths      ←  GET /knowledge-base/{product_id}?query=...
         ↓
Both are injected into the LLM context window
         ↓
Support AI agent answers with structured, product-specific guidance
```

***

## Endpoint

```
GET /knowledge-base/{product_id}?query=<text>&top_k=<int>
```

### Path parameters

<ParamField path="product_id" type="string" required>
  Your product identifier — the same one used for the SSE stream and webhook.
</ParamField>

### Query parameters

<ParamField query="query" type="string" required>
  The user's question or the session context snippet to use as the search vector.
  The endpoint embeds this text and performs an ANN lookup against your product's golden paths.
</ParamField>

<ParamField query="top_k" type="integer" default="3">
  Number of golden path results to return. Higher values give the LLM more context
  but consume more tokens.
</ParamField>

### Authentication

Pass the same Unkey API key used for the SSE stream:

```
Authorization: Bearer <api_key>
```

***

## Support AI agent integration example

Inject the knowledge base results alongside the live session context in your system prompt:

```python theme={null}
import httpx
from autoplay_sdk import AsyncConnectorClient, ActionsPayload

CONNECTOR_URL = "https://your-connector.onrender.com"
API_KEY = "unkey_xxxx..."
PRODUCT_ID = "acme-corp"


async def build_context(user_message: str, session_buffer: list[str]) -> str:
    """Fetch golden paths and combine with real-time session context."""
    async with httpx.AsyncClient() as client:
        resp = await client.get(
            f"{CONNECTOR_URL}/knowledge-base/{PRODUCT_ID}",
            params={"query": user_message, "top_k": 3},
            headers={"Authorization": f"Bearer {API_KEY}"},
        )
        resp.raise_for_status()
        kb = resp.json()

    golden_paths = "\n\n".join(
        f"## {r['title']}\n" + "\n".join(f"- {s}" for s in r["steps"])
        for r in kb["results"]
    )

    session_context = "\n".join(session_buffer) if session_buffer else "No session activity yet."

    return f"""
## What the user is doing right now
{session_context}

## Relevant adoption guidance
{golden_paths}
""".strip()


async def answer(user_message: str, session_buffer: list[str]) -> str:
    context = await build_context(user_message, session_buffer)
    # Pass `context` as part of your system prompt to the LLM
    ...
```

***

## Combining with RedisEventBuffer

For the best results, retrieve the user's recent session activity from your buffer
at the same time as fetching golden paths:

```python theme={null}
from autoplay_sdk import RedisEventBuffer

buffer = RedisEventBuffer(
    redis_url="redis://...",
    session_id=current_session_id,
)

# Drain the buffer and fetch knowledge base in parallel
session_payloads, kb_response = await asyncio.gather(
    buffer.drain(),
    fetch_knowledge_base(user_message),
)

session_text = "\n".join(p.to_text() for p in session_payloads)
```

***

## Golden path management

Golden paths for your product are managed through two surfaces:

**[Autoplay Chrome extension](https://chromewebstore.google.com/detail/autoplay/ckabmfabmccgkcpajebbdkniedapgfpm) (recommended)**

Record a golden path directly in your product — no manual writing required.
Open the extension, start recording, walk through the ideal user journey in
your app, then save. The extension captures each step automatically and adds
it to your product's knowledge base.

**Autoplay dashboard**

* Add and edit golden paths manually for each feature or workflow
* Edit step descriptions to match your UI terminology
* Archive paths for deprecated features
* Preview how paths are retrieved for sample queries

Contact your Autoplay account manager to configure your product's knowledge base.
