Reference / Search API for Bun and Node
Search API for Bun and Node
Every public class, function and type of the Search engine in @tinyshed/tinystore, generated from its source. The Search guide explains how to use them, and the Python, Go and Rust pages list the same API.
IndexOptions
interface IndexOptions {
/** the fields whose words are read, each with what a word found there weighs, or a list that weighs each 1 */
fields?: Record<string, number> | readonly string[] | undefined
/** the fields a search may keep its hits to */
filters?: readonly string[] | undefined
/** a misspelt word read as the index's nearest; on unless false */
typoTolerance?: boolean | undefined
/** a vector the program's model gives each document, and `recall` for searches from clusters */
vectors?: {
dimensions: number
recall?: number | undefined
} | undefined
/** how a search by words and a vector at once combines them unless it says */
hybrid?: {
vectorWeight?: number | undefined
rerank?: boolean | undefined
} | undefined
/** whether a change that needs every document read again waits for `store.reindex` */
rebuild?: 'automatic' | 'manual' | undefined
}How an index reads its documents and combines its halves, given where it opens.
Vector
type Vector = readonly number[] | Float32ArrayA vector the program's own model gave, of the index's dimensions.
WhereValue
type WhereValue = string | number | bigint | boolean | null | readonly (string | number | bigint | boolean)[] | {
gt?: number | bigint
gte?: number | bigint
lt?: number | bigint
lte?: number | bigint
}A value a where matches: text, a number, a boolean, one of a list, a range, or null for none.
Where
type Where = Readonly<Record<string, WhereValue>> | GroupWhat a search keeps its hits to, as sqldb's where reads an object: each
field equal to its value, one of a list, within a range, or null for
none, every field named passing; search.or and search.and group them.
Query
interface Query {
text?: string | undefined
vector?: Vector | undefined
where?: Where | undefined
/** this search's way of combining its words and its vector, in place of the index's */
hybrid?: {
vectorWeight?: number | undefined
rerank?: boolean | undefined
} | undefined
/** 10 unless said; offset and limit together 1000 at most */
limit?: number | undefined
offset?: number | undefined
}What a search asks: its words, its vector, or both, and what it keeps to.
Hit
interface Hit<T> {
id: string
value: T
score: number
}A document a search found, and the score that ordered it among this search's hits.
Found
interface Found<T> {
hits: Hit<T>[]
corrected?: string | undefined
}What a search found, the best first, and the text it read in fact when a word was misspelt.
IndexStatus
type IndexStatus = {
state: 'ready'
} | {
state: 'rebuilding'
done: number
} | {
state: 'failed'
error: string
}Where an index stands: serving what it was opened with, read again beside it, or a rebuild that failed.
IndexInfo
interface IndexInfo {
name: string
documents: number
vectors: number
/** when a program last opened it */
opened?: Date | undefined
status: IndexStatus
}An index as store.indexes() lists it.
TableIndexOptions
interface TableIndexOptions {
/** the table whose rows the index holds and follows */
table: string
/** the column of unique values a row is found by, the table's primary key unless said */
key?: string | undefined
/** the columns whose words are read, each with what a word found there weighs, or a list that weighs each 1 */
fields: Record<string, number> | readonly string[]
/** the columns a search may keep its hits to; a boolean is the 1 or 0 SQLite keeps */
filters?: readonly string[] | undefined
typoTolerance?: boolean | undefined
/** a column of blobs of little-endian floats, one a row or null, and `recall` for searches from clusters */
vectors?: {
column: string
dimensions: number
recall?: number | undefined
} | undefined
hybrid?: {
vectorWeight?: number | undefined
rerank?: boolean | undefined
} | undefined
rebuild?: 'automatic' | 'manual' | undefined
}How a table's index reads a table of its database: its columns of text, those a search may filter by, and a column of vectors the program fills.
IndexDocument
interface IndexDocument<T> {
id: Key
value: T
vector?: Vector | null | undefined
}A document setMany sets: its id, its value, and its vector, or null for none.
SearchIndex
class SearchIndex<T> extends Searchable<T> {}Documents of one type by id, found again by their words, vectors or both: store.index(name, options).
SearchIndex.set
set(id: Key, value: T, options?: {
vector?: Vector | null | undefined
}): Promise<void>Sets the document id to value, replacing it whole; the next search
sees it. On an index with vectors a set gives its vector, or null for
a document only its words find.
SearchIndex.setMany
setMany(documents: readonly IndexDocument<T>[]): Promise<void>Sets every document in one commit, all of them or none: 1,000 and 16 MiB at most.
SearchIndex.delete
delete(id: Key): Promise<boolean>Deletes the document id; says whether there was one.
SearchIndex.get
get(id: Key): Promise<T | undefined>The document id, or undefined.
TableIndex
class TableIndex<T> extends Searchable<T> {}A table's rows found again by their words, vectors or both, each hit's
value its row as db.all reads it: db.searchIndex(name, options). The
table owns the rows, and every change of one reaches the index in the
commit that makes it.
search
const search: {
or: (...parts: Where[]) => Group
and: (...parts: Where[]) => Group
}The conditions a where groups: search.or({ category: 'boots' }, { tags: 'sale' }).