Documentation
¶
Overview ¶
Package examples embeds the catalogue of runnable Pulse request JSON files and exposes a search/get API over them.
Every embedded JSON carries a top-level _meta block describing the example's name, category, taxonomy tags, the operators it uses, and a one-sentence description. Pulse's types.Request unmarshaler ignores unknown fields by default, so _meta is invisible at execution time — the examples remain runnable verbatim.
Get returns the example with the _meta block stripped, so callers can hand the JSON straight to pulse_process / pulse_predict.
Index ¶
- Variables
- func AllCategories() []string
- func AllTags() []string
- func Capabilities() map[string][]string
- func Count() int
- func DeriveOperators(body []byte) []string
- func Intents() map[string][]string
- func IsCanonicalTag(tag string) bool
- func Parse(data []byte, strict bool) (*Example, Meta, error)
- func Tokenize(s string) []string
- type Example
- type ExampleSummary
- type Meta
- type Options
- type Query
Constants ¶
This section is empty.
Variables ¶
var CanonicalTags = []string{
"time-series", "cohort-analysis", "experiment-analysis", "correlation-analysis",
"comparison", "before-after", "top-n", "distribution-shape", "cross-tabulation",
"proportion-analysis", "trend-detection", "outlier-detection", "cardinality-analysis",
"data-quality", "financial", "feature-engineering",
"hypothesis-test", "t-test", "parametric", "nonparametric", "paired", "one-sample",
"two-sample", "k-sample", "repeated-measures", "post-hoc",
"normality-test", "homogeneity-test", "exact-test",
"regression", "ecological",
"ols", "glm", "logistic", "bayesian",
"regularization", "ridge", "lasso", "elasticnet",
"polynomial", "resampling", "jackknife", "selection", "stepwise",
"tier-1-test", "tier-2-test", "composed", "pre-filter", "feature-pipeline",
"window-operator", "streaming-friendly", "buffered-pipeline",
"matrix", "covariance", "multivariate",
"leakage-risk", "small-sample",
"facet",
"sharded", "anchor",
"overlay",
"byte-equal-test",
"compose",
"crosstab",
"welch",
"welford-triple",
"z",
}
CanonicalTags is the curated taxonomy every annotated example must draw from. Kept here (rather than embedded in a separate file) so the validation gate can compare directly without round-tripping through a disk asset.
var ErrNoMeta = errors.New("missing _meta block")
ErrNoMeta is Parse's error for a JSON object without a _meta block.
Functions ¶
func AllCategories ¶
func AllCategories() []string
AllCategories returns every directory the library indexes, sorted alphabetically.
func AllTags ¶
func AllTags() []string
AllTags returns every taxonomy tag the library currently uses, sorted alphabetically. Derived from the indexed examples — not the canonical allowlist — so callers see exactly what is tagged today.
func Capabilities ¶
Capabilities returns every example's optional _meta.capabilities, keyed by example name; an example without the key is absent. Values are feature-profile spellings of non-operator features (`capability:stream`), validated by internal/descriptor (TestExamples_CapabilitiesFromFeatures), which this package cannot import. The key exists for capabilities a request body carries no structural signal for; internal/descriptor's ontology builder turns each value into an `example requires_capability <feature>` edge.
func DeriveOperators ¶
DeriveOperators returns the sorted, distinct operator names a body carries as a `"type"` value — what `_meta.operators` must equal (TestExamples_OperatorsMatchBody; embedder examples at pulse.New).
func Intents ¶
Intents returns every example's optional _meta.intents, keyed by example name; an example without the key is absent. Values are validated against the intent taxonomy by internal/descriptor (TestExamples_IntentsFromTaxonomy), which this package cannot import.
func IsCanonicalTag ¶
IsCanonicalTag reports whether tag belongs to the curated taxonomy.
func Parse ¶
Parse reads one example file: a JSON object carrying a _meta block plus the request body. It returns the Example — Body is the object minus _meta, re-marshaled deterministically — and the parsed Meta. strict refuses an unknown _meta key (embedder examples); the embedded library parses leniently. Parse does not validate Meta's values.
Types ¶
type Example ¶
type Example struct {
Name string `json:"name"`
Category string `json:"category"`
Tags []string `json:"tags"`
Operators []string `json:"operators"`
Description string `json:"description"`
// Intents is the example's _meta.intents (intent-taxonomy IDs);
// absent on the wire when the example declares none.
Intents []string `json:"intents,omitempty"`
Body json.RawMessage `json:"body"`
}
Example is the full record returned by Get. Body carries the request JSON with the _meta block stripped, so it can be handed verbatim to pulse_process / pulse_predict.
type ExampleSummary ¶
type ExampleSummary struct {
Name string `json:"name"`
Category string `json:"category"`
Tags []string `json:"tags"`
Operators []string `json:"operators"`
Description string `json:"description"`
// Intents is the example's _meta.intents (intent-taxonomy IDs);
// absent on the wire when the example declares none.
Intents []string `json:"intents,omitempty"`
}
ExampleSummary is the lightweight projection used by Search results.
func Search ¶
func Search(query string, tags []string, category string) []ExampleSummary
Search returns summaries matching all three filters. An empty filter is treated as "no constraint" for that dimension. It is SearchQuery over the embedded library with no synonym tables; SearchQuery documents the matching rules. Never nil.
func SearchIn ¶
func SearchIn(lib []*Example, query string, tags []string, category string) []ExampleSummary
SearchIn is Search over lib, which must be sorted by name (the no-query order and the score tie-break). An instance serving embedder examples searches the merged library through it.
func SearchLibrary ¶
func SearchLibrary(q Query, opts Options) []ExampleSummary
SearchLibrary is SearchQuery over the embedded library.
func SearchQuery ¶
func SearchQuery(lib []*Example, q Query, syn Options) []ExampleSummary
SearchQuery returns the summaries of lib matching q, ranked. lib must be sorted by name (the no-query order and the score tie-break).
Matching runs as ordered tiers; the first tier with any hit wins:
- exact — a query that is a single plain word (letters and digits only) keeps the legacy rule: a case-insensitive substring of the name, the description or any operator, so a one-word query answers exactly as before. Any other query is tokenized (lower-cased, split on non-alphanumerics, no stemming, common stop words dropped) and an example matches when every query token is an exact token of at least one of its fields (name, description, operators, intents, tags); a field counts when it holds any query token.
- synonym — a query phrase that is a Purpose.KnownAs alias expands the query to that operator, and a query phrase found inside an intent's Sound expands it to that intent. An example matches when its operators or intents carry an expansion; the fields matched by the expansions and by any query token count.
Score = distinct matched fields; ties break alphabetically by name. No query lists every example passing the filters, alphabetically. Returns a non-nil empty slice when nothing matches.
type Meta ¶
type Meta struct {
Name string `json:"name"`
Category string `json:"category"`
Tags []string `json:"tags"`
Operators []string `json:"operators"`
Description string `json:"description"`
// Intents is optional; every value must be an intent-taxonomy ID
// (validated by internal/descriptor's TestExamples_IntentsFromTaxonomy,
// since this package cannot import the taxonomy).
Intents []string `json:"intents,omitempty"`
// Capabilities is optional; every value must be a non-operator
// feature name (validated by internal/descriptor's
// TestExamples_CapabilitiesFromFeatures).
Capabilities []string `json:"capabilities,omitempty"`
}
Meta mirrors the _meta block every example JSON carries — built-in and embedder (pulse.Extensions.Examples) alike.
type Options ¶
type Options struct {
// Aliases maps a Purpose.KnownAs alias to the operator declaring it.
Aliases map[string]string
// Sounds maps an intent Sound to its intent ID.
Sounds map[string]string
// KeepIntent, when set, drops every _meta.intents value it refuses
// from matching and from the returned summaries (an intent the
// instance hides). Nil keeps all.
KeepIntent func(id string) bool
// KeepExample, when set, drops every example it refuses before any
// tier runs, so a hidden example never decides which tier answers.
KeepExample func(name string) bool
}
Options carries an instance's view into a search: the synonym tables of the synonym match tier and the visibility filters. Every table key is in internal/descriptor's FoldAlias form (lower-cased, whitespace collapsed, punctuation kept). The zero value searches the whole library with the synonym tier disabled.
type Query ¶
type Query struct {
Query string `json:"query,omitempty"`
Tags []string `json:"tags,omitempty"`
Category string `json:"category,omitempty"`
Intent string `json:"intent,omitempty"`
}
Query is one example search: every filter optional, all ANDed.
- Query is matched against an example's name, description, operators, _meta.intents and tags (see SearchQuery for the match tiers).
- Tags is ANDed: an example must carry every requested tag.
- Category is an exact directory match.
- Intent is an intent-taxonomy ID the example's _meta.intents must carry. This package does not validate it (it cannot import the taxonomy); internal/descriptor refuses an unknown or hidden one before searching.