# save()

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/memory/save/
Language: pt

`api.memory.save(note) → Promise<Memory>`

Crea una nota, o la sostituisce con il memònimo nome. Il nome è l'identitè — non c'è una aggiornament separata.

Status: POST /api/ai/memories · free · upsert by name

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string | obrigatório | Mincescase, cifres e guinxes, fino a 64. Cualquier altra cosa è convertita; ciò che non può ser nega. |
| `content` | string | obrigatório | La nota stessa, fino a 4 000 caracteres. |
| `description` | string |  | Una fila, fino a 200. It's ove lo agent vee quando elige — ved [inferior](#description). |
| `type` | string |  | `preference` · `project` · `fact` · `correction` · `other`. Valori sconosciutis diventa `other`. |
| `source` | string |  | `user` or `agent`. Qualsiasi cosa non è `user` diventa `agent`. |
| `sessionId` | string |  | La sessione in cui fu imparat, quando fuse una. |

## Il nome è l'identitè {#name}

Salvare con un nome che già esiste sostituisce que nota. Questo è l'intero meccanismo di update, e è per questo che vale la pena scegliere bene: è la cosa che dovrès aderire poi.

```javascript
await api.memory.save({ name: "tone-of-voice", content: "Short answers.", source: "user" });
await api.memory.save({ name: "tone-of-voice", content: "Short answers, in French.", source: "user" });
// One note. The second content replaced the first.
```

| Tu passa | - Conservato como |
| --- | --- |
| Tonu de voce | Tono de voce |
| user_preferences | Preferenze d'usuari |
| - Deploiment!! | d-ploiement |
| !!! | Refusat — invalid_name |

> **I nomi sono convertiti, non validati**
>
> Due nomi diversi possono convergere su un, e la seconda salva poi sostituisce la prima nota senza dicir. Pitch simple, nomes stabile, e legga il nome che torna quando lo costruite da input d'usuario.

## Scrive la descriptura per l'agente {#description}

Il contenuto è aperto solo quando una nota pare pertinente, e la relevance è giudicata sulla description. Quindi la description deve dicire *quando vale la pena lere*, non quello che contiene.

| Descriptio deficiente | -Meglior |
| --- | --- |
| «Preferenze» | «Come questo utentu vore ser scrit a» |
| « Base de données » | «Qual database a usar, e qual mai a tocar» |
| « Notes sul progetto » | «Le regole di implementare per questo progetto, incluso ciò che è proibit» |

## Retorno {#returns}

```javascript
const note = await api.memory.save({
  name: "deploy-rules",
  description: "The deploy rules for this project, including what is forbidden",
  content: "No deploys on Friday. Staging first, always. Migrations run separately.",
  type: "project",
  source: "user",
});

note.name;        // "deploy-rules"
note.type;        // "project"
note.updatedAt;
```

La nota come memorized — dopo che il nome è convertit e il testo rimàstot a i suoi limiti. Legîlo di nuovo, invece di supponendo che quello che tu enviaste è quello che era conservat.

## Erros {#errors}

| Código | Status | Quando |
| --- | --- | --- |
| invalid_name | 400 | Nada utilizable era lasciato dopo la conversione. |
| content_required | 400 | Il contenit era vazio o solo spazio bianco. |
| too_many_memories | 400 | 200 notes ya, e questo sarebbe un nuovo. |

`too_many_memories` solo aplica a una nota *nov*: sostituire una existente funciona al cap, perché non aggiunge nada. Isso è deliberat — esser pieno non deve impedir-te de corregir algo errat.

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

try {
  await api.memory.save({ name, content, description, type, source: "user" });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "too_many_memories") {
    // Let the user choose what goes. Do not evict on their behalf.
    return { needsPruning: await api.memory.list() };
  }
  throw err;
}
```

## fonte, e por què vale la pena impostare {#source}

Qualsiasi cosa non è `"user"` è registrat come `agent`. Setuant-lo onestamente è ciò che lascia una interface separate « me has detto » de « me ha reso l'officina » — e la seconda merita di essere più facile da questionare.

- [list()](/pt/sdk/ref/memory/list): Legî-li tots, contenuto incluso.
- [delete()](/pt/sdk/ref/memory/delete): Retirando uno.

```python
api.memory.save(name="tone-of-voice", content="Short answers.", source="user")
api.memory.save(name="tone-of-voice", content="Short answers, in French.", source="user")
# One note. The second content replaced the first.
```

```python
note = api.memory.save(
    name="deploy-rules",
    description="The deploy rules for this project, including what is forbidden",
    content="No deploys on Friday. Staging first, always. Migrations run separately.",
    type="project",
    source="user",
)

note["name"]        # "deploy-rules"
note["type"]        # "project"
note["updatedAt"]
```

```python
from iagenify import IaGenifyError

try:
    api.memory.save(name=name, content=content, description=description, type=kind, source="user")
except IaGenifyError as error:
    if error.code != "too_many_memories":
        raise
    # Let the user choose what goes. Do not evict on their behalf.
    needs_pruning = api.memory.list()
```
