Short answer: apply cheap, authoritative metadata filters before semantic retrieval, then verify the page snapshot before sending an alert. This keeps product-search results relevant while putting a hard ceiling on latency for a catalog page watcher.
A useful mental model is a two-stage gate. The first gate answers questions a database can answer exactly: tenant, locale, publication state, category, and the last observed content hash. The second gate handles meaning: which surviving records are actually related to the changed text? Mixing those jobs is how a small page edit turns into a slow, noisy incident.
What should metadata filters do before product retrieval?
Metadata is a safety boundary, not decoration. Every product record needs an owner (tenant), a canonical URL, locale, status, and a version or fetched-at timestamp. A change event from the watcher carries the same tenant and URL, plus the new normalized text and its hash. The query cannot override those fields.
Filter first on fields with exact semantics. status=published prevents a draft from entering an alert. tenant_id prevents cross-customer leakage. A locale match avoids comparing an English page with a French catalog. The hash check makes a repeated delivery cheap: if the normalized hash is already the latest accepted version, acknowledge the event and stop.
Then run retrieval over that bounded candidate set. A vector score can tell you that “wireless charger” resembles “Qi2 pad”; it cannot tell you that the product is still sold by the requesting tenant. Exact predicates must win.
Ship the predicate.
A runbook for a page-change alert
When an event arrives, record its id and start a trace. Fetch or read the normalized snapshot, compute a stable hash, and compare it with the last accepted hash. If there is no material change, mark the event as a duplicate and do not spend retrieval work.
For a real change, construct an immutable filter object from the event context. Keep retrieval top-k small enough for the alert budget, and attach the filter and hash to the result record so an operator can reproduce the decision. The alert payload should include the old and new hash, the changed fields, and the evidence passages; a score without evidence is a pager mystery.
Here is the control flow in Go. The interfaces are deliberately generic so the same contract can sit in front of a SQL index, a search service, or a self-hosted vector store.
package monitor import ( "context" "crypto/sha256" "encoding/hex" ) type Event struct { ID, Tenant, URL, Locale, Text string } type Filter struct { Tenant, URL, Locale, Status string } type SnapshotStore interface { LatestHash(context.Context, string, string) (string, error) SaveHash(context.Context, string, string, string) error } type Retriever interface { Search(context.Context, string, Filter, int) ([]string, error) } func Process(ctx context.Context, e Event, store SnapshotStore, r Retriever) ([]string, bool, error) { sum := sha256.Sum256([]byte(e.Text)) hash := hex.EncodeToString(sum[:]) previous, err := store.LatestHash(ctx, e.Tenant, e.URL) if err != nil { return nil, false, err } if previous == hash { return nil, false, nil // duplicate delivery } filter := Filter{Tenant: e.Tenant, URL: e.URL, Locale: e.Locale, Status: "published"} matches, err := r.Search(ctx, e.Text, filter, 8) if err != nil { return nil, false, err } if err := store.SaveHash(ctx, e.Tenant, e.URL, hash); err != nil { return nil, false, err } return matches, true, nil } The ordering matters. Persisting the new hash before retrieval can suppress a retry after a transient dependency failure; persisting only after successful retrieval makes the operation retryable. In practice, the failure is easy to miss because the first attempt may have already acknowledged the queue message while the downstream search call is still waiting. A retry then sees a new page, emits a second alert, and leaves operators comparing identical evidence. I prefer recording the event id and hash in one durable transaction, followed by an alert send keyed by tenant/url/hash; if the send times out, the same key is safe to replay. Either way, the event id needs a uniqueness constraint, and the alert sender needs an idempotency key such as tenant/url/hash.
How do you trade retrieval quality against alert latency?
Measure the stages separately. Track filter time, candidate count, retrieval time, rerank time, and end-to-end time at p50 and p95. Also track empty-result rate and duplicate-alert rate. A fast pipeline that alerts on irrelevant products is not healthy; a precise pipeline that misses the notification window is not healthy either.
Set a budget before tuning. For example, reserve most of the deadline for fetching and filtering, leave a bounded slice for semantic search, and fail closed when the remaining time cannot produce evidence. The exact numbers depend on traffic and page size; I'm not sure a universal threshold exists, and your mileage will vary. The important part is that the budget is explicit and tested.
Quality improves when filters preserve recall within the correct boundary. Avoid filtering on fields that are inferred from text unless the business has accepted the false-negative risk. Conversely, never weaken tenant or publication predicates to rescue recall. That is an incident, not an optimization.
Failure modes, verification, and rollback
A postmortem usually finds one of four causes: a stale snapshot, a missing tenant predicate, duplicate delivery, or a timeout that was retried without a cap. Test each as a contract. Feed the same event twice and expect one alert. Feed two tenants with identical text and expect isolated candidates. Change only whitespace and verify that normalization follows the documented policy.
Before deployment, replay a sampled set of page diffs in a shadow path. Compare candidate counts and evidence overlap with the current pipeline, then canary by tenant. Keep the old retrieval path available behind a flag. If p95 latency or false alerts crosses the agreed threshold, disable the new path, drain in-flight work, and replay events from the durable queue; do not delete hashes while diagnosing.
The catch is that this design is not suitable when the source has no stable identity or when alerts must be generated from unstructured, tenant-wide discovery with no trustworthy metadata. In those cases, stick with a broader crawl and add human review, accepting higher latency.
The RAG paper describes retrieval as a separate source of knowledge for generation, which is the same separation that makes this alerting workflow explainable: retrieve bounded evidence first, then act on it.
