find

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package find implements the natural language EC2 instance search pipeline used by the truffle tool. It covers three stages:

  1. Parsing: ParseQuery converts a free-text query ("nvidia h100 8gpu", "amd epyc genoa 64gb memory") into a structured ParsedQuery.

  2. Criteria building: ParsedQuery.BuildCriteria translates the parsed query into a SearchCriteria containing a compiled regexp and [FilterOptions] ready to pass to truffle/pkg/aws.SearchInstanceTypes.

  3. Result enrichment: ExplainMatch annotates each result with human-readable match reasons (e.g., "GPU: A100 (80 GiB, training)").

Typical usage:

pq, err := find.ParseQuery("nvidia h100 8gpu")
criteria, err := pq.BuildCriteria()
results, err := client.SearchInstanceTypes(ctx, regions, criteria.InstanceTypePattern, criteria.FilterOptions)
for _, r := range results {
    reasons := find.ExplainMatch(r, pq)
}

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatch = errors.New("truffle: no instance types match card")

ErrNoMatch is returned by ResolveCard when a card name does not resolve to any known GPU / instance types. It exists so a card-name consumer gets an explicit "no match" instead of the free-text search pipeline's match-all (".*") fallback, which silently degrades an unresolved query into "every instance type" — a dangerous result to mistake for a real one (#90).

View Source
var QualitativeSortMap = map[string]SortPreference{
	"cheap": SortCheapest, "cheapest": SortCheapest, "affordable": SortCheapest, "budget": SortCheapest,
	"expensive": SortExpensive, "premium": SortExpensive,
	"fast": SortPerformant, "fastest": SortPerformant, "powerful": SortPerformant, "performant": SortPerformant,
	"new": SortNewest, "newest": SortNewest, "latest": SortNewest,
}

Functions

func CardInstanceTypes added in v0.43.0

func CardInstanceTypes(card string) (canonical string, instances []string, err error)

CardInstanceTypes is the metadata-only sibling of ResolveCard: it looks a card up directly in the catalog (including aliases) without running the token parser, returning the canonical GPU key and its instance types. It is useful when a caller already holds a clean card key and wants an exact catalog hit rather than free-text tolerance. Returns ErrNoMatch if the card is unknown.

func ExplainMatch

func ExplainMatch(result aws.InstanceTypeResult, query *ParsedQuery) []string

ExplainMatch generates human-readable reasons why an instance matched the query

func ResolveCard added in v0.43.0

func ResolveCard(card string) ([]string, error)

ResolveCard maps a GPU card name (e.g. "RTX PRO 6000", "H100", "L40S") to the concrete EC2 instance types that carry it. It is the strict, card-oriented counterpart to the free-text ParseQuery/ParsedQuery.BuildCriteria pipeline: a card that resolves to nothing returns ErrNoMatch, never a match-all pattern. The returned instance types are sorted for stable output.

It resolves via the same catalog and alias table as the search pipeline, so marketing spellings ("rtx pro 6000") and canonical names ("rtx pro server 6000") both work. A query that carries constraints other than the card (vCPUs, memory, size, …) is rejected — this is a card resolver, not a search; use ParseQuery for compound queries.

Types

type FindResult

type FindResult struct {
	aws.InstanceTypeResult          // Embedded full result from the AWS query
	MatchReasons           []string // Human-readable explanations of why this instance matched the query
	MatchScore             int      // Relevance score for sorting; higher means more specific match
}

FindResult extends aws.InstanceTypeResult with match explanations produced by ExplainMatch, useful for displaying to end users why a result was returned.

type ParsedQuery

type ParsedQuery struct {
	Vendors        []string // Hardware vendor filters, e.g. ["amd"], ["nvidia"]
	Processors     []string // Processor code names, e.g. ["genoa", "sapphire rapids"]
	GPUs           []string // GPU model names, e.g. ["h100", "a100"]
	Sizes          []string // Size-category filters, e.g. ["large", "xlarge"]
	MinVCPU        int      // Minimum vCPU count; 0 means unconstrained
	MinPhysCores   int      // Minimum physical core count; 0 means unconstrained
	MinMemory      float64  // Minimum memory in GiB; 0 means unconstrained
	GPUCount       int      // Minimum number of GPUs; 0 means unconstrained
	Architecture   string   // "x86_64" or "arm64"; empty means both
	MinNetworkGbps int      // Minimum network bandwidth in Gbps; 0 means unconstrained
	RequireEFA     bool     // If true, only match instance families with EFA support
	RequireNestedV bool     // If true, only match instance types supporting nested virtualization
	ExactMatch     bool     // If true, match exact vCPU and memory values instead of minimum
	RawTokens      []Token  // Parsed tokens in input order, useful for diagnostics
	Apps           []string // Application names from catalog (e.g. ["paraview"]); resolved to hardware in BuildCriteria
}

ParsedQuery is the structured output of ParseQuery. It holds all constraints extracted from the user's free-text input and is consumed by ParsedQuery.BuildCriteria.

func ParseQuery

func ParseQuery(query string) (*ParsedQuery, error)

ParseQuery parses a natural language query into structured search criteria

func (*ParsedQuery) BuildCriteria

func (pq *ParsedQuery) BuildCriteria() (*SearchCriteria, error)

BuildCriteria converts a ParsedQuery into SearchCriteria for execution

func (*ParsedQuery) BuildSizePattern

func (pq *ParsedQuery) BuildSizePattern() string

BuildSizePattern returns a regex pattern for size filtering

func (*ParsedQuery) DeriveArchitecture

func (pq *ParsedQuery) DeriveArchitecture() string

DeriveArchitecture determines the architecture from query criteria

func (*ParsedQuery) QualitativeTokens added in v0.37.0

func (pq *ParsedQuery) QualitativeTokens() []string

QualitativeTokens returns any qualitative keywords found in the parsed query.

func (*ParsedQuery) ResolveGPUInstances

func (pq *ParsedQuery) ResolveGPUInstances() []string

ResolveGPUInstances returns exact instance types for GPU queries

func (*ParsedQuery) ResolveInstanceFamilies

func (pq *ParsedQuery) ResolveInstanceFamilies() []string

ResolveInstanceFamilies returns all instance families matching the query

func (*ParsedQuery) SortPreference added in v0.37.0

func (pq *ParsedQuery) SortPreference() SortPreference

SortPreference returns the sort preference derived from qualitative keywords in the query.

func (*ParsedQuery) Validate

func (pq *ParsedQuery) Validate() error

Validate checks for conflicting or invalid query criteria

type SearchCriteria

type SearchCriteria struct {
	InstanceTypePattern *regexp.Regexp    // Compiled regexp matching eligible EC2 instance type strings
	FilterOptions       aws.FilterOptions // Numeric and categorical filters passed to SearchInstanceTypes
}

SearchCriteria holds the compiled, ready-to-execute form of a ParsedQuery. Pass InstanceTypePattern and FilterOptions directly to aws.SearchInstanceTypes.

func (*SearchCriteria) Matcher

func (sc *SearchCriteria) Matcher() func(string) bool

Matcher returns a function suitable for aws.SearchInstanceTypes

type SortPreference added in v0.37.0

type SortPreference int

SortPreference represents a user-requested sort derived from qualitative keywords.

const (
	SortDefault    SortPreference = iota
	SortCheapest                  // sort by on-demand price ascending
	SortExpensive                 // sort by on-demand price descending
	SortNewest                    // sort by generation descending
	SortPerformant                // sort by vCPU count descending
)

type Token

type Token struct {
	Type  TokenType // Semantic classification of this token
	Value string    // Normalized canonical value, e.g. "nvidia", "128gb"
	Raw   string    // Original input text before normalization
}

Token represents a single classified word from a natural language query.

type TokenType

type TokenType int

TokenType represents the type of a parsed token

const (
	TokenUnknown TokenType = iota
	TokenVendor
	TokenProcessor
	TokenGPU
	TokenSize
	TokenVCPU
	TokenMemory
	TokenGPUCount
	TokenArchitecture
	TokenNetworkSpeed
	TokenEFA
	TokenNestedVirt    // Nested-virtualization support (e.g. "nested-virt")
	TokenPhysicalCores // Physical core count (e.g. "8 physical cores")
	TokenApp           // Application name from pkg/catalog (e.g. "paraview", "igv")
	TokenQualitative   // Qualitative/subjective keyword (e.g. "cheap", "fastest")
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL