# Search files

URL: https://docs.hanzo.ai/docs/openapi/knowledge/post-knowledge-files-search

> Answers the passages of the caller's org files that match a query, each citing its file › section › paragraph: the search behind Drive's box, and the first step an agent takes across a workspace.

`POST /v1/knowledge/files/search`

> [Knowledge →](https://docs.hanzo.ai/docs/openapi/knowledge) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                  |
| ------------- | ------------------------------------------------ |
| **Address**   | `https://api.hanzo.ai/v1/knowledge/files/search` |
| **Method**    | `POST`                                           |
| **Operation** | `post_knowledge_files_search`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`           |

Answers the passages of the caller's org files that match a query,
each citing its file › section › paragraph: the search behind Drive's box,
and the first step an agent takes across a workspace. Name file ids to search
only those files; name none to search them all. A semantic leg compares the
query with every embedded passage and a full-text leg finds the passages
holding its words; the two are fused, so a passage both found comes first.

## Request

4 fields, body `application/json` (required).

| Field     | In   | Type            | Required | Description                                                            |
| --------- | ---- | --------------- | -------- | ---------------------------------------------------------------------- |
| `files`   | body | string\[]       | —        | Files restricts the search to these file ids.                          |
| `limit`   | body | integer (int64) | —        | Limit bounds the passages returned.                                    |
| `project` | body | string          | —        | Project restricts the search to files indexed under one project scope. |
| `query`   | body | string          | —        | Query is the question or phrase.                                       |

## Response

| Status    | Body                    | Meaning |
| --------- | ----------------------- | ------- |
| `200`     | knowledge.fileSearchOut | ok      |
| `default` | problem-details         | refused |

`200` body — 18 fields.

| Field                      | In   | Type                      | Always | Description                                                                                                                                                 |
| -------------------------- | ---- | ------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `degraded`                 | body | boolean                   | —      | Degraded is true when a leg failed — the query could not be embedded, or the full-text index could not be read — and Passages are what the other leg found. |
| `passages`                 | body | knowledge.citedPassage\[] | —      | Passages are the matching passages, best first, at most Limit.                                                                                              |
| `passages[].cite`          | body | string                    | —      | Cite is how an answer cites it: file › section path › ¶part.                                                                                                |
| `passages[].file`          | body | knowledge.fileBrief       | —      |                                                                                                                                                             |
| `passages[].file.bucket`   | body | string                    | —      | Bucket and Key are where its bytes are: GET /v1/s3/buckets/{bucket}/objects/{key} answers a signed download URL.                                            |
| `passages[].file.id`       | body | string                    | —      | ID is the file's id.                                                                                                                                        |
| `passages[].file.key`      | body | string                    | —      | Key is the object's key in Bucket.                                                                                                                          |
| `passages[].file.name`     | body | string                    | —      | Name is the file's name.                                                                                                                                    |
| `passages[].file.type`     | body | string                    | —      | Type is the file's media type.                                                                                                                              |
| `passages[].part`          | body | integer (int64)           | —      | Part is the passage's place in its section, from 1.                                                                                                         |
| `passages[].score`         | body | number (double)           | —      | Score is the fused rank score, comparable within one response only.                                                                                         |
| `passages[].section`       | body | knowledge.sectionBrief    | —      |                                                                                                                                                             |
| `passages[].section.id`    | body | integer (int64)           | —      | ID is the section's number in its file's table of contents; 0 is the document itself.                                                                       |
| `passages[].section.path`  | body | string                    | —      | Path is the section's place in its document: the titles from the document's own down to it, joined by " › ".                                                |
| `passages[].section.title` | body | string                    | —      | Title is the section's heading.                                                                                                                             |
| `passages[].text`          | body | string                    | —      | Text is the passage: a span of its section of about 2000 bytes, never crossing into another section.                                                        |
| `passages[].via`           | body | string                    | —      | Via is how retrieval reached it: search (it matched), toc (it is in a section the table of contents pointed at) or graph (a linked section).                |
| `passages[].why`           | body | string                    | —      | Why says, for a passage reached through the graph, which edge led there.                                                                                    |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

`hanzo` has no subcommand for this operation — the CLI serves only what cloud's live route table confirms. Use HTTP or an SDK.

**SDK**

**.ts**

```ts
import { Configuration, KnowledgeApi } from 'hanzoai';

const api = new KnowledgeApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postKnowledgeFilesSearch({ files: ["<files>"], limit: 0 });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import KnowledgeApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = KnowledgeApi(client).post_knowledge_files_search(files=["<files>"], limit=0)
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.KnowledgeAPI.PostKnowledgeFilesSearch(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, knowledge_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = knowledge_api::post_knowledge_files_search(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.KnowledgeApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new KnowledgeApi(client).postKnowledgeFilesSearch();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/knowledge/files/search \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "files": [
         "<files>"
       ],
       "limit": 0
     }'
```

**MCP**

MCP reaches **knowledge** through the `knowledge` tool, which names its 9 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_knowledge_connectors"
         }
       }
     }'
```

---

[Knowledge API](https://docs.hanzo.ai/docs/openapi/knowledge) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
