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

go
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

go
func Reindex(ctx context.Context, store *tinystore.Store, name string, opts ...Option) error

Reindex 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

go
func Vector(v []float32) vector

Vector 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.

AliasesNew in 0.13.1

go
type Aliases map[string]string

Aliases are a document's own words for the whole text of its fields, each alias, one word, with the field's path: search.Aliases{"кмзи": "name"}. A search for one finds the document as a match of that field and marks the field's text; a set without them leaves the document none.

AmongOption

go
type AmongOption interface {
	// contains filtered or unexported methods
}

AmongOption is how one index of a search among several is searched: Boost, Limit, Offset, a Where, Prefix, PrefixEvery, Matches and Snippet. A vector or a Total belong to a search of one index alone.

Boost

go
func Boost(b float64) AmongOption

Boost is what an index's hits weigh in ManyResult.Merged, a positive number, 1 unless given.

Asked

go
type Asked struct {
	// contains filtered or unexported fields
}

Asked is an index a search among several asks, from Among.

AmongNew in 0.13.1

go
func Among[T any](x *Index[T], opts ...AmongOption) Asked

Among is the index x in a search among several, searched as opts say: each of its hits' Value is a T, as a search of x alone reads it. Limit is 10 unless given, Offset and Limit together 1000 at most, and the group's More says whether x has more, its next page at Offset plus Limit.

Counted

go
type Counted struct {
	Count int
	// AtLeast says counting stopped at 10,000, more being there.
	AtLeast bool
}

Counted is how many documents a search finds: exactly, or past 10,000, 10,000 and AtLeast, never an estimate.

Doc

go
type Doc[T any] struct {
	ID       any
	Value    T
	Vector   []float32
	NoVector bool
	Aliases  Aliases
}

Doc is a document SetMany sets: its id, its value, what it says of its vector, and its aliases.

Fields

go
type Fields map[string]float64

Fields 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

go
type Group struct {
	// contains filtered or unexported fields
}

Group is conditions joined: Or's, And's.

And

go
func And(parts ...Where) Group

And is conditions every one of which passes.

Or

go
func Or(parts ...Where) Group

Or is conditions any of which passes.

Hit

go
type Hit[T any] struct {
	ID         string
	Value      T
	Score      float64
	Matches    []Match
	Snippet    *HitSnippet
	TextScore  *float64
	Similarity *float64
}

Hit is a document a search found, and the score that ordered it among this search's hits; Matches says where the search's words matched it, when the search asked with Matches. TextScore is the score its words gave it, as a search by its words alone scores it, nil where they did not find it among their best; Similarity the cosine of its vector with the search's, from -1 to 1, nil where either has none. Snippet is the piece of a field around its first match, when the search asked with Snippet and the hit holds the field.

HitSnippet

go
type HitSnippet struct {
	Text  string
	Marks []Mark
	Item  int
}

HitSnippet is the piece of a field around a hit's first match there: the field's own text, "…" where it was cut, and every match inside it as bytes Start to End of Text. Item is the string's place in a field that holds a list, 0 in one that holds a string. The store adds no markup and escapes nothing.

Hybrid

go
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

go
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

go
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. Change an index by opening it with other options under the same name, and never version its name.

Index.Delete

go
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

go
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

go
func (x *Index[T]) Name() string

Name is the index's name.

Index.Ready

go
func (x *Index[T]) Ready(ctx context.Context) error

Ready waits until the index serves the settings it was opened with; a rebuild that failed is Invalid, saying why.

Index.Search

go
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

go
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

go
func (x *Index[T]) Set(ctx context.Context, id any, value T, opts ...SetOption) error

Set sets the document id to value, replacing it whole; the next search sees it.

Index.SetMany

go
func (x *Index[T]) SetMany(ctx context.Context, docs []Doc[T]) error

SetMany sets every document in one commit, all of them or none. A call holds 1,000 documents at most, limits.SetManyDocuments, and 16 MiB of JSON, limits.SetManyBytes. Past either it fails with a limit error that names the bound.

Index.Status

go
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

go
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

go
func List(ctx context.Context, store *tinystore.Store) ([]Listed, error)

List is every index the store holds, by name.

ManyGroup

go
type ManyGroup struct {
	Index     string
	Hits      []Hit[any]
	More      bool
	Corrected string
	Err       error
}

ManyGroup is an index's hits in a search among several, the best by its own scores first, and More, whether it has hits past its Limit; or Err, why its search failed, and no hit.

ManyResult

go
type ManyResult struct {
	Groups []ManyGroup
	Merged []Merged
}

ManyResult is what a search among several indexes found: a group an index, in the order asked, and every group's hits in one order, Merged, by reciprocal rank fusion and never by score: the hit at rank r of its group, from 1, weighs boost / (60 + r); of equal weights the group asked first comes first, then the higher rank.

ManyNew in 0.13.1

go
func Many(ctx context.Context, home tinystore.Home, text string, among ...Asked) (ManyResult, error)

Many asks text of every index named, 1 to 32, in one call over one connection, each with its own options:

found, err := search.Many(ctx, store, "algebra",
	search.Among(courses, search.Boost(2), search.Limit(5)),
	search.Among(pages, search.Where{"space_id": mine}, search.Limit(5), search.Snippet("plain", 60)),
	search.Among(people, search.Limit(5)))

An index that fails is its group's Err while the others answer; the call fails only when every one does. The store's indexes are searched in one snapshot, a table's index in its database's, and groups of different files are not one moment. An index of another store is refused.

Mark

go
type Mark struct {
	Start int
	End   int
}

Mark is where a search's word matched inside a snippet: Text[Start:End].

Match

go
type Match struct {
	Field string
	Item  int
	Start int
	End   int
	Word  string
}

Match is where a search's word matched a hit: bytes Start to End of a field's text, so that text[m.Start:m.End] is what matched. Field is its path, or a table's column, and "" for a document that is its own text; Item is the string's place in a field that holds a list, 0 in one that holds a string; Word is the query's word, as its text wrote it.

Merged

go
type Merged struct {
	Index string
	Group int
	Hit   *Hit[any]
}

Merged is a hit of ManyResult.Merged: its group's index, the group's place among the groups, and the hit its group holds.

Option

go
type Option interface {
	// contains filtered or unexported methods
}

Option is how an index opens.

FieldNames

go
func FieldNames(paths ...string) Option

FieldNames are fields whose words each weigh 1, in this order.

Filters

go
func Filters(paths ...string) Option

Filters are the fields a search's Where may keep its hits to.

Key

go
func Key(column string, more ...string) Option

Key is a table's column of unique values the index names rows by, or its columns whose values are unique together, Key("space_id", "n"): its primary key unless given. A hit's ID is a key of several columns' values as a JSON array, "[1,6]".

Layouts

go
func Layouts(names ...string) Option

Layouts are the keyboard layouts the index's readers type with, "ru" and "en" for ЙЦУКЕН and QWERTY: a word that finds nothing as typed is read as the same keys type in the other layout, when it finds something there, and Result.Corrected says so.

Rebuild

go
func Rebuild(mode RebuildMode) Option

Rebuild says when a change of settings that needs the documents read again is read.

Table

go
func Table(name string) Option

Table 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

go
func TypoTolerance(on bool) Option

TypoTolerance reads a misspelt word as the nearest the index holds, on unless turned off.

QueryOption

go
type QueryOption interface {
	// contains filtered or unexported methods
}

QueryOption is how a search reads: Vector, Where, Or, Prefix, PrefixEvery, Matches, Snippet, Limit, Offset, Hybrid.

MinSimilarity

go
func MinSimilarity(cosine float64) QueryOption

MinSimilarity is the least cosine, from -1 to 1, a document's vector has with the search's for the Vector to find it: a search by its vector alone leaves out the hits under it, and one by words too adds nothing for them to the sum. Invalid beside a Rerank.

Total

go
func Total() QueryOption

Total has the search count the documents it finds as well, in Result.Total, under its Where and whatever its Limit and Offset: exactly up to 10,000, and past it 10,000 with AtLeast. It reads every posting of its words, which a search alone skips most of; invalid beside a Vector.

Range

go
type Range struct {
	Gt, Gte, Lt, Lte any
}

Range is a field's number within bounds: nil for a bound not given.

RebuildMode

go
type RebuildMode bool

RebuildMode is when a change of settings that needs the documents read again is read.

Automatic

go
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

go
type Result[T any] struct {
	Hits      []Hit[T]
	Corrected string
	Total     *Counted
}

Result is what a search found, the best first, and the text it read in fact when a word was misspelt: "" when none was. Total is how many it finds, when the search asked with Total, and nil otherwise.

SearchOption

go
type SearchOption interface {
	QueryOption
	AmongOption
}

SearchOption is a QueryOption a search among several takes too.

LimitNew in 0.13.1

go
func Limit(n int) SearchOption

Limit is how many hits a search gives, 10 unless given; Offset and Limit together 1000 at most.

MatchesNew in 0.13.1

go
func Matches() SearchOption

Matches has each hit say where the search's words matched it, in Hit.Matches, as a search box shows them in bold: a word found as written, by its stem or once corrected whole, and a word a prefix began by the letters typed.

OffsetNew in 0.13.1

go
func Offset(n int) SearchOption

Offset skips the best hits a page before gave.

Prefix

go
func Prefix() SearchOption

Prefix reads the last word as the start of a word too, as a search box types: "crypt" finds "cryptography" as well, at half its field's weight. A word a space follows is whole, and so is one of a single letter.

PrefixEvery

go
func PrefixEvery() SearchOption

PrefixEvery reads every word as the start of a word too, as people shorten each word of a name: "лин алг" finds "Линейная алгебра". Each word of two letters or more is read so, the first eight, whatever follows it; a document that holds a word for each word of the text comes first, its score raised above the rest. In place of Prefix.

Snippet

go
func Snippet(field string, around int) SearchOption

Snippet has each hit carry the piece of field, a path the index reads, around the field's first match, in Hit.Snippet: its own text from around characters before it to around after it, 1 to 1000 and 80 when 0, cut where a word starts and ends, "…" where text was cut. A hit that matched elsewhere, or by its vector alone, gets the field's first 2 × around characters and no mark.

SetOption

go
type SetOption interface {
	// contains filtered or unexported methods
}

SetOption is what a set says of its document: Vector, NoVector, Aliases.

NoVector

go
func NoVector() SetOption

NoVector says the document has none, on an index with vectors: only its words find it.

State

go
type State string

State is where an index stands.

Ready

go
const (
	Ready      State = "ready"
	Rebuilding State = "rebuilding"
	Failed     State = "failed"
)

Status

go
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. Error beside Ready and Rebuilding is the last maintenance pass's failure while the passes keep failing.

Synonyms

go
type Synonyms map[string]string

Synonyms pair each short form, one word, with the phrase of 1 to 8 words it stands for, search.Synonyms{"ml": "machine learning"}: a search for the short form finds a document that holds the phrase, its words adjacent and in order, and a search for the phrase's words one that holds the short form. They are read when a document is set, so a search pays nothing; other synonyms read an index that holds documents again, and an open without them leaves it none.

Vectors

go
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

go
type Where map[string]any

Where 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. A search's Where holds 8 conditions and 1000 values in its slices at most. For a table's index, a value may be a statement of its database, sqldb.SQL("select user_id from members where course_id = ?", id): one of the values its rows give, read in the search's snapshot, 100,000 at most, counting toward no bound on values; on the table's key no filter is needed.

search.Where{"category": []string{"shoes", "boots"}, "price": search.Range{Gte: 10, Lt: 100}}

Generated from the source Updated 27 November 2026

esc
↑↓ navigate ↵ open ⇥ filter 0 results