> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/stackai-mcp/tool-reference/connections-knowledge-and-discovery/kb-search.md).

# kb\_search

Retrieve ranked chunks from one knowledge base. query\_strategy is semantic (default), keyword or hybrid. top\_k defaults to 5 and caps at 20.

**Effect:** This call reads data and does not run or change a project.

## Inputs

| Name             | Type                               | Requirement | Description                                                                     |
| ---------------- | ---------------------------------- | ----------- | ------------------------------------------------------------------------------- |
| `kb_id`          | string                             | Required    | Knowledge base ID from `kb_list`.                                               |
| `query`          | string                             | Required    | Nonempty question or search text, at most 2000 characters.                      |
| `top_k`          | integer                            | Optional    | Maximum chunks returned: default 5; allowed range 1–20.                         |
| `query_strategy` | `semantic`, `keyword`, or `hybrid` | Optional    | Default `semantic`. `keyword` matches terms; `hybrid` combines both approaches. |
| `expand`         | array of strings                   | Optional    | Up to 20 returned chunk IDs whose full text to include.                         |

## Example

These are MCP tool arguments, not an HTTP request body. Replace bracketed IDs with values returned from your account.

```json
{
  "kb_id": "<knowledge-base-id>",
  "query": "What is the approval process?",
  "top_k": 5
}
```

## Result

Abbreviated result example; unshown fields are omitted for clarity.

```json
{
  "chunks": [
    {
      "chunk_id": "<chunk-id>",
      "doc_name": "<document-name>",
      "text_preview": "<matching-passage-preview>",
      "text": null,
      "text_truncated": false
    }
  ],
  "expanded_chunk_ids": []
}
```

## Behavior

Results contain previews and document/locator metadata, not a synthesized answer.

Repeat the query with expand set to selected chunk IDs (up to 20) to obtain full text where available; check text\_truncated before relying on completeness.

## Troubleshooting

If an answer needs more evidence, repeat the same query with selected chunk IDs in `expand`. Check `text_truncated`; an empty or partial result does not establish that the source contains no relevant information.

## Related resources

[Connections, knowledge and discovery](https://docs.stackai.com/stackai-mcp/tool-reference/connections-knowledge-and-discovery.md)

[Connection, permissions, pagination, and recovery](https://docs.stackai.com/stackai-mcp/best-practices-and-troubleshooting.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/stackai-mcp/tool-reference/connections-knowledge-and-discovery/kb-search.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
