---
title: "Copy access rights into the index and · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/retrieval/retrieval-permissions
updated: 2026-10-20
licence: "All rights reserved"
---

# Copy access rights into the index and check them again

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Retrieval](https://agentwranglers.se/playbook/ai-features/retrieval)
- Rule: Store each document's access rights with its chunks, filter every search by them, and re-check the source's rights before a chunk reaches the model.
- How: Copy the owner, team or group list from the source onto each chunk. Filter the search query by the user's groups, as [scope what the model can look up](https://agentwranglers.se/playbook/adversarial-testing/ai-agents-and-models/scoped-retrieval) requires. Rights change faster than indexes, so check the remaining hits against the source system at answer time. Update stored rights on every permission change event.
- Check: Give a test user access to a document, ask about it, then remove the access. The next question returns nothing from that document, even before the index updates.

Example:

```ts
const candidates = await index.search(question, { filter: { groups: { anyOf: user.groups } }, limit: 20 });
const allowed = await documents.filterReadable(candidates.map(c => c.documentId), user);
const chunks = candidates.filter(c => allowed.has(c.documentId));
```

```python
candidates = index.search(question, filter={"groups": {"any_of": user.groups}}, limit=20)
allowed = documents.filter_readable({c.document_id for c in candidates}, user)
chunks = [c for c in candidates if c.document_id in allowed]
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/retrieval/retrieval-permissions`.

- Previous: [Keep the index as fresh as its sources](https://agentwranglers.se/playbook/ai-features/retrieval/index-freshness)
- [Retrieval](https://agentwranglers.se/playbook/ai-features/retrieval)
