Documentation
¶
Overview ¶
Package vecna provides a schema-validated filter builder for vector database queries. It serves as the query language for vector metadata filtering, similar to how edamame provides SQL AST capabilities.
Index ¶
- Variables
- type Builder
- type FieldBuilder
- func (fb *FieldBuilder[T]) Contains(value any) *Filter
- func (fb *FieldBuilder[T]) Eq(value any) *Filter
- func (fb *FieldBuilder[T]) Gt(value any) *Filter
- func (fb *FieldBuilder[T]) Gte(value any) *Filter
- func (fb *FieldBuilder[T]) In(values ...any) *Filter
- func (fb *FieldBuilder[T]) Like(pattern string) *Filter
- func (fb *FieldBuilder[T]) Lt(value any) *Filter
- func (fb *FieldBuilder[T]) Lte(value any) *Filter
- func (fb *FieldBuilder[T]) Ne(value any) *Filter
- func (fb *FieldBuilder[T]) Nin(values ...any) *Filter
- type FieldKind
- type FieldSpec
- type Filter
- type FilterSpec
- type Op
- type Spec
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotStruct is returned when the type parameter is not a struct. ErrNotStruct = errors.New("vecna: type must be a struct") // ErrFieldNotFound is returned when a field name is not found in the schema. ErrFieldNotFound = errors.New("vecna: field not found") // ErrInvalidFilter is returned when a filter contains validation errors. ErrInvalidFilter = errors.New("vecna: invalid filter") )
Errors returned by vecna.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder[T any] struct { // contains filtered or unexported fields }
Builder provides schema-validated filter construction for type T. Create a Builder using New[T]().
func New ¶
New creates a schema-validated Builder for metadata type T. Uses sentinel to extract field metadata from T. Field names are resolved from: json tag > Go field name. Fields with json:"-" are excluded.
func (*Builder[T]) And ¶
And combines filters with logical AND. Returns a Filter that matches when all child filters match.
func (*Builder[T]) FromSpec ¶
func (b *Builder[T]) FromSpec(spec *FilterSpec) *Filter
FromSpec converts a FilterSpec to a validated Filter. The spec is validated against the schema defined by T. Any validation errors are accessible via Filter.Err().
func (*Builder[T]) Not ¶
Not negates a filter. Returns a Filter that matches when the child filter does not match.
func (*Builder[T]) Or ¶
Or combines filters with logical OR. Returns a Filter that matches when any child filter matches.
func (*Builder[T]) Where ¶
func (b *Builder[T]) Where(field string) *FieldBuilder[T]
Where begins a filter condition on a field. If the field doesn't exist in T, the returned FieldBuilder will produce a Filter with an error accessible via Filter.Err().
type FieldBuilder ¶
type FieldBuilder[T any] struct { // contains filtered or unexported fields }
FieldBuilder constructs conditions for a specific field.
func (*FieldBuilder[T]) Contains ¶
func (fb *FieldBuilder[T]) Contains(value any) *Filter
Contains creates an array membership filter (array field contains value).
func (*FieldBuilder[T]) Eq ¶
func (fb *FieldBuilder[T]) Eq(value any) *Filter
Eq creates an equality filter (field == value).
func (*FieldBuilder[T]) Gt ¶
func (fb *FieldBuilder[T]) Gt(value any) *Filter
Gt creates a greater-than filter (field > value).
func (*FieldBuilder[T]) Gte ¶
func (fb *FieldBuilder[T]) Gte(value any) *Filter
Gte creates a greater-than-or-equal filter (field >= value).
func (*FieldBuilder[T]) In ¶
func (fb *FieldBuilder[T]) In(values ...any) *Filter
In creates a set membership filter (field IN values).
func (*FieldBuilder[T]) Like ¶
func (fb *FieldBuilder[T]) Like(pattern string) *Filter
Like creates a pattern matching filter (field LIKE pattern). Pattern syntax is provider-dependent but typically supports % and _ wildcards.
func (*FieldBuilder[T]) Lt ¶
func (fb *FieldBuilder[T]) Lt(value any) *Filter
Lt creates a less-than filter (field < value).
func (*FieldBuilder[T]) Lte ¶
func (fb *FieldBuilder[T]) Lte(value any) *Filter
Lte creates a less-than-or-equal filter (field <= value).
func (*FieldBuilder[T]) Ne ¶
func (fb *FieldBuilder[T]) Ne(value any) *Filter
Ne creates a not-equal filter (field != value).
func (*FieldBuilder[T]) Nin ¶
func (fb *FieldBuilder[T]) Nin(values ...any) *Filter
Nin creates a set exclusion filter (field NOT IN values).
type FieldKind ¶
type FieldKind uint8
FieldKind categorizes field types for validation.
Field kind constants.
type FieldSpec ¶
type FieldSpec struct {
Name string // JSON field name (from tag or Go name)
GoName string // Original Go field name
Kind FieldKind // Type category
}
FieldSpec describes a single filterable field.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter represents a filter condition or logical group. Construct filters using Builder[T].Where(), And(), or Or().
func (*Filter) Children ¶
Children returns the child filters for logical operators (And, Or). Returns nil for field conditions.
func (*Filter) Err ¶
Err returns any error that occurred during filter construction. This enables deferred error checking after building complex filters.
type FilterSpec ¶
type FilterSpec struct {
Op string `json:"op"` // Operator: "eq", "ne", "gt", "gte", "lt", "lte", "in", "and", "or"
Field string `json:"field,omitempty"` // Field name (for field conditions)
Value any `json:"value,omitempty"` // Comparison value (for field conditions)
Children []*FilterSpec `json:"children,omitempty"` // Child filters (for and/or)
}
FilterSpec represents a serializable filter specification. This enables programmatic filter construction from JSON or other external sources.
type Op ¶
type Op uint8
Op represents a filter operator.