# search

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run/search/
Language: en

`storage.run({ action: "search", query, limit })`

Finds documents by meaning rather than by words. The only action that costs a credit — and the only one that refuses rather than answering badly.

Status: any storage · 1 credit · refunded on refusal

Documents uploaded to a storage are cut up and indexed when they arrive, on our side. So the same call answers for a document database, a relational one and a bucket alike — the provider has nothing to do with it.

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `query` | string | required | What you are looking for, in your own words. |
| `limit` | integer |  | How many passages to return. |

```javascript
await storage.run({ action: "search", query: "what is our refund window", limit: 5 });
// {
//   results: [{ text: "…", score: 0.82, source: { id, name, index } }],
//   scanned: 1240,
//   model: "…",
//   creditsUsed: 1
// }
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `results[].text` | string |  | The passage itself — a fragment of a document, not the whole file. |
| `results[].score` | number |  | How close it is. Compare within one answer, not across two. |
| `results[].source` | object |  | `{ id, name, index }` — which document, and which fragment of it. |
| `scanned` | integer |  | How many fragments were considered. |
| `creditsUsed` | integer |  | `1`. Read it rather than assuming — it is what an agent's budget counts. |

## The credit, and when it comes back {#cost}

Taken before the call and refunded on **any** refusal, including an unknown storage id — which vectorised nothing and should cost nothing.

## It refuses rather than answering badly {#refusal}

> **embedding_unavailable is a refusal on purpose**
>
> Without a service to turn text into vectors, there is a fallback that is not semantic. Answering from it would return plausible scores that mean nothing — worse than no answer, because nothing tells you to distrust them.

```javascript
import { IaGenifyError } from "iagenify";

try {
  const found = await storage.run({ action: "search", query, limit: 5 });
  return found.results;
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "embedding_unavailable") {
    return null;   // say « search is unavailable », never « nothing found »
  }
  throw err;
}
```

## Only what was indexed is findable {#indexed}

- Documents are indexed when they are [saved](/sdk/ref/files/save), and only the `document` category is.
- Indexing is not awaited, so something saved a moment ago may not be there yet.
- [update()](/sdk/ref/files/update) does not re-index: the old text stays findable. Delete and save again when that matters.

- [file.save()](/sdk/ref/files/save): Ce qui est indexé, et quand.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(action="search", query="what is our refund window", limit=5)
# {
#   "results": [{"text": "…", "score": 0.82, "source": {"id", "name", "index"}}],
#   "scanned": 1240,
#   "model": "…",
#   "creditsUsed": 1
# }
```

```python
from iagenify import IaGenifyError

def search(storage, query):
    try:
        return storage.run(action="search", query=query, limit=5)["results"]
    except IaGenifyError as error:
        if error.code == "embedding_unavailable":
            return None   # say « search is unavailable », never « nothing found »
        raise
```
