LiyaEngine Docs

Access Control on Retrieval

Restrict documents to groups, send each request the end user's groups, and have retrieval honour them on every path before ranking.

Dashboard

Some documents are not for everyone: salary bands, board papers, a region's contracts. Access control on retrieval lets you label a document with the groups that may see it and tell each request which groups the end user belongs to. Retrieval then returns unrestricted documents plus the restricted ones the user's groups share, and nothing else.

LiyaEngine does not authenticate your end users and does not know who is in which group. Your application does, and passes the result with each request.


How it works

A group is a string you choose (hr, finance, region:emea, plan:gold). A document is either:

  • unrestricted: visible to any caller. This is the default, and every document you uploaded before turning this on.
  • restricted to one or more groups: visible to a caller who holds at least one of them.

Access control is switched on per domain. On a domain where it is off, access is validated and ignored, and nothing changes.

Domain settingRequest sendsCaller sees
off (default)anythingEverything the domain retrieves today
enforceaccess.groups: ["hr"]Unrestricted documents plus those restricted to hr
enforceaccess.groups: [] or no accessUnrestricted documents only

On an enforcing domain a request that forgets access fails safe: it sees less, never more. That also holds for workflow steps, scheduled runs and anything else that reaches the domain without a user in hand.


Set it up

1. Label documents

Pass accessGroups when you upload or push a document. Leave it out, or send null, for an unrestricted document. An empty list is rejected.

curl -X POST https://api.liyaengine.ai/v1/documents \
  -H "Authorization: Bearer $LIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "fileBase64": "...", "fileName": "pay-bands.pdf", "accessGroups": ["hr"] }'

Change a label later without re-embedding anything:

curl -X PATCH https://api.liyaengine.ai/v1/documents/doc_123 \
  -H "Authorization: Bearer $LIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "accessGroups": ["hr", "finance"] }'

{ "accessGroups": null } makes the document unrestricted. Every change is recorded in the audit log as document.access_update, with the labels before and after.

Re-pushing a document keeps its label unless you send a new one, so a re-sync never makes a restricted document public.

2. Turn it on for a domain

curl -X PATCH https://api.liyaengine.ai/v1/domains/hr-assistant \
  -H "Authorization: Bearer $LIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "retrievalAccess": "enforce" }'

3. Send the end user's groups

access is a top-level field. It is never part of input, so nothing the end user types can set it, and it is never shown to the model.

curl -X POST https://api.liyaengine.ai/v1/run \
  -H "Authorization: Bearer $LIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "hr-assistant",
    "intent": "answer",
    "input": { "user_id": "emp_42", "message": "What is the L5 band?" },
    "access": { "groups": ["hr"] }
  }'

Limits: up to 50 groups per request, each a non-empty string of at most 64 characters. Anything malformed is rejected with 400 INVALID_ACCESS_CONTEXT. It is never trimmed or widened.


Where it applies

DoorTakes accessNotes
POST /v1/run, /v1/run/streamyes
POST /v1/{domain}/{intent} and /streamyes
POST /v1/domains/{key}/queryyesApplied when the domain enforces
POST /v1/agents/{agentKey}/run and /streamyesCarried into the agent's document search and intent tools
POST /v1/collections/queryyesNo domain here, so it applies exactly when you send access. Omitted means no restriction (you are the trusted caller)
Workflow steps and scheduled runsnot yetThey see unrestricted documents only on an enforcing domain

Browser widgets

A page visitor must not choose their own groups. An embed token carries its groups, set when the token is created (access_groups), and any access a browser sends is discarded. Use a separate token per audience, for example one for the public site and one for an internal portal.


What is covered

Every retrieval path applies the same rule before ranking: vector search, keyword search, the fetch of a chunk's parent document, and the in-memory fallback. Cached answers are keyed by audience, so one caller never receives another's cached result. The auto-generated knowledge base overview is built only from unrestricted documents, because every caller can retrieve it.

The check is made in the database query, not on the results afterwards, so a restricted chunk is never ranked, never cited, and never reaches the model.

What is not covered yet

  • Conversation memory. Summaries of earlier sessions are embedded and retrieved per user. A summary written while a caller held a restricted group can contain restricted text. On domains that handle restricted content, use minimal trace capture and disable session memory.
  • Connector permissions. Documents synced from a connector (Google Drive, SharePoint) are not labelled from the source system's permissions. Label them yourself, or set a default on the connector.
  • Dashboard controls. Labels are set through the API for now.
  • Group membership. Groups come from your system on each request. Signed access contexts, which let an identity provider vouch for them, are planned.

Common mistakes

  • Labelling a document but not switching the domain on. Nothing is filtered until retrievalAccess is enforce.
  • Sending access from the browser. It must come from your server, or from an embed token.
  • Expecting an empty group list to mean "everything". It means unrestricted documents only.
  • A typo in a group name. finanace quietly matches nobody. Test with a request that should see the document.

On this page