Reference / Search API for Rust
Search API for Rust
Every public type, trait and function of the Search engine in tinystore::search and tinystore::aio::search, generated from its source. The Search guide explains how to use them, and the Bun and Node, Python and Go pages list the same API.
Store
impl StoreStore.searchNew in 0.13.1
pub fn search(&self, text: &str) -> ManySearch<'_>One question asked of several indexes in one call, each named with
among and its own options, run by
run:
use tinystore::search::eq;
let found = store
.search("algebra")
.among(&courses, |a| a.boost(2.0).limit(5))
.among(&pages, |a| a.filter(eq("space_id", &7)).limit(5).snippet("plain", 60))
.among(&people, |a| a.limit(5))
.run()?;
for merged in &found.merged {
println!("{} {}", merged.index, merged.hit.id);
}Each group holds its index's best by its own scores, and says whether
it has more; merged holds them merged by
reciprocal rank fusion, since scores of two indexes cannot be compared. An index that
fails is its group's error, and the others answer; the call fails
only when every group does, or when its cancel or its timeout stops
it, Cancelled whichever group it reached. The store's indexes of documents are
searched in one snapshot of search.db, so that no write lands between
two of their groups; a table's index is searched in a snapshot of its
database's file, and groups from different files are not one moment.
Store.index
pub fn index<T: Serialize + DeserializeOwned>(&self, name: &str) -> IndexBuilder<'_, T>The index name, made the first time it opens: documents of type
T set by id and found again by their words, their vectors or both.
Store.drop_index
pub fn drop_index(&self, name: &str) -> Result<bool>Drops the index name and every document it holds, in the background,
and says whether there was one; a handle of it is refused from then
on, and opening the name again makes a new index. An index no program
opens any more is kept until it is dropped, since another version of
the program may open it again.
aio::Store
impl aio::Storeaio::Store.index
pub fn index<T: Serialize + DeserializeOwned>(&self, name: &str) -> IndexBuilder<'_, T>The index name, made the first time it opens, as
crate::Store::index opens one: its builder and its open are plain
calls, and the index's calls are awaited.
aio::Store.drop_index
pub fn drop_index(&self, name: &str) -> impl Future<Output = Result<bool>> + Send + 'staticDrops the index name and every document it holds, as
crate::Store::drop_index does, on the store's pool: the drop
waits for the sets in flight, and once polled it runs to its end.
Maintenance
pub struct Maintenance {
pub packed: u64,
pub purged: u64,
}What one pass of maintenance did.
Condition
pub struct Condition(_)A condition of a search, given to SearchCall::filter.
Values
pub trait ValuesWhat is_in keeps a filter to: a list of values, &["shoes", "boots"]
or &ids, or for a table's index a statement of its database, sql!(…).
and
pub fn and(conditions: impl IntoIterator<Item = Condition>) -> ConditionEvery one of conditions, for a group inside an or; an empty and
passes everything.
eq
pub fn eq<T: Serialize + ?Sized>(path: &str, value: &T) -> ConditionA filter equal to value: a document passes when it holds it, or one of
its list is it. Values match exactly, case and type: the text "50" is not
the number 50, and 42.0 is 42. None is invalid, so that an absent id
never asks for documents without one; missing asks for those.
is_in
pub fn is_in(path: &str, values: impl Values) -> ConditionA filter holding one of values, as SQL's in (…); an empty list passes
nothing. A search's filter holds 8 conditions and 1000 values in its lists
at most.
For a table's index, values may be a statement of its database that
gives one column, as SQL's in (select …): is_in("id", sql!("select user_id from members where course_id = ?", course)). Its rows are read
in the snapshot the search reads, 100,000 at most, and count toward no
bound on values; on the table's key the column needs no filter.
missing
pub fn missing(path: &str) -> ConditionA filter with no value: no such field, null or an empty list.
or
pub fn or(conditions: impl IntoIterator<Item = Condition>) -> ConditionAny of conditions, in parentheses; an empty or passes nothing.
range
pub fn range<T: Serialize>(path: &str, bounds: impl RangeBounds<T>) -> ConditionA filter holding a number within bounds, any of Rust's ranges:
range("price", 10..100) holds 10 and not 100, range("at", since..).
A document with no number there never passes. Numbers compare as f64,
so whole numbers past 2⁵³ compare by the nearest f64, where eq is
exact.
Doc
pub struct Doc<'v, T> { /* private fields */ }A document Index::set_many sets, with what it says of its vector and
its aliases: Doc::new("1", &course).aliases([("кмзи", "name")]).
Doc.new
pub fn new(id: impl Key, value: &'v T) -> SelfThe document id of value, saying nothing of its vector, with no
alias.
Doc.vector
pub fn vector(self, vector: &'v [f32]) -> SelfAs DocumentCall::vector.
Doc.without_vector
pub fn without_vector(self) -> SelfAs DocumentCall::without_vector.
Doc.aliases
pub fn aliases<W: AsRef<str>, F: AsRef<str>>(self, pairs: impl IntoIterator<Item = (W, F)>) -> SelfAs DocumentCall::aliases.
Document
pub trait Document<'v, T>A document as Index::set_many takes it: (id, &value), or on an index
with vectors (id, &value, &vector[..]) and (id, &value, None); or a
Doc, which says its aliases too.
Document.parts
fn parts(self) -> (String, &'v T, Option<Option<&'v [f32]>>)Its id, its value, and its vector: None when it says nothing of one,
Some(None) when it has none.
Document.aliased
fn aliased(&self) -> Vec<(String, String)>Its aliases, each a word and the path of the field it stands for; none unless it says.
DocumentCall
pub struct DocumentCall<'a, T> { /* private fields */ }A set of one document with its vector or its aliases, run by
DocumentCall::set.
DocumentCall.vector
pub fn vector(self, vector: &'a [f32]) -> SelfThe document's vector, which the program's own model gave it: of the index's dimensions, every number finite and not all zeros.
DocumentCall.without_vector
pub fn without_vector(self) -> SelfThe document has no vector, and only its words find it.
DocumentCall.aliases
pub fn aliases<W: AsRef<str>, F: AsRef<str>>(self, pairs: impl IntoIterator<Item = (W, F)>) -> SelfThe document's aliases: each a word that stands for the whole text of
one of its fields, in this document alone, by the field's path, as
[("кмзи", "name")]. A search for the word finds the document as a
match of that field, and its matches mark the field's text. One word
of 64 bytes each, 64 at most; a set without them leaves the document
none.
let courses = store.index::<serde_json::Value>("courses").field("name", 1.0).open()?;
let course = serde_json::json!({ "name": "Криптографические методы защиты информации" });
courses.id("1").aliases([("кмзи", "name")]).set(&course)?;
let found = courses.search("кмзи").matches().run()?; // "1", its name marked wholeDocumentCall.set
pub fn set(self, value: &T) -> Result<()>Sets the document to value, replacing it whole, its words, its
aliases and its vector; the next search sees it.
Found
pub struct Found<T> {
pub hits: Vec<Hit<T>>,
pub corrected: Option<String>,
pub total: Option<Total>,
}What a search found, the best first, the text it read in fact when it
read a misspelt word as the index's nearest, and how many it finds in all
when it asked with total.
Hit
pub struct Hit<T> {
pub id: String,
pub value: T,
pub score: f64,
pub matches: Vec<Match>,
pub snippet: Option<Snippet>,
pub text_score: Option<f64>,
pub similarity: Option<f64>,
}A document a search found, and the score that ordered it: a score orders one search's hits and means nothing beside another's. Of a search by words and a vector, each half's own score says how near it was, as the sum cannot: a document the vector found least near still has its half's whole weight in the sum when that half found nothing nearer.
Index
pub struct Index<T> { /* private fields */ }Documents of type T by id in a named index, found again by their words,
their vectors or both.
Index.name
pub fn name(&self) -> &strIndex.status
pub fn status(&self) -> Result<Status>Where the index stands: serving the settings it was opened with, read again beside them and how far, or a rebuild that failed and why; and beside the first two, a maintenance pass that keeps failing. A search never waits: it answers by the settings the index serves.
Index.ready
pub fn ready(&self) -> Result<()>Waits until the index serves the settings it was opened with: at once
when no rebuild is under way, and an error naming why when one failed.
A store opened without background work runs maintain
itself meanwhile.
Index.search
pub fn search(&self, text: &str) -> SearchCall<'_, T>A search by text's words: a document needs any of them, not all,
and the best ten come first unless the search says otherwise. Of
equal scores the document set first comes first, so pages of one
search join without a hit twice. With a vector
it searches by both.
Index.search_vector
pub fn search_vector<'i>(&self, vector: &'i [f32]) -> SearchCall<'i, T>A search by vector alone, which the program's model gave the
question: the exact best by their cosine with it, which is each
hit's score. A document without a vector is never found by one.
Index.set
pub fn set(&self, id: impl Key, value: &T) -> Result<()>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
says it has none, through id.
Index.id
pub fn id(&self, id: impl Key) -> DocumentCall<'_, T>A set of the document id with its vector or its aliases, run by its
last step: products.id("p-3").vector(&embedding).set(&product).
Index.set_many
pub fn set_many<'v>(&self, documents: impl IntoIterator<Item = impl Document<'v, T>>) -> Result<()>
where
T: 'v,Sets each document to its value, all of them in one commit or none:
(id, &value), or on an index with vectors (id, &value, &vector),
and in a list where some have none (id, &value, Some(&vector[..]))
and (id, &value, None); a Doc says its aliases too. A refused
one names its place in the list
and its id. A call holds 1,000 documents and 16 MiB of them as JSON
at most, SET_MANY_DOCUMENTS and SET_MANY_BYTES; a larger
import goes in calls of that size.
Index.delete
pub fn delete(&self, id: impl Key) -> Result<bool>Deletes the document id; says whether there was one.
Index.get
pub fn get(&self, id: impl Key) -> Result<Option<T>>The document id, or none.
IndexBuilder
pub struct IndexBuilder<'s, T> { /* private fields */ }What Store::index opens: an index's settings, given where it opens.
IndexBuilder.field
pub fn field(self, path: &str, weight: f64) -> SelfA field whose text is read, by its path into the document, author.name
for a field of a field, and what a word found there weighs: a word in
a field of 2 scores twice what it would in a field of 1. An index of
no field reads a document that is a string as its text.
IndexBuilder.fields
pub fn fields<S: AsRef<str>>(self, paths: impl IntoIterator<Item = S>) -> SelfFields that each weigh 1.
IndexBuilder.filters
pub fn filters<S: AsRef<str>>(self, paths: impl IntoIterator<Item = S>) -> SelfThe fields a search may keep its hits to, each a path into the document whose value is text, a number, a boolean or a list of them; the index keeps their values and no other field's.
IndexBuilder.typo_tolerance
pub fn typo_tolerance(self, on: bool) -> SelfWhether a misspelt word is read as the index's nearest: on unless turned off.
IndexBuilder.layouts
pub fn layouts<S: AsRef<str>>(self, names: impl IntoIterator<Item = S>) -> SelfThe keyboard layouts the index's readers type with, ["ru", "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 corrected says so: rhbgnj reads as крипто. None
unless said; ru and en are the layouts known.
IndexBuilder.synonyms
pub fn synonyms<S: AsRef<str>, P: AsRef<str>>(self, pairs: impl IntoIterator<Item = (S, P)>) -> SelfPairs each short form, one word, with the phrase of 1 to 8 words it
stands for, both ways: ("кмзи", "криптографические методы защиты информации"). A search for the short form finds a document whose
field holds the phrase, its words adjacent and in order by their
stems, and a search for the phrase's words finds one that holds the
short form; matches and snippets mark the text that stands there.
The words are read when a document is set, so a search pays nothing,
and they count in no field's length. At most 1,000 pairs, a short
form of 64 bytes at most; other synonyms on an index that holds
documents read them again, as a field added does. An open without
them leaves the index none.
IndexBuilder.vectors
pub fn vectors(self, dimensions: usize) -> SelfKeeps a vector of dimensions numbers with each document, which the
program's own model gives it, and finds documents by their cosine
with a search's.
IndexBuilder.recall
pub fn recall(self, recall: f64) -> SelfSearches by a vector read the clusters nearest their question rather
than every vector, and find recall of the exact ten on average,
from above 0 to below 1: the clusters are built in the background,
and searches stay exact until then. How many clusters a search reads
is the index's to choose, from questions drawn from its own vectors.
IndexBuilder.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfWhat a vector weighs against the words in a search by both, from 0, the words alone, to 1, the vector alone; 0.5 unless set, and a search may give its own.
IndexBuilder.rerank
pub fn rerank(self) -> SelfMakes a search by both order the hits of its words by their vectors, finding nothing its words do not, unless it gives a weight.
IndexBuilder.rebuild
pub fn rebuild(self, rebuild: Rebuild) -> SelfWhether a change of settings that needs the index read again begins
by itself, as it does unless said, or waits for reindex,
for a program that schedules its own load.
IndexBuilder.open
pub fn open(self) -> Result<Index<T>>Opens the index, made the first time. An index that holds other settings is changed to these, each change said in the log: a weight, a field or a filter removed, typo tolerance, vectors added, recall and how a search by both combines them at once; a field or a filter added to an index that holds documents by reading them again beside it, in the background, the index answering as before until then. Vectors of other dimensions, or none where it keeps some, are refused. Opening never waits for the work a change needs. Change an index by opening it with other options under the same name, and never version its name.
IndexBuilder.reindex
pub fn reindex(self) -> Result<Index<T>>Opens the index as open does, and reads it again
beside itself in the background: a change Rebuild::Manual left
waiting, or the documents numbered again.
Rebuild
pub enum Rebuild {
Automatic,
Manual,
}Whether a change of an index's settings that needs it read again begins
by itself or waits for IndexBuilder::reindex.
SearchCall
pub struct SearchCall<'i, T> { /* private fields */ }A search of an index, run by SearchCall::run.
SearchCall.vector
pub fn vector(self, vector: &'i [f32]) -> SelfSearches by vector too, which the program's model gave the question:
each half's best hundred, or offset + limit if more, their scores
each scaled to 0–1 by its own lowest and highest, 0 where the other
half did not find a document, and summed at the index's vector
weight; a hit's score is that sum. Pages join within the first
hundred, where both halves stay the same; past it each page's halves
are longer, and their sums may order it otherwise.
SearchCall.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfWhat the vector weighs in this search, in place of the index's: from 0, the search by its words alone, to 1, by its vector alone, each with its own scores.
SearchCall.rerank
pub fn rerank(self) -> SelfOrders the hundred best of the search's words by their vectors' cosines with its vector, finding nothing the words do not; a hit without a vector comes after those with one, scored −1.
SearchCall.min_similarity
pub fn min_similarity(self, cosine: f64) -> SelfThe least cosine, from −1 to 1, that a document's vector has with the
search's for the vector to find it: of a search by its vector alone,
the hits under it are left out; of one by words too, a document under
it adds nothing to the sum and comes by its words or not at all,
where without the floor the least near of the vector's best would
still be scaled into the sum. invalid beside a rerank.
SearchCall.prefix
pub fn prefix(self) -> SelfReads the text's last word as the start of a word too, as a search
box does while its reader types: crypt finds cryptography as
well, at half its field's weight. A word followed by a space or a
mark is whole, and so is one of a single letter.
SearchCall.prefix_every
pub fn prefix_every(self) -> SelfReads every word of the text as the start of a word too, as people
shorten each word of a name: лин алг finds Линейная алгебра, at
half its field's weight. 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 before any that does not, its score
raised by the most any other could score, so that scores descend
down the page. In place of prefix.
SearchCall.matches
pub fn matches(self) -> SelfSays in each hit's matches where the search's words
matched it, as a search box shows them in bold: in each field, the
bytes of its text that a word matched as written, by its stem or once
corrected, and the letters typed of a word a prefix began, each with
the query's word that found it. алгебре matches алгебра of
Линейная алгебра, bytes 17..31.
SearchCall.snippet
pub fn snippet(self, field: &str, around: usize) -> SelfCuts each hit's snippet of field, a path the index
reads as IndexBuilder::field names it: its own text from around
characters before the field's first match to around after it, 1 to
1,000 and 80 a fair choice, cut where a word starts and where one
ends and never inside a character, … where text was cut; its marks
are every match inside it, as bytes of its text. A hit that matched
elsewhere, or by its vector alone, gets the field's first 2 × around characters and no mark; one whose document lacks the field,
none. Only the page's hits are cut, and the store adds no markup.
SearchCall.filter
pub fn filter(self, condition: Condition) -> SelfKeeps its hits to the documents condition passes, and to those
every earlier one passes: .filter(search::eq("owner_id", &42)),
.filter(search::is_in("category", &["shoes", "boots"])). It answers
the best of those, scored by the words of the whole index, never the
best of all with the others taken out after.
SearchCall.total
pub fn total(self) -> SelfCounts the documents it finds as well, in Found::total: each one
its words find, as it read them, that its filters pass, exactly up to
10,000, and past it 10,000 with at_least. Counting reads every
posting of its words, most of which a search alone skips. invalid
beside a vector, which finds every document that has one.
SearchCall.limit
pub fn limit(self, limit: usize) -> SelfThe hits it answers, 10 unless it says.
SearchCall.offset
pub fn offset(self, offset: usize) -> SelfThe hits it passes before the first it answers.
SearchCall.run
pub fn run(self) -> Result<Found<T>>Total
pub struct Total {
pub count: u64,
pub at_least: bool,
}How many documents a search finds, under its filters and whatever its
limit and offset: exactly up to 10,000, and past it 10,000 with
at_least, never an estimate.
Among
pub struct Among { /* private fields */ }What a group of a ManySearch asks of its index, as a search of it
alone would: the text is the call's.
Among.boost
pub fn boost(self, boost: f64) -> SelfWhat the group's hits weigh in ManyFound::merged, a positive number,
1 unless said: a hit of a group of 2 weighs what a hit of half its
rank would in a group of 1, near enough.
Among.limit
pub fn limit(self, limit: usize) -> SelfThe hits the group answers, 10 unless said, offset and limit
together 1000 at most; its more says whether the
index has more.
Among.offset
pub fn offset(self, offset: usize) -> SelfThe hits the group passes before the first it answers, as
SearchCall::offset: the next page of
a group whose more was true is the same group at offset + limit.
Among.filter
pub fn filter(self, condition: Condition) -> SelfAs SearchCall::filter.
Among.prefix
pub fn prefix(self) -> SelfAs SearchCall::prefix.
Among.prefix_every
pub fn prefix_every(self) -> SelfAs SearchCall::prefix_every.
Among.matches
pub fn matches(self) -> SelfAs SearchCall::matches.
Among.snippet
pub fn snippet(self, field: &str, around: usize) -> SelfAs SearchCall::snippet.
Group
pub struct Group<V> {
pub index: String,
pub hits: Vec<Hit<V>>,
pub more: bool,
pub corrected: Option<String>,
pub error: Option<Error>,
}An index's hits in a ManySearch, the best by its own scores first, or
why its search failed.
ManyFound
pub struct ManyFound {
pub groups: Vec<Group>,
pub merged: Vec<Merged>,
}What a ManySearch found: a group an index, in the order asked, and
every group's hits in one order.
ManySearch
pub struct ManySearch<'s> { /* private fields */ }One question asked of several indexes, run by ManySearch::run.
ManySearch.amongNew in 0.13.1
pub fn among(self, index: &impl Searched, options: impl FnOnce(Among) -> Among) -> SelfAsks index too, its search as options says: |a| a.limit(5). The
same index may be asked twice, with another filter.
ManySearch.runNew in 0.13.1
pub fn run(self) -> Result<ManyFound>Searches every index asked, 1 to 32, each group in the order asked.
Merged
pub struct Merged {
pub index: String,
pub group: usize,
pub hit: Hit<Value>,
}A hit of ManyFound::merged: its group's index, the group's place among
the groups, and the hit as its group holds it.
Searched
pub trait SearchedAn index a ManySearch asks: an index of documents or a table's, each
hit's value its document or its row as JSON, since the indexes of one
call keep values of different types. A table's index reads each row as
its type and writes it as JSON again, so that type is Serialize too.
Match
pub struct Match {
pub field: String,
pub item: Option<usize>,
pub at: Range<usize>,
pub word: String,
}Where a search's word matched a hit: a range of a field's text, and the
query's word that found it. &text[at.clone()] is the whole word for a
word found as written, by its stem or once corrected, and the letters
typed for a word a prefix began.
Status
pub enum Status {
Ready { error: Option<String> },
Rebuilding { done: f64, error: Option<String> },
Failed { error: String },
}Where an index stands: serving the settings it was opened with, read again beside them, or a rebuild that stopped.
error, beside Ready and Rebuilding, is the last maintenance pass's
failure, a merge on a full disk, while the passes keep failing; None
once one passes. The index still answers searches meanwhile.
Listed
pub struct Listed {
pub name: String,
pub documents: u64,
pub vectors: u64,
pub opened: Option<SystemTime>,
pub status: Status,
}An index as search::list says it.
Snippet
pub struct Snippet {
pub text: String,
pub marks: Vec<Range<usize>>,
pub item: Option<usize>,
}The piece of a field around the first place a search's words matched a hit, with every match inside it.
text "…Then linear algebra took three weeks of…"
marks [13..20], counted as the search's matches are: bytes in RustColumns
pub trait ColumnsWhat TableIndexBuilder::key takes: a column, "slug", or columns,
["space_id", "n"].
TableIndex
pub struct TableIndex<T> { /* private fields */ }The rows of a table found again by their words, their vectors or both; a hit's value is its row, read in the snapshot its search read.
TableIndex.name
pub fn name(&self) -> &strTableIndex.search
pub fn search(&self, text: &str) -> SearchCall<'_, T>A search by text's words, as Index::search makes one; each
hit's id is its row's key and its value the row.
TableIndex.search_vector
pub fn search_vector<'i>(&self, vector: &'i [f32]) -> SearchCall<'i, T>A search by vector alone, as Index::search_vector makes one.
TableIndex.status
pub fn status(&self) -> Result<Status>Where the index stands: ready, reading the table's rows the first time or again beside itself and how far, or a rebuild that failed.
TableIndex.ready
pub fn ready(&self) -> Result<()>Waits until the index has read its table's rows and serves the settings it was opened with.
TableIndexBuilder
pub struct TableIndexBuilder<T> { /* private fields */ }What db.search_index opens: an index's table and its settings.
TableIndexBuilder.table
pub fn table(self, table: &str) -> SelfThe table whose rows the index holds and follows from then on.
TableIndexBuilder.key
pub fn key(self, columns: impl Columns) -> SelfThe column of unique values a row is found by, or the columns whose
values are unique together, key(["space_id", "n"]): the table's
primary key unless said. A hit's id is the value of a key of one
column as text, and the values of a key of several as a JSON array,
[1,6] or ["NW",6].
TableIndexBuilder.field
pub fn field(self, column: &str, weight: f64) -> SelfA column whose text is read, and what a word found there weighs: a word in a column of 2 scores twice what it would in a column of 1.
TableIndexBuilder.fields
pub fn fields<S: AsRef<str>>(self, columns: impl IntoIterator<Item = S>) -> SelfColumns that each weigh 1.
TableIndexBuilder.filters
pub fn filters<S: AsRef<str>>(self, columns: impl IntoIterator<Item = S>) -> SelfThe columns a search may keep its hits to, each holding text, a number, or a boolean as SQLite keeps one, 1 or 0.
TableIndexBuilder.typo_tolerance
pub fn typo_tolerance(self, on: bool) -> SelfWhether a misspelt word is read as the index's nearest: on unless turned off.
TableIndexBuilder.layouts
pub fn layouts<S: AsRef<str>>(self, names: impl IntoIterator<Item = S>) -> SelfAs IndexBuilder::layouts.
TableIndexBuilder.synonyms
pub fn synonyms<S: AsRef<str>, P: AsRef<str>>(self, pairs: impl IntoIterator<Item = (S, P)>) -> SelfAs IndexBuilder::synonyms, each
phrase found in the columns the index reads.
TableIndexBuilder.vectors
pub fn vectors(self, column: &str, dimensions: usize) -> SelfReads each row's vector from column: a blob of dimensions
little-endian floats that the program's own model gave it, or null
for a row without one. The store runs no model: a changed text keeps
its row's vector until the program writes another.
TableIndexBuilder.recall
pub fn recall(self, recall: f64) -> SelfAs IndexBuilder::recall.
TableIndexBuilder.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfAs IndexBuilder::vector_weight.
TableIndexBuilder.rerank
pub fn rerank(self) -> SelfAs IndexBuilder::rerank.
TableIndexBuilder.rebuild
pub fn rebuild(self, rebuild: Rebuild) -> SelfAs IndexBuilder::rebuild.
TableIndexBuilder.open
pub fn open(self) -> Result<TableIndex<T>>Opens the index, made the first time: its triggers put on the table,
and its rows read in the background, which TableIndex::ready
waits for. Other settings change it as IndexBuilder::open
says; another table or key is read beside it, the old table's rows
answering and taking its writes until the new table is read whole and
switches in.
TableIndexBuilder.reindex
pub fn reindex(self) -> Result<TableIndex<T>>Opens the index as open does, and reads it again
beside itself in the background.
TxTableIndex
pub struct TxTableIndex<'a, T> { /* private fields */ }A table's index's searches inside a transaction of its database, from
tx.with(&index): they see what the transaction wrote.
TxTableIndex.search
pub fn search(&self, text: &str) -> SearchCall<'a, T>TxTableIndex.search_vector
pub fn search_vector(&self, vector: &'a [f32]) -> SearchCall<'a, T>list
pub fn list(store: &Store) -> Result<Vec<Listed>>Every index the store's search.db holds, by name: its documents and
vectors, when a program last opened it, and whether a rebuild is under
way.
maintain
pub fn maintain(store: &Store) -> Result<Maintenance>Runs the store's search maintenance now, as a store opened without background work has to: each index's segments merged into one and the documents gone purged, in search.db and in each database a table's index was opened in, and a table's rows read the first time.
aio::search::list
pub fn list(store: &Store) -> impl Future<Output = Result<Vec<Listed>>> + Send + 'staticEvery index the store's search.db holds, by name, as
crate::search::list reads them, on the store's pool.
aio::search::IndexBuilder
pub struct IndexBuilder<'s, T> { /* private fields */ }What Store::index opens: an index's settings, given where it opens.
aio::search::IndexBuilder.field
pub fn field(self, path: &str, weight: f64) -> SelfAs crate::search::IndexBuilder::field.
aio::search::IndexBuilder.fields
pub fn fields<S: AsRef<str>>(self, paths: impl IntoIterator<Item = S>) -> SelfAs crate::search::IndexBuilder::fields.
aio::search::IndexBuilder.filters
pub fn filters<S: AsRef<str>>(self, paths: impl IntoIterator<Item = S>) -> SelfAs crate::search::IndexBuilder::filters.
aio::search::IndexBuilder.typo_tolerance
pub fn typo_tolerance(self, on: bool) -> SelfAs crate::search::IndexBuilder::typo_tolerance.
aio::search::IndexBuilder.layouts
pub fn layouts<S: AsRef<str>>(self, names: impl IntoIterator<Item = S>) -> SelfAs crate::search::IndexBuilder::layouts.
aio::search::IndexBuilder.synonyms
pub fn synonyms<S: AsRef<str>, P: AsRef<str>>(self, pairs: impl IntoIterator<Item = (S, P)>) -> SelfAs crate::search::IndexBuilder::synonyms.
aio::search::IndexBuilder.vectors
pub fn vectors(self, dimensions: usize) -> SelfAs crate::search::IndexBuilder::vectors.
aio::search::IndexBuilder.recall
pub fn recall(self, recall: f64) -> SelfAs crate::search::IndexBuilder::recall.
aio::search::IndexBuilder.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfAs crate::search::IndexBuilder::vector_weight.
aio::search::IndexBuilder.rerank
pub fn rerank(self) -> SelfAs crate::search::IndexBuilder::rerank.
aio::search::IndexBuilder.rebuild
pub fn rebuild(self, rebuild: Rebuild) -> SelfAs crate::search::IndexBuilder::rebuild.
aio::search::IndexBuilder.open
pub fn open(self) -> Result<Index<T>>Opens the index as crate::search::IndexBuilder::open does: a plain
call, made once at start, which never waits for the work a change of
its settings needs.
aio::search::IndexBuilder.reindex
pub fn reindex(self) -> Result<Index<T>>Opens the index as open does, and reads it again
beside itself in the background, as
crate::search::IndexBuilder::reindex does.
aio::search::Index
pub struct Index<T> { /* private fields */ }Documents of type T by id in a named index, found again by their words,
their vectors or both, its calls awaited: the same index as
crate::search::Index, and the same again through From and
blocking.
aio::search::Index.blocking
pub fn blocking(&self) -> &Index<T>The same index, for its blocking calls.
aio::search::Index.name
pub fn name(&self) -> &straio::search::Index.status
pub fn status(&self) -> impl Future<Output = Result<Status>> + Send + 'staticWhere the index stands, as crate::search::Index::status reads it,
on the store's pool.
aio::search::Index.ready
pub fn ready(&self) -> impl Future<Output = Result<()>> + Send + 'staticWaits until the index serves the settings it was opened with, as
crate::search::Index::ready does, holding no thread: woken as its
rebuild switches in or fails, and looking at its status again on the
store's pool every tenth of a second. Dropped, it stops waiting, and
the rebuild goes on. On a store opened without background work it
runs the maintenance itself, a pass at a time on the store's pool,
and a pass it began runs to its end.
aio::search::Index.search
pub fn search(&self, text: &str) -> SearchCall<'_, T>A search by text's words, as crate::search::Index::search makes
one, run by its awaited run.
aio::search::Index.search_vector
pub fn search_vector<'i>(&self, vector: &'i [f32]) -> SearchCall<'i, T>A search by vector alone, as crate::search::Index::search_vector
makes one.
aio::search::Index.get
pub fn get(&self, id: impl Key) -> impl Future<Output = Result<Option<T>>> + Send + 'staticThe document id, or none, as crate::search::Index::get reads it:
a point read, tried in the future's first poll.
aio::search::Index.set
pub fn set(&self, id: impl Key, value: &T) -> impl Future<Output = Result<()>> + Send + 'staticSets the document id to value, replacing it whole, as
crate::search::Index::set does; the next search sees it once the
future is ready. On an index with vectors a set gives its vector, or
says it has none, through id.
aio::search::Index.id
pub fn id(&self, id: impl Key) -> DocumentCall<'_, T>A set of the document id with its vector or its aliases, run by its
awaited last step: products.id("p-3").vector(&embedding).set(&product).await.
aio::search::Index.set_many
pub fn set_many<'v>(
&self,
documents: impl IntoIterator<Item = impl Document<'v, T>>,
) -> impl Future<Output = Result<()>> + Send + 'static
where
T: 'v,Sets each document to its value, all of them in one commit or none,
as crate::search::Index::set_many does.
aio::search::Index.delete
pub fn delete(&self, id: impl Key) -> impl Future<Output = Result<bool>> + Send + 'staticDeletes the document id, as crate::search::Index::delete does;
says whether there was one.
aio::search::DocumentCall
pub struct DocumentCall<'a, T> { /* private fields */ }A set of one document with its vector or its aliases, run by
DocumentCall::set.
aio::search::DocumentCall.vector
pub fn vector(self, vector: &'a [f32]) -> SelfAs crate::search::DocumentCall::vector.
aio::search::DocumentCall.without_vector
pub fn without_vector(self) -> SelfAs crate::search::DocumentCall::without_vector.
aio::search::DocumentCall.aliases
pub fn aliases<W: AsRef<str>, F: AsRef<str>>(self, pairs: impl IntoIterator<Item = (W, F)>) -> SelfAs crate::search::DocumentCall::aliases.
aio::search::DocumentCall.set
pub fn set(self, value: &T) -> impl Future<Output = Result<()>> + Send + 'staticSets the document to value, its words, its aliases and its vector,
as crate::search::DocumentCall::set does.
aio::search::SearchCall
pub struct SearchCall<'i, T> { /* private fields */ }A search of an index, run by its awaited SearchCall::run.
aio::search::SearchCall.vector
pub fn vector(self, vector: &'i [f32]) -> SelfAs crate::search::SearchCall::vector.
aio::search::SearchCall.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfAs crate::search::SearchCall::vector_weight.
aio::search::SearchCall.rerank
pub fn rerank(self) -> SelfAs crate::search::SearchCall::rerank.
aio::search::SearchCall.min_similarity
pub fn min_similarity(self, cosine: f64) -> SelfAs crate::search::SearchCall::min_similarity.
aio::search::SearchCall.prefix
pub fn prefix(self) -> SelfAs crate::search::SearchCall::prefix.
aio::search::SearchCall.prefix_every
pub fn prefix_every(self) -> SelfAs crate::search::SearchCall::prefix_every.
aio::search::SearchCall.matches
pub fn matches(self) -> SelfAs crate::search::SearchCall::matches.
aio::search::SearchCall.snippet
pub fn snippet(self, field: &str, around: usize) -> SelfAs crate::search::SearchCall::snippet.
aio::search::SearchCall.total
pub fn total(self) -> SelfAs crate::search::SearchCall::total.
aio::search::SearchCall.filter
pub fn filter(self, condition: Condition) -> SelfAs crate::search::SearchCall::filter.
aio::search::SearchCall.limit
pub fn limit(self, limit: usize) -> SelfAs crate::search::SearchCall::limit.
aio::search::SearchCall.offset
pub fn offset(self, offset: usize) -> SelfAs crate::search::SearchCall::offset.
aio::search::SearchCall.run
pub fn run(self) -> impl Future<Output = Result<Found<T>>> + Send + 'staticRuns the search on the store's pool, as
crate::search::SearchCall::run does, each hit's value decoded
there. Its text, its limits, its filters and its vector are checked
here, so that a search refused for them answers in its first poll and
never reaches the pool.
aio::search::TableIndexBuilder
pub struct TableIndexBuilder<T> { /* private fields */ }What db.search_index opens: a table's index and its settings, as
crate::search::TableIndexBuilder gives them, opened into an index
whose calls are awaited.
aio::search::TableIndexBuilder.table
pub fn table(self, table: &str) -> SelfAs crate::search::TableIndexBuilder::table.
aio::search::TableIndexBuilder.key
pub fn key(self, column: &str) -> SelfAs crate::search::TableIndexBuilder::key.
aio::search::TableIndexBuilder.field
pub fn field(self, column: &str, weight: f64) -> SelfAs crate::search::TableIndexBuilder::field.
aio::search::TableIndexBuilder.fields
pub fn fields<S: AsRef<str>>(self, columns: impl IntoIterator<Item = S>) -> SelfAs crate::search::TableIndexBuilder::fields.
aio::search::TableIndexBuilder.filters
pub fn filters<S: AsRef<str>>(self, columns: impl IntoIterator<Item = S>) -> SelfAs crate::search::TableIndexBuilder::filters.
aio::search::TableIndexBuilder.typo_tolerance
pub fn typo_tolerance(self, on: bool) -> SelfAs crate::search::TableIndexBuilder::typo_tolerance.
aio::search::TableIndexBuilder.layouts
pub fn layouts<S: AsRef<str>>(self, names: impl IntoIterator<Item = S>) -> SelfAs crate::search::TableIndexBuilder::layouts.
aio::search::TableIndexBuilder.synonyms
pub fn synonyms<S: AsRef<str>, P: AsRef<str>>(self, pairs: impl IntoIterator<Item = (S, P)>) -> SelfAs crate::search::TableIndexBuilder::synonyms.
aio::search::TableIndexBuilder.vectors
pub fn vectors(self, column: &str, dimensions: usize) -> SelfAs crate::search::TableIndexBuilder::vectors.
aio::search::TableIndexBuilder.recall
pub fn recall(self, recall: f64) -> SelfAs crate::search::TableIndexBuilder::recall.
aio::search::TableIndexBuilder.vector_weight
pub fn vector_weight(self, weight: f64) -> SelfAs crate::search::TableIndexBuilder::vector_weight.
aio::search::TableIndexBuilder.rerank
pub fn rerank(self) -> SelfAs crate::search::TableIndexBuilder::rerank.
aio::search::TableIndexBuilder.rebuild
pub fn rebuild(self, rebuild: Rebuild) -> SelfAs crate::search::TableIndexBuilder::rebuild.
aio::search::TableIndexBuilder.open
pub fn open(self) -> Result<TableIndex<T>>Opens the index as crate::search::TableIndexBuilder::open does: a
plain call, made once at start, its table's rows read in the
background, which TableIndex::ready waits for.
aio::search::TableIndexBuilder.reindex
pub fn reindex(self) -> Result<TableIndex<T>>Opens the index as open does, and reads it again
beside itself in the background.
aio::search::TableIndex
pub struct TableIndex<T> { /* private fields */ }The rows of a table found again by their words, their vectors or both, its
calls awaited: the same index as crate::search::TableIndex, and the
same again through From and blocking. It has no
set or delete: its rows are the table's, and the index changes in their
commit.
aio::search::TableIndex.blocking
pub fn blocking(&self) -> &TableIndex<T>The same index, for its blocking calls.
aio::search::TableIndex.name
pub fn name(&self) -> &straio::search::TableIndex.search
pub fn search(&self, text: &str) -> SearchCall<'_, T>A search by text's words, as crate::search::TableIndex::search
makes one: each hit's id is its row's key and its value the row, read
on the store's pool in the snapshot its search read.
aio::search::TableIndex.search_vector
pub fn search_vector<'i>(&self, vector: &'i [f32]) -> SearchCall<'i, T>A search by vector alone, as
crate::search::TableIndex::search_vector makes one.
aio::search::TableIndex.status
pub fn status(&self) -> impl Future<Output = Result<Status>> + Send + 'staticWhere the index stands, as crate::search::TableIndex::status reads
it, on the store's pool.
aio::search::TableIndex.ready
pub fn ready(&self) -> impl Future<Output = Result<()>> + Send + 'staticWaits until the index has read its table's rows and serves the
settings it was opened with, as Index::ready waits: dropped, it
stops waiting, and the table's rows are read on.
aio::search::ManySearch
pub struct ManySearch<'s> { /* private fields */ }One question asked of several indexes, run by its awaited
ManySearch::run.
aio::search::ManySearch.among
pub fn among(self, index: &impl Searched, options: impl FnOnce(Among) -> Among) -> SelfAs crate::search::ManySearch::among.
aio::search::ManySearch.run
pub fn run(self) -> impl Future<Output = Result<ManyFound>> + Send + 'staticRuns the search on the store's pool, as
crate::search::ManySearch::run does. How many indexes it asks and
their limits and boosts are checked here, so that a call refused for
them answers in its first poll and never reaches the pool.