quivr plugin init template, a rule that matches a phrase or a metadata value.
Prerequisites
- Python 3.12 or later, a
quivr-v2checkout in$QUIVR_REPO, and thequivrcommand on yourPATH(Build your first plugin shows how).
How Quivr calls a rule
When a Version becomes searchable, the worker collects every enabled Subscription that names your rule and sends them in batches: one article (its text Parts and metadata) and a list of evaluations, each a Saved Queryexpression and a Subscription configuration. Subscriptions that share the same expression and configuration become one evaluation, so a rule that calls a paid service pays once per distinct alert.
Your rule answers one decision per evaluation:
A decision must depend only on the article, the expression and the configuration. If the rule cannot decide at all, for example because a backend is down, it answers an error: Quivr keeps the evaluations pending and retries. A plugin outage delays alerts; it never turns into a negative decision.
Steps
1
Create the rule
2
Define what an alert looks like
expression_schema in quivr-plugin.yaml is the JSON Schema of the queries your rule understands. The template offers two kinds, told apart by kind:422 invalid_expression instead of failing later. configuration_schema does the same for the per-Subscription settings, here case_sensitive. To offer another kind of alert, add a branch to the oneOf and handle it in phrase_alerts/rule.py.3
Decide
evaluate in phrase_alerts/rule.py receives the article and the batch, and returns one decision per evaluation, built with the SDK’s helpers:phrase_alerts/rule.py (excerpt)
part_keys at most 100 keys of Parts in the request, and details a JSON object of at most 16 KiB. Quivr stores the evidence with the Match and sends it in the webhook.4
Replay the fixture
fixtures/sample.json holds one article and five evaluations with the decision each one should get:5
Certify it
6
Pin it and use it
Pin the plugin on the deployment’s
api and worker processes: the API calls it too, to preview alerts. A Subscription then names it by id and version:Check it worked
Preview an alert before saving it.POST /v0/subscription-previews runs your rule on the most recent articles of a Corpus and returns what it would match, without saving or sending anything:
evaluator.