# How Docklee works (/docs/docklee/how-docklee-works)
Every piece of data takes one of two paths. Knowledge goes into a container and is read through an engine. Memory goes into a memory space and is read from that space.

Read this page before you design your writes, because the destination you declare decides which path the data takes.

<FlowDiagram
  caption="The knowledge path. Data lands in a container, an engine reads the sources linked to it, and Lynk returns the result."
  stages={[
    { title: 'Source or Dock', detail: 'A connected source, or a Dock write that declares a container.' },
    { title: 'Container', detail: 'Chunks, extracts, and embeds the content, or builds OKF concepts.' },
    { title: 'Engine', detail: 'Reads only the sources linked to it.' },
    { title: 'Lynk', detail: 'query returns an answer. retrieve returns the chunks.' },
  ]}
/>

## Without and with Docklee [#without-and-with-docklee]

| Without Docklee | With Docklee |
| --- | --- |
| You build chunking, embeddings, and a vector store for each project. | A container does the processing, and engines share sources across projects. |
| A new fact sits next to the old one it contradicts. | The newer fact replaces the older one, and confidence is updated. |
| Per-user data relies on filters in your own code. | An `end_user` isolates and separately encrypts each user's memories. |
| Every service holds its own credentials to every data source. | Sources connect once, and credentials never leave the source. |

## The knowledge path [#the-knowledge-path]

1. **Data arrives.** You connect documents and apps in **Sources**, or your code writes with `Dock` and declares a container.
2. **A container processes it.** A vector container chunks the content, extracts its structure, and embeds it at your chosen dimension. An OKF container builds concepts and the links between them. See [Containers](/docs/docklee/containers).
3. **An engine reads linked sources.** An engine has no data of its own. It reads from the sources you link to it, and nothing else. See [Engines](/docs/docklee/engines).
4. **Lynk returns the result.** `lynk.query` returns an answer with citations. `lynk.retrieve` returns the ranked chunks.

## The memory path [#the-memory-path]

1. **Dock writes to a memory space.** Your code calls `capture` on a `Dock` that has a `memory_space_id`, with an `end_user` when the memory belongs to one person.
2. **Docklee organizes the memory.** It classifies the memory, extracts the people and things it mentions, links it to related memories, and settles conflicts with older facts. See [How memory works](/docs/memory/how-memory-works).
3. **Lynk recalls it.** `lynk.recall` returns the most relevant memories, each with a type and a confidence score.

## Where a write goes [#where-a-write-goes]

A write never names an engine. It declares a destination, and Docklee routes each event by what the request declares.

| The request declares | Where events go |
| --- | --- |
| `container` only | Every event goes to the container. |
| `memory_space_id` only | Every event goes to the memory space. |
| Both | `document` and `knowledge` events go to the container. `conversation`, `event`, `preference`, and `entity` events go to the memory space. |
| Neither | The request fails with `422` and the error `missing_destination`. |

One `Dock` that declares both splits the events for you:

<CodeTabs items={['Python', 'TypeScript']}>
  <Tab value="Python">
    ```python
    from docklee import Dock

    dock = Dock(container="vector", dimension=1024, memory_space_id="your-memory-space-id")

    dock.capture("Our SLA covers 99.9% uptime.", type="knowledge")
    dock.capture("Maya asked about the SLA.", type="conversation", end_user="user_8f2c")
    dock.flush_sync()
    ```
  </Tab>
  <Tab value="TypeScript">
    ```ts
    import { Dock } from 'docklee';

    const dock = new Dock({
      container: 'vector',
      dimension: 1024,
      memorySpaceId: 'your-memory-space-id',
    });

    dock.capture('Our SLA covers 99.9% uptime.', { type: 'knowledge' });
    dock.capture('Maya asked about the SLA.', { type: 'conversation', endUser: 'user_8f2c' });
    await dock.close();
    ```
  </Tab>
</CodeTabs>

The first event goes to the vector container. The second goes to the memory space, for that end user only.

## Where data lives [#where-data-lives]

| Data | Lives in | Readable by |
| --- | --- | --- |
| A connected source | A container, chosen when you add the source | Every engine the source is linked to |
| A `Dock` knowledge write | The container's API/SDK Feed source | Every engine the feed is linked to |
| A `Dock` memory write | The memory space | `lynk.recall` on that space |
| An end user's memory | The memory space, encrypted for that end user | `lynk.recall` with the same `end_user` |

## Build with this flow [#build-with-this-flow]

- Declare a container for knowledge and a memory space for memory. Don't send knowledge to a memory space.
- Link a new API/SDK Feed to an engine before you expect answers from it.
- Keep one vector dimension per engine.
- Pass `end_user` on every write and recall in a per-user space.
- Flush or close `Dock` before your process exits.

## Next steps [#next-steps]

You've seen both paths. Learn the knowledge side first, starting with where content comes from.

<Cards>
  <Card title="Sources" href="/docs/docklee/sources" description="Connect content once for every engine." />
  <Card title="Containers" href="/docs/docklee/containers" description="Vector or OKF, and how to declare one." />
  <Card title="Memory spaces" href="/docs/docklee/memory-spaces" description="Where memories live and who can read them." />
</Cards>
