# LLMSlim + Neo4j

> Temporal agent memory where newer facts supersede old ones, with an audit trail.

Neo4jContextStore keeps tenant-scoped memories in Neo4j. When a fact changes, supersede() links the new memory to the one it replaces, so recall() returns only what is valid now while the history stays auditable. Recalled memories are untrusted context items for the planner.

Category: Backend Services

## Install

```bash
pip install 'llmslim[neo4j]'
```

## How it fits

- Open a tenant-scoped store from NEO4J_URI, NEO4J_USERNAME and NEO4J_PASSWORD.
- Remember facts explicitly, one subject at a time.
- When a fact changes, supersede the old memory with a reason.
- Recall the memories valid now and plan them with the rest of the context.

## Example

```python
from llmslim.integrations.neo4j import Neo4jContextStore

store = Neo4jContextStore.from_env(tenant_id="tenant-42")
old = await store.remember("customer.card_address", "Ship cards to Indiranagar, Bengaluru.")
await store.supersede(old.memory_id, "Ship cards to Koregaon Park, Pune.", reason="customer moved")
items = await store.recall(subject="customer.card_address")
# Only the current address comes back; pass items to plan_context(memories=items).
```

## Deployment

Keep Neo4j credentials server-side, give each customer its own tenant_id, and store only facts users have agreed to keep. Use the LLMSLIM_NEO4J_* limits to cap reads and writes.

## Tips

- Supersede facts instead of deleting them, so answers can be audited later.
- Recall by subject when you know it; it is cheaper and more precise than a text query.
- Treat recalled memories as untrusted context, never as instructions.

## FAQ

### Does LLMSlim write to Neo4j automatically?

No. Memories are written only when your code calls remember() or supersede().

### What happens to a superseded fact?

It stops being recalled as current, and the SUPERSEDES link with its reason stays in the graph for auditing.

## Troubleshooting

- **recall() returns an old fact:** Record the change with supersede() rather than remember(); two memories on one subject are reported as conflicting until one supersedes the other.

Canonical page: https://www.llmslim.app/integrations/neo4j
