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

# Store memory in OpenViking

The `openviking` long-term-memory backend submits session messages to
OpenViking, which extracts and stores entities, events, and preferences for each
user. VeADK keeps retrieval scoped to the current user and returns matching
memory to the agent.

## Prerequisites

Prepare a reachable OpenViking service and a service-owner API key. VeADK 1.0.3
includes `openviking-sdk>=0.1.3` in its base dependencies.

```bash lines theme={null}
export DATABASE_OPENVIKING_URL="https://openviking.example.com"
export DATABASE_OPENVIKING_API_KEY="${OPENVIKING_API_KEY}"
```

## Example

```python lines theme={null}
import asyncio

from veadk import Agent, Runner
from veadk.memory.long_term_memory import LongTermMemory

memory = LongTermMemory(
    backend="openviking",
    app_name="support_assistant",
    top_k=5,
)

agent = Agent(
    name="support_assistant",
    instruction="Search the user's long-term memory before answering.",
    long_term_memory=memory,
    auto_save_session=True,
)

runner = Runner(
    agent=agent,
    app_name="support_assistant",
    user_id="user_123",
)

print(asyncio.run(runner.run("Remember that I prefer concise answers.")))
```

When a session is saved, the OpenViking backend receives text messages from both
the user and the agent and forms long-term memory after committing the session.
Retrieval is fixed to the current user's
`viking://user/peers/{peer_id}/memories` scope, keeping memories isolated
between users.

## Parameters

See the [long-term memory overview](/productions/veadk/archives/1.0.3/en/components/memory) for
shared `LongTermMemory` parameters. Use `backend_config` to override these
OpenViking backend parameters:

| Parameter | Environment variable | Type | Default | Description |
| :- | :- | :- | :- | :- |
| `index` | None | `str` | `app_name` or `default_app` | Application index that owns the memory. |
| `openviking_config` | `DATABASE_OPENVIKING_*` | `OpenVikingConfig` | Built from environment | Connection configuration containing `url` and `api_key`. |
| `url` | `DATABASE_OPENVIKING_URL` | `str` | `""` | OpenViking service URL. Required. An explicit value overrides `openviking_config.url`. |
| `api_key` | `DATABASE_OPENVIKING_API_KEY` | `str` | `""` | OpenViking service-owner API key. Required. An explicit value overrides `openviking_config.api_key`. |
| `peer_id_resolver` | None | `Callable[[str, str], str] \| None` | Use `user_id` | Function that maps `app_name` and `user_id` to an OpenViking peer identifier. |
| `timeout` | None | `float` | `30` | OpenViking SDK request timeout in seconds. |

By default, `peer_id` equals `Runner.user_id`. A custom function must return a
non-empty identifier containing only letters, digits, periods, underscores,
`@`, and hyphens; `.` and `..` are not allowed.

```python lines theme={null}
from veadk.memory.long_term_memory import LongTermMemory

memory = LongTermMemory(
    backend="openviking",
    app_name="support_assistant",
    backend_config={
        "peer_id_resolver": lambda app_name, user_id: f"{app_name}-{user_id}",
        "timeout": 60,
    },
)
```

<Warning>
  `peer_id_resolver` defines the user-isolation boundary in OpenViking. Changing
  the mapping after deployment leaves existing memories under their old peer
  paths, so later searches may no longer find them.
</Warning>
