Supported composition
Build company search
Flow
This composition stores canonical source revisions, builds a replaceable index, applies an authorization result during candidate scoring, and returns the exact revision used as context.
"""Synchronize revisions, apply host authorization, and retrieve evidence."""
from mari_components import KnowledgeDocument, ScopeRef
from mari_components.platform import InMemoryDocumentStore
from mari_components.retrieval import RevisionBM25Index
def run() -> dict[str, object]:
scope = ScopeRef(tenant="acme", space="handbook")
documents = (
KnowledgeDocument(
source_id="handbook",
external_id="refunds",
title="Refund policy",
body="Enterprise purchases can be refunded within 30 days.",
revision="policy-v1",
),
KnowledgeDocument(
source_id="handbook",
external_id="payroll",
title="Payroll",
body="Payroll closes on the final business day.",
revision="payroll-v1",
),
)
store = InMemoryDocumentStore()
for document in documents:
store.commit(document, scope=scope, expected_revision=None)
refs = {document.ref_in(scope): document for document in documents}
index = RevisionBM25Index({ref: document.body for ref, document in refs.items()})
allowed_refs = {documents[0].ref_in(scope)} # supplied by the host authorizer
hits = index.search("enterprise refund window", limit=5, allowed_refs=allowed_refs)
selected = refs[hits[0].ref]
return {
"document_id": selected.document_id,
"revision": selected.revision,
"text": selected.body,
"score": hits[0].score,
}
if __name__ == "__main__":
print(run())
InMemoryDocumentStore supplies reference semantics. A production adapter can
implement DocumentStore and run assert_document_store_conforms against its
transaction and isolation behavior. BM25Index can be replaced by a dense,
multi-vector, graph, or external index. The document and authorization
boundaries stay unchanged.
The application computes allowed_ids from its own identity and policy system.
The index receives that set before it scores candidates.
Decision |
Default in this example |
Other Mari tools |
|---|---|---|
Canonical storage |
In-memory reference store |
Application |
Candidate generation |
BM25 |
Dense flat, sparse vector, HNSW, IVF-PQ, MUVERA |
Authorization |
Explicit allowed-ID set |
Application |
Returned context |
Whole document body |
Semantic atoms and neighbor expansion |