Rust API¶
The Rust API reference is on docs.rs/completr. Enable the store feature for
databases, and aws (or aws-credentials), gcp or azure for cloud storage.
Main types¶
| Type | Feature | Role |
|---|---|---|
Document |
A document: Document::new(id, text, popularity) or Document::keyed(key, text, popularity), with with_synonym, with_abbreviation, with_context and with_vector. |
|
Segment |
An immutable, memory-mapped set of documents and deletes. | |
Index |
Segments searched as one: complete, complete_aliases, vector_search, hybrid_search, and the _with variants taking options. |
|
Engine |
Indexes by name, published atomically, searched as layers. Returns LayeredSuggestions. |
|
Suggestion, AliasSuggestion, HybridSuggestion |
Results, with id, key, text, score and, for completions, kind and byte-range highlights. |
|
MatchKind, Fusion |
Match kinds, and hybrid fusion methods. | |
BuildOptions, IndexOptions, SearchOptions, HybridOptions |
Settings, with chainable setters. | |
Database |
store |
Versioned manifests of named indexes in a store. |
Transaction |
store |
An optimistic, atomic commit. |
ChangeSet |
store |
Upserts and deletes submitted to the inbox. |
Ingestor, IngestStep |
store |
The lease-elected committer of change sets, and the result of a round. |
Replica |
store |
Follows a database and publishes changed indexes to an Engine. |
CompactionPolicy, CleanupPolicy |
store |
Maintenance settings. |
Store, BlockingStore |
store |
Object-store access, async and blocking. |
Error |
Io, Corrupt, InvalidInput, NotFound, Conflict and Store, among others. |
The database API is async and runs on Tokio. From synchronous code, completr::block_on runs one of its
futures on completr's internal runtime; do not call it from async code.
Example¶
use std::sync::Arc;
use completr::{AliasKind, Document, Index, IndexOptions, MatchKind, Segment};
let docs = [
Document::new(1, "Machine Learning", 0.9).with_alias("ML", AliasKind::Abbreviation),
Document::new(2, "Machine Vision", 0.4),
];
let index = Index::new(vec![Arc::new(Segment::build(docs, [])?)], IndexOptions::default())?;
let hits = index.complete("ml", 10);
assert_eq!((hits[0].id, hits[0].kind), (1, MatchKind::Abbreviation));
Runnable examples:
quickstart.rs and
live_updates.rs.