# ricerca

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

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

Trova documenti per significat e non per parole. La unica azione che costa un credit — e la única che nega piuttosto que replica mal.

Status: any storage · 1 credit · refunded on refusal

I documenti caricati in un stoccaggio sono tagliu e indexats quando arrivano, da noi. Quindi la stessa chiamata risponde per una base di documenti, una relazion e un cubo pare — il provider non ha nulla a che fare con esso.

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `query` | string | obrigatório | Cere, con paroles tuas. |
| `limit` | integer |  | Quanti passaggis da restituir. |

```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 |  | Il passèr in se — un fragmento di un document, non l'archivi intero. |
| `results[].score` | number |  | Quan angus is. Compare in una risposta, non in due. |
| `results[].source` | object |  | `{ id, name, index }` — qual documenta, e qual fragmenta di esso. |
| `scanned` | integer |  | Quants fragmenti si considerava. |
| `creditsUsed` | integer |  | `1`. Legêlo piuttosto que presupponendo — è ciò che conta il budget del agente. |

## Il credito, e quando torna {#cost}

Preso prima del call e restituit al **qualquea**regime, compreso un id de stoccaggio incognoscido — che non vectorised nulla e non deve costar nulla.

## Resiste a non rispondere mal {#refusal}

> **embedding_unavailable è un rejet intenzional**
>
> Senza un servizio per convertir il testo in vectors, non c'è un replie que non è semantic. Rispondendo da esso daria puntuari plausibili che non significa nada — piu mal di non risponde, perché nulla dice di di loro di disfidare.

```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;
}
```

## Solo lo indexat è a possíbil {#indexed}

- I documenti sono indexati quando sono [salvât](/pt/sdk/ref/files/save), e solo la categoria `document` è.
- L'indexare non è atteso, quindi qualcosa salvato un momento fa potrebbe non essere là ancora.
- [update()](/pt/sdk/ref/files/update) non reindexa: il vecchio testo resta a localizar. Elimina e salva di nuovo quando ciò importa.

- [file.save()](/pt/sdk/ref/files/save): Ce qui est indexé, et quand.
- [run()](/pt/sdk/ref/connected-storage/run): Tutes les actions, les garde-fous et ce que chaque coute.

```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
```
