Skip to content

Scoring & Permissions ​

When a table mixes public and restricted records, standard full-text search can leak information: even if restricted rows are hidden from the result list, their term frequencies still change the BM25 scores of visible rows.

PiramideDB prevents this by enforcing row-level permissions inside the index.

Choosing a scoring mode ​

sql
CREATE INDEX documents_search_idx ON documents
USING piramidedb (tenant, body)
WITH (format = 7, analyzer = 'en', scoring = 'visible');
  • Computes exact BM25 statistics (N, df, and average document length) strictly over rows the caller is permitted to read.
  • Restricted rows have zero effect on the scores or ordering of visible rows.
  • Rejects attempts to weaken scoring to corpus at query time.

constant ​

Uses fixed term weights and the configurable constant_avgdl option. Provides the same zero-leak guarantee as visible with constant per-document scoring work. Best when you want predictable latency over very large grant sets and don't need corpus-relative IDF weighting.

corpus ​

Standard corpus-wide BM25 statistics. Use only for public catalogs or tables where every caller within a tenant has identical read access.

Passing caller grants ​

Include the caller's authorized grant tokens in the query JSON:

sql
SELECT d.id, d.title
FROM index_ctids_hybrid(
  'documents_search_idx'::regclass,
  'acme',
  '{"q":"incident review","grants":["role:engineering","team:sre"]}',
  NULL, 10, 40, 60, 0.25, 1.0
) AS h
JOIN documents AS d ON d.ctid = h.ctid
ORDER BY h.score DESC;

Permission-safe facets and diagnostics ​

  • facet_counts counts only rows admitted by the caller's grants.
  • diagnose_query reports the exact same zero-hit result for a word that appears only in restricted documents as for a word that does not exist at all.

PiramideDB is built by Nomad River.