patterns_query
patterns_query
¶
Pattern query and lookup mixin for GlobalLearningStore.
Provides methods for querying, filtering, and retrieving patterns: - get_patterns: Query with filtering by type, priority, tags, quarantine, trust - get_pattern_by_id: Single pattern lookup - get_pattern_provenance: Provenance information retrieval - _row_to_pattern_record: Database row to PatternRecord conversion - _row_to_discovery_event: Database row to PatternDiscoveryEvent conversion
This is the "hub" mixin — other pattern sub-mixins depend on its query methods.
Classes¶
PatternQueryProtocol
¶
Bases: Protocol
Protocol declaring the query methods provided by PatternQueryMixin.
Dependent mixins (TrustMixin, SuccessFactorsMixin, QuarantineMixin, BroadcastMixin) inherit from this under TYPE_CHECKING so mypy knows these methods will exist at runtime through mixin composition.
PatternQueryMixin
¶
Mixin providing pattern query methods for GlobalLearningStore.
This mixin requires that the composed class provides: - _get_connection(): Context manager yielding sqlite3.Connection
Functions¶
get_patterns
¶
get_patterns(pattern_type=None, min_priority=0.01, limit=20, context_tags=None, quarantine_status=None, exclude_quarantined=False, min_trust=None, max_trust=None, include_inactive=False, instrument_name=None, include_universal=True)
Get patterns from the global store.
v19 Evolution: Extended with quarantine and trust filtering options. v14 (cycle 2): Extended with soft-delete and instrument filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_type
|
str | None
|
Optional filter by pattern type. |
None
|
min_priority
|
float
|
Minimum priority score to include. |
0.01
|
limit
|
int
|
Maximum number of patterns to return. |
20
|
context_tags
|
list[str] | None
|
Optional list of tags for context-based filtering. Patterns match if ANY of their tags match ANY query tag. If None or empty, no tag filtering is applied. |
None
|
quarantine_status
|
QuarantineStatus | None
|
Filter by specific quarantine status. |
None
|
exclude_quarantined
|
bool
|
If True, exclude QUARANTINED patterns. |
False
|
min_trust
|
float | None
|
Filter patterns with trust_score >= this value. |
None
|
max_trust
|
float | None
|
Filter patterns with trust_score <= this value. |
None
|
include_inactive
|
bool
|
If True, include soft-deleted patterns (active=0). |
False
|
instrument_name
|
str | None
|
Filter by instrument name. None means no filter. |
None
|
include_universal
|
bool
|
If True (default) AND instrument_name is set, also include patterns where instrument_name is NULL (universal patterns applicable to all instruments). |
True
|
Returns:
| Type | Description |
|---|---|
list[PatternRecord]
|
List of PatternRecord objects sorted by priority. |
Source code in src/marianne/learning/store/patterns_query.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get_pattern_by_id
¶
Get a single pattern by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_id
|
str
|
The pattern ID to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
PatternRecord | None
|
PatternRecord if found, None otherwise. |
Source code in src/marianne/learning/store/patterns_query.py
get_pattern_provenance
¶
Get provenance information for a pattern.
Returns details about the pattern's origin and lifecycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_id
|
str
|
The pattern ID to query. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Dict with provenance info, or None if pattern not found. |