Appearance
Hybrid & Agent Search
PiramideDB combines keyword search, semantic vector search, temporal filtering, and structured excerpts in standard SQL.
Keyword search
Use @@@ to filter matching rows and <=> to rank them by BM25 relevance:
sql
SELECT id, title
FROM documents
WHERE tenant = 'acme'
AND body @@@ 'vpn credentials rotated'
ORDER BY body <=> 'vpn credentials rotated'
LIMIT 10;Hybrid search (keyword + vector)
Use index_ctids_hybrid to fuse full-text BM25 and vector similarity in a single query using Reciprocal Rank Fusion (RRF). Each result includes the combined score plus lex_rank and vec_rank so your application or agent can see why a row matched.
sql
SELECT d.id, d.title, h.score, h.lex_rank, h.vec_rank
FROM index_ctids_hybrid(
'documents_search_idx'::regclass,
'acme',
'{"q":"vpn rotation","grants":["role:eng"],"valid_at":"2026-12-06","max_per_group":1}',
$1::bytea, -- Encoded query vector, or NULL for keyword-only
20, -- Results to return
80, -- Candidates per leg before fusion
60, -- RRF constant (k)
0.25, -- Lexical weight (default)
1.0 -- Vector weight (default)
) AS h
JOIN documents AS d ON d.ctid = h.ctid
ORDER BY h.score DESC;Pass NULL as the vector parameter whenever embeddings are unavailable—PiramideDB falls back cleanly to keyword ranking with the same query shape.
Point-in-time queries, phrases & snippets
Knowledge bases and policies change over time. Pass valid_at, phrases, and max_per_group inside the query JSON to return only the version that was in force on a given date, require exact phrase matches, and collapse duplicate versions:
sql
SELECT d.id, snippet_doc(d.body, 'vpn credentials rotated', 160) AS excerpt
FROM index_ctids_hybrid(
'documents_search_idx'::regclass,
'acme',
'{
"q": "vpn credentials rotated",
"valid_at": "2025-06-01",
"phrases": ["vpn credentials"],
"max_per_group": 1,
"grants": ["role:eng"]
}',
NULL, 5, 20, 60, 0.25, 1.0
) AS h
JOIN documents AS d ON d.ctid = h.ctid
ORDER BY h.score DESC;Agent search primitives
| Function | What it solves |
|---|---|
snippet_doc(body, query, max_chars) | Extracts a concise excerpt around matching terms so agents don't load full documents unnecessarily. |
facet_counts(index, tenant, query_json, field) | Counts matching records per category before fetching rows, strictly within the caller's grants. |
diagnose_query(index, tenant, query_json) | Explains why a query returned zero results by identifying unmatched terms—without revealing hidden rows. |
search_batch(index, tenant, queries_json) | Runs multiple sub-queries against one consistent snapshot in a single database round trip. |