Reference / Search API for Go
Search API for Go
Every public type, function and constant of the Search engine in tinyshed.org/tinystore/search, generated from its source. The Search guide explains how to use them, and the Bun and Node, Python and Rust pages list the same API.
Drop
func Drop(ctx context.Context, home tinystore.Home, name string) (bool, error)Drop drops an index and every document it holds, a table's index its triggers off the table, from the store or the database home is; it says whether there was one.
Reindex
func Reindex(ctx context.Context, store *tinystore.Store, name string, opts ...Option) errorReindex reads every document of the index again beside it, by these settings, the old answering until the new switch in, and returns once they did: what Rebuild(Manual) waits for.
Vector
func Vector(v []float32) vectorVector is a document's vector on a set, or a search's on a search, of the index's dimensions, as the program's own model gave it.
Doc
type Doc[T any] struct {
ID any
Value T
Vector []float32
NoVector bool
}Doc is a document SetMany sets: its id, its value and what it says of its vector.
Fields
type Fields map[string]float64Fields are the fields whose words are read, by their paths, each with what a word found there weighs; without them a document is its own text.
Group
type Group struct {
// contains filtered or unexported fields
}Group is conditions joined: Or's, And's.
And
func And(parts ...Where) GroupAnd is conditions every one of which passes.
Or
func Or(parts ...Where) GroupOr is conditions any of which passes.
Hit
type Hit[T any] struct {
ID string
Value T
Score float64
}Hit is a document a search found, and the score that ordered it among this search's hits.
Hybrid
type Hybrid struct {
VectorWeight float64
Rerank bool
}Hybrid is how a search by words and a vector at once combines them: each half's best hundred scaled and summed at VectorWeight, 0.5 unless given, or the words' best Reranked by their vectors.
Index
type Index[T any] struct {
// contains filtered or unexported fields
}Index is documents of one type by id, or a table's rows, found again by their words, vectors or both.
OpenIndex
func OpenIndex[T any](home tinystore.Home, name string, opts ...Option) (*Index[T], error)OpenIndex opens an index on the store, or a table's index on a database with Table. It opens at its first call; its error is a name or an option it refuses.
Index.Delete
func (x *Index[T]) Delete(ctx context.Context, id any) (bool, error)Delete deletes the document id, and says whether there was one.
Index.Get
func (x *Index[T]) Get(ctx context.Context, id any) (T, bool, error)Get is the document id, and whether there is one.
Index.Name
func (x *Index[T]) Name() stringName is the index's name.
Index.Ready
func (x *Index[T]) Ready(ctx context.Context) errorReady waits until the index serves the settings it was opened with; a rebuild that failed is Invalid, saying why.
Index.Search
func (x *Index[T]) Search(ctx context.Context, text string, opts ...QueryOption) (Result[T], error)Search is the best ten, or Limit, by text's words, by a Vector, or by both, kept to what a Where passes. Both at once scale each half's best hundred and sum them at the index's vector weight. Of equal scores the one set first comes first.
Index.SearchVector
func (x *Index[T]) SearchVector(ctx context.Context, v []float32, opts ...QueryOption) (Result[T], error)SearchVector is the best ten, or Limit, by a vector alone.
Index.Set
func (x *Index[T]) Set(ctx context.Context, id any, value T, opts ...SetOption) errorSet sets the document id to value, replacing it whole; the next search sees it.
Index.SetMany
func (x *Index[T]) SetMany(ctx context.Context, docs []Doc[T]) errorSetMany sets every document in one commit, all of them or none, 1,000 at most.
Index.Status
func (x *Index[T]) Status(ctx context.Context) (Status, error)Status is where the index stands; a search never waits, and answers by the settings it serves.
Listed
type Listed struct {
Name string
Documents, Vectors int
// Opened is when a program last opened it; zero when none did.
Opened time.Time
Status Status
}Listed is an index as List gives it.
List
func List(ctx context.Context, store *tinystore.Store) ([]Listed, error)List is every index the store holds, by name.
Option
type Option interface {
// contains filtered or unexported methods
}Option is how an index opens.
FieldNames
func FieldNames(paths ...string) OptionFieldNames are fields whose words each weigh 1, in this order.
Filters
func Filters(paths ...string) OptionFilters are the fields a search's Where may keep its hits to.
Key
func Key(column string) OptionKey is a table's column of unique values the index names rows by; its primary key unless given.
Rebuild
func Rebuild(mode RebuildMode) OptionRebuild says when a change of settings that needs the documents read again is read.
Table
func Table(name string) OptionTable makes the index a database's table's, opened from the database: its rows found again, each hit's value its row, the index following every change of a row in the commit that makes it.
TypoTolerance
func TypoTolerance(on bool) OptionTypoTolerance reads a misspelt word as the nearest the index holds, on unless turned off.
QueryOption
type QueryOption interface {
// contains filtered or unexported methods
}QueryOption is how a search reads: Vector, Where, Or, Limit, Offset, Hybrid.
Limit
func Limit(n int) QueryOptionLimit is how many hits a search gives, 10 unless given; Offset and Limit together 1000 at most.
Offset
func Offset(n int) QueryOptionOffset skips the best hits a page before gave.
Range
type Range struct {
Gt, Gte, Lt, Lte any
}Range is a field's number within bounds: nil for a bound not given.
RebuildMode
type RebuildMode boolRebuildMode is when a change of settings that needs the documents read again is read.
Automatic
const (
Automatic RebuildMode = false
Manual RebuildMode = true
)Manual waits for Reindex to read the documents again; Automatic, the default, reads them beside the index at once.
Result
type Result[T any] struct {
Hits []Hit[T]
Corrected string
}Result is what a search found, the best first, and the text it read in fact when a word was misspelt: "" when none was.
SetOption
type SetOption interface {
// contains filtered or unexported methods
}SetOption is what a set says of its document's vector.
NoVector
func NoVector() SetOptionNoVector says the document has none, on an index with vectors: only its words find it.
State
type State stringState is where an index stands.
Ready
const (
Ready State = "ready"
Rebuilding State = "rebuilding"
Failed State = "failed"
)Status
type Status struct {
State State
Done float64
Error string
}Status is where an index stands: ready, rebuilding with how much is Done, or a rebuild that failed and why.
Vectors
type Vectors struct {
Dimensions int
Recall float64
Column string
}Vectors is a vector the program's model gives each document, of these Dimensions, and Recall for searches from clusters, exact without it. A table's index names the Column of blobs that holds them.
Where
type Where map[string]anyWhere keeps a search's hits to the documents whose filters pass, as sqldb's where reads a map: each field equal to its value, one of a slice, within a Range, or nil for none, every field named passing. Or and And group them.
search.Where{"category": []string{"shoes", "boots"}, "price": search.Range{Gte: 10, Lt: 100}}