USING LENS And APPLY ANALYSIS RUN
Generic Description
USING LENS attaches a registered lens abstraction to the current query stream. APPLY ANALYSIS RUN runs a registered analysis-run artifact against the current row stream and yields analysis output columns.
Example:
CREATE ABSTRACTION ACTOR Member
DESCRIPTION 'People whose retention, engagement, and churn risk are tracked.';
CREATE ABSTRACTION LENS ChurnInvestigation
DESCRIPTION 'Understand why members churn and identify useful separation rules.'
TAGS (assistant_generated, intent);
CREATE ANALYSIS RUN ChurnSeparabilityRules OPTIONS {
kind: 'separability_filter',
lens: 'ChurnInvestigation',
target_abstraction: 'Member',
target_feature: 'churned',
confidence: 0.82,
segment: 'low_activity',
reason: 'Low recent activity separates churned members in the current feature snapshot.'
};
MATCH (c:actor(Member))
USING LENS ChurnInvestigation
APPLY ANALYSIS RUN ChurnSeparabilityRules ON c
YIELD passed, score, confidence, segment, reason
RETURN c, passed, score, confidence, segment, reason
Consumer-Level Explanation
Use USING LENS when a query is answering from a particular viewpoint. A lens may represent an assistant-captured user intent, a reporting perspective, a domain-specific investigation, or a reusable projection over the graph.
Use APPLY ANALYSIS RUN when a reusable analysis-run definition should be applied without re-planning or re-calling an LLM. The analysis run can represent a separability filter, scorer, projector, transformset, or segmenter. Once registered, applying it should be deterministic.
Conceptual Explanation
Lens and analysis runs solve different problems.
A lens is an abstraction. It is a abstraction viewpoint: what the user is trying to see, why the selection matters, and how the visible graph can be represented.
An analysis run is executable abstraction machinery stored as an artifact. It can be attached to a lens, but it is not itself an abstraction. For separability workflows, the analysis run stores the ruleset or scoring metadata produced by analysis. Query execution can then apply that definition to candidate subjects.
The clause order is intentionally row-stream oriented:
MATCHfinds or creates the row streamUSING LENSrecords the viewpoint for the downstream queryAPPLY ANALYSIS RUNenriches rows with analysis-run outputsWHERE,RETURN, aggregation, and later clauses can use those outputs
Advanced Example
CREATE ABSTRACTION ACTOR ActiveMember FOR LABEL User TAGS (retention);
CREATE ABSTRACTION IF NOT EXISTS LENS ChurnInvestigation
DESCRIPTION 'Find explainable churn patterns in member behavior.'
TAGS (assistant_generated, intent);
CREATE ANALYSIS RUN ChurnRules OPTIONS {
kind: 'separability_filter',
lens: 'ChurnInvestigation',
target_abstraction: 'ActiveMember',
target_feature: 'churned',
confidence: 0.91,
segment: 'inactive_recently',
reason: 'Members with low recent activity are separated from the retained group.'
};
MATCH (m:actor(ActiveMember))
USING LENS ChurnInvestigation
APPLY ANALYSIS RUN ChurnRules ON m
YIELD passed, score, confidence, segment, reason
WHERE passed = true
RETURN segment, count(m) AS members, avg(score) AS average_score
ORDER BY average_score DESC
Real Use Cases
- Run an assistant-created investigation lens over the current graph without exposing technical controls to the user.
- Apply a separability ruleset produced by feature analysis to all current subjects.
- Build a report from a lens, selected abstractions, and analysis runs while preserving the queryable contract.
- Keep durable intent and executable analysis separate while still letting Cypher compose them in one query.
Real Limitations And Tradeoffs
USING LENSis currently a abstraction query annotation. It validates that the lens clause is part of the query stream, but richer planner behavior such as lens-driven default source expansion can be added incrementally.APPLY ANALYSIS RUNcurrently calls the registered analysis-run application path and yields deterministic fields from the stored analysis-run metadata. Full separability ruleset execution is expected to extend this same executor rather than introduce another public clause.- Analysis runs should be deterministic after creation. If an analysis run needs LLM work, do that before registration, then persist the resulting ruleset or configuration.
APPLY ANALYSIS RUNis row-stream oriented. It is not a replacement for batch materialization, snapshot building, or model scoring procedures when those workflows need their own operational lifecycle.