> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.livingbrain.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.livingbrain.com/_mcp/server.

# Search and prompt context

## Semantic + keyword search

`searchPages` combines vector similarity with keyword matching and returns results ranked by
relevance, each with a snippet explaining the match and a `matchedOn` value saying why it
matched: `semantic`, `keyword`, or `both`.

**`TypeScript`**

```typescript TypeScript
const results = await client.workspace.searchPages({
  brainId,
  query: "why did we drop the cache",
  topK: 5,
});

for (const r of results) {
  console.log(r.similarity.toFixed(2), r.matchedOn, r.title);
}
```

**`Python`**

```python Python
results = client.workspace.search_pages(
    brain_id=brain_id, query="why did we drop the cache", top_k=5,
)

for r in results:
    print(f"{r.similarity:.2f}", r.matched_on, r.title)
```

Tune with `topK` (how many results) and `minSimilarity` (a floor, to drop weak matches rather
than returning padding). Keyword matches are returned even when their similarity is below
`minSimilarity`.

## Prompt index

Search answers a specific question. When you instead want to give an agent *general* working
context, use `index` — a compact, prompt-shaped digest of the brain's most important pages.

**`TypeScript`**

```typescript TypeScript
const index = await client.workspace.index({ brainId, limit: 40 });

const completion = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: `What you know about this user:\n\n${index}` },
    { role: "user", content: userMessage },
  ],
});
```

**`Python`**

```python Python
index = client.workspace.index(brain_id=brain_id, limit=40)

completion = openai.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": f"What you know about this user:\n\n{index}"},
        {"role": "user", "content": user_message},
    ],
)
```

> **Tip**
>
> This is the intended way to make an agent remember. Pinned pages rank first, so pinning is
> how a user says "always keep this in mind."

Pick `limit` to fit your context budget — start around 40 and tune against token cost.

## Connections

Connections are the non-obvious links the brain finds on its own.

**`TypeScript`**

```typescript TypeScript
// Strong connections the user hasn't dismissed yet
for await (const c of await client.workspace.listConnections({
  brainId, strength: "strong", unackedOnly: true,
})) {
  console.log(c.pageASlug, "↔", c.pageBSlug);
}

// Connections for one page
const related = await client.workspace.pageConnections({ brainId, slug });

// Dismiss without deleting
await client.workspace.ackConnection({ brainId, connectionId });
```

**`Python`**

```python Python
for c in client.workspace.list_connections(
    brain_id=brain_id, strength="strong", unacked_only=True,
):
    print(c.page_a_slug, "↔", c.page_b_slug)

related = client.workspace.page_connections(brain_id=brain_id, slug=slug)
client.workspace.ack_connection(brain_id=brain_id, connection_id=connection_id)
```

## Graph

For visualization, `graph` returns a renderable subgraph. Keep `nodeLimit` low enough to draw.

**`TypeScript`**

```typescript TypeScript
const { nodes, edges } = await client.workspace.graph({ brainId, nodeLimit: 150 });
```

**`Python`**

```python Python
graph = client.workspace.graph(brain_id=brain_id, node_limit=150)
```