Reference / Search API for Python
Search API for Python
Every public class, function and type of the Search engine in tinystore, generated from its source. The Search guide explains how to use them, and the Bun and Node, Go and Rust pages list the same API.
Vectors
@dataclass(frozen=True, slots=True)
class Vectors:
dimensions: int
recall: float | None = None
column: str | None = NoneA vector the program's model gives each document, and recall for searches from clusters.
A table's index names the column of blobs that holds them.
Hybrid
@dataclass(frozen=True, slots=True)
class Hybrid:
vector_weight: float | None = None
rerank: bool | None = NoneHow a search by words and a vector at once combines them: a vector weight, or the words' best reranked.
Hit
@dataclass(frozen=True, slots=True)
class Hit[T]:
id: str
value: T
score: floatA document a search found, and the score that ordered it among this search's hits.
Result
@dataclass(frozen=True, slots=True)
class Result[T]:
hits: list[Hit[T]]
corrected: str | None = NoneWhat a search found, the best first, and the text it read in fact when a word was misspelt.
IndexStatus
@dataclass(frozen=True, slots=True)
class IndexStatus:
state: Literal['ready', 'rebuilding', 'failed']
done: float = 0.0
error: str = ''Where an index stands: ready, rebuilding with how much is done, or a rebuild that failed and why.
IndexInfo
@dataclass(frozen=True, slots=True)
class IndexInfo:
name: str
documents: int
vectors: int
opened: datetime | None # when a program last opened it
status: IndexStatusAn index as store.indexes() lists it.
SearchIndex
class SearchIndex[T](_Searchable[T]):
...Documents of one type by id, found again by their words, vectors or both: store.index(name, Article).
SearchIndex.set
async def set(id: Key, value: T, *, vector: Vector | None = _UNSET) -> None: ...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 None for a document only its words find.
SearchIndex.set_many
async def set_many(
documents: Sequence[tuple[Key, T] | tuple[Key, T, Vector | None]],
) -> None: ...Sets every document in one commit, all of them or none: (id, value) or (id, value, vector), 1,000 at most.
SearchIndex.delete
async def delete(id: Key) -> bool: ...Deletes the document id; says whether there was one.
SearchIndex.get
async def get(id: Key) -> T | None: ...The document id, or None.
TableIndex
class TableIndex[T](_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.
The table owns the rows, and every change of one reaches the index in the commit that makes it.