> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nonhumans.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Memory: Vector Storage & Persistent Knowledge

> Give your Nonhumans agent long-term memory with vector search and file storage that persists across sessions and restarts.

Your agent remembers nothing by default — unless you give it memory. The memory primitive provides two complementary storage layers: a vector store for semantic recall, and a file drive for raw assets. Everything persists across agent restarts, so context your agent builds today is still available the next time it runs.

## Storage Types

<CardGroup cols={2}>
  <Card title="Vector Memory" icon="brain">
    Embed and retrieve experiences, notes, and knowledge using semantic similarity search.
  </Card>

  <Card title="File Storage" icon="folder-open">
    Upload and retrieve raw files — PDFs, images, CSVs, audio — attached to your agent.
  </Card>
</CardGroup>

***

## Vector Memory

Vector memory lets your agent store any text as an embedding and later retrieve the most semantically relevant entries. Use it to remember user preferences, store summaries of past conversations, or build a private knowledge base your agent can query at runtime.

### Store a memory

<CodeGroup>
  ```typescript TypeScript theme={null}
  await agent.memory.store({
    content: 'User Alice prefers morning meetings between 9am and 11am.',
    metadata: { userId: 'alice', category: 'preferences' },
  });
  ```

  ```python Python theme={null}
  await agent.memory.store(
      content="User Alice prefers morning meetings between 9am and 11am.",
      metadata={"userId": "alice", "category": "preferences"},
  )
  ```
</CodeGroup>

### Search memories

<CodeGroup>
  ```typescript TypeScript theme={null}
  const results = await agent.memory.search({
    query: 'Alice preferences',
    limit: 5,
  });

  results.forEach((entry) => {
    console.log(entry.content, entry.score);
  });
  ```

  ```python Python theme={null}
  results = await agent.memory.search(
      query="Alice preferences",
      limit=5,
  )

  for entry in results:
      print(entry.content, entry.score)
  ```
</CodeGroup>

<Tip>
  Chunk large documents into 300–500 token segments before storing them. Smaller, focused chunks produce higher-quality similarity scores and more precise retrieval.
</Tip>

***

## File Storage

Use the file drive to attach raw assets to your agent — reports, images, data exports, or any binary content. Files are stored durably and can be retrieved at any time.

### Upload a file

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { readFileSync } from 'fs';

  const content = readFileSync('./report.pdf');

  const file = await agent.memory.files.upload({
    name: 'report.pdf',
    content,
  });

  console.log('Uploaded:', file.id);
  ```

  ```python Python theme={null}
  with open("report.pdf", "rb") as f:
      content = f.read()

  file = await agent.memory.files.upload(
      name="report.pdf",
      content=content,
  )

  print("Uploaded:", file.id)
  ```
</CodeGroup>

***

## Memory Persistence

Both storage layers survive agent restarts automatically — you don't need to configure anything. Vector embeddings and uploaded files are durable by default and tied to your agent's identity.

<Info>
  Memory is scoped per agent handle. Two agents with different handles never share a memory namespace, even within the same project.
</Info>

***

## Common Use Cases

<Steps>
  <Step title="Remember user preferences">
    Store user-specific context (timezone, communication style, project priorities) as vector memories and retrieve them at the start of each session.
  </Step>

  <Step title="RAG over documents">
    Upload PDFs or text files to file storage, chunk and embed their contents into vector memory, and run semantic search at inference time to ground your agent's responses.
  </Step>

  <Step title="Build a knowledge base">
    Continuously store summaries, notes, and facts as your agent operates. Over time, your agent accumulates a rich, queryable knowledge base scoped entirely to its own identity.
  </Step>
</Steps>
