Apply explicit user preferences only after access checks, with clear consent, cache isolation and deletion behavior.
Personalized retrieval: preferences never grant access
Separate preference from permission
Personalized retrieval can rank eligible material using a reader's chosen topics, reading level or current project. That preference cannot make an unauthorized document eligible. First apply tenant, group and document lifecycle filters from the active authenticated session; only then adjust the rank of remaining candidates. A model's guess about a user's role is not an access token. Corpus permissions define the hard boundary; personalization operates inside it.
Collect only useful state
Store explicit preference fields with their purpose, consent state and expiration. A recent query may be useful for one follow-up without becoming permanent memory. Do not silently turn private questions or retrieved passages into a lasting user profile. Let the user inspect, correct or clear preference state, and make the default search path useful with no personalization at all. Conversation rewriting may carry a short-lived entity or constraint, but it should not import unrelated history into a new search.
Isolate caches and embeddings
A result cache keyed only by query text can leak personalized ranks or even snippets across accounts. Include identity scope, authorization version, preference version and corpus generation where those affect output, or decline to cache the result. User-specific embeddings create another derived-data copy that must be covered by retention and deletion rules. If consent is withdrawn, stop using the feature immediately and invalidate cached outputs. Permission-aware caches provide the same discipline for nonpersonalized conversation turns.
Keep explanations specific
When personalization changes order, show a concise reason such as 'your selected Java topic' rather than implying the top document is more authoritative. User preferences can help choose among equally eligible tutorials, but they should not override exact identifiers, current policy revision or evidence support. A strong preference for one source can create a narrow view that misses contradictory material, so diversify when the task calls for comparison. Evidence diversity helps prevent a preference filter from hiding necessary counterevidence.
Test consent transitions
Build cases for opt-in, opt-out, changed group membership, preference deletion, shared devices and two users with the same query. Verify that unauthorized documents never enter candidates, personalized ranks disappear after opt-out and no cached response crosses an identity boundary. Measure whether personalization improves task completion or merely raises clicks on familiar material. Review long-tail users separately; sparse history can make the model's inferred interests unstable.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class ReaderContext:
tenant: str
groups: frozenset[str]
consent: bool
preferred_topic: str | None
@dataclass(frozen=True)
class SearchDocument:
document_id: str
tenant: str
required_group: str
topic: str
relevance: float
def ranked_for_reader(reader: ReaderContext,
documents: list[SearchDocument]) -> list[str]:
allowed = [document for document in documents
if document.tenant == reader.tenant
and document.required_group in reader.groups]
return [document.document_id for document in sorted(
allowed,
key=lambda document: (-(document.relevance + (
.1 if reader.consent and document.topic == reader.preferred_topic else 0)),
document.document_id))]
reader = ReaderContext("north", frozenset({"engineers"}), True, "maintenance")
documents = [SearchDocument("pump-p47", "north", "engineers", "maintenance", .72),
SearchDocument("salary-plan", "north", "finance", "maintenance", .99),
SearchDocument("pump-p48", "south", "engineers", "maintenance", .97)]
assert ranked_for_reader(reader, documents) == ["pump-p47"]
assert ranked_for_reader(ReaderContext("north", reader.groups, False, None), documents) == ["pump-p47"]Performance and operating cost
Filtering and sorting N candidates costs O(N log N) time and O(N) working space in this small implementation. An index should apply tenant and group constraints before ranking to avoid scanning ineligible documents. Per-user state and cache keys increase storage cardinality, so set retention limits and avoid caching low-reuse private results. Preference boosts should be evaluated separately from authorization and evidence support.
Common Mistakes
- Using a predicted role or preferred topic as an access grant.
- Caching personalized snippets under only the query text.
- Keeping query history after a user withdraws personalization consent.
- Letting a preference boost hide a newer or contradictory source.
Validation drill
Create 29 two-user scenarios with shared queries, group changes and opt-out events. Verify no cross-user snippet appears, then measure whether explicit preferences improve supported task completion.
