Skip to content

Autocompletion as a library.

An embedded engine for Rust and Python whose database is a bucket. Every process reads the index straight from storage and ranks exact, prefix, infix, abbreviation and misspelt matches together, in a fraction of a millisecond. No cluster, no server.

completype completing music queries: prefix, abbreviation, spelling correction, word decomposition and infix
median query
0.15 ms

Hacker News titles, typed as prefixes

queries a second
40,016

on 8 threads, Hacker News titles

index size
3.1 GB

for 40 million MusicBrainz recordings

best ranking
19 of 20

comparisons with tantivy, Typesense and Meilisearch

Measured on one laptop; see Benchmarks for every table and caveat.

Every kind of match, ranked together.

One request collects every match kind and ranks them with popularity, match kind and text length. You never choose between prefix, infix or fuzzy search. Results from the demo index:

  1. dancDancing Queen – ABBAprefix
  2. rhcpUnder the Bridge – Red Hot Chili Peppersabbreviation
  3. bohemain rapsodyBohemian Rhapsody – Queenfuzzy
  4. dancingqueenDancing Queen – ABBAprefix
  5. queenBohemian Rhapsody – Queeninfix
  6. is this the realBohemian Rhapsody – Queensynonym

How completion and ranking work

The database is a bucket.

completype is a library, not a service. Storage is the only shared component.

  • Create-only commits. Version N + 1 is written with If-None-Match, so concurrent writers never corrupt each other.
  • Readers follow by themselves. Engines load only changed, immutable segments and switch versions atomically.
  • No hop on the hot path. Queries run inside your process, on memory-mapped segments.

Serverless deployment

a workertxn.commit() an ingestorleased bucket s3 · gs · az _versions/ segments/ the database your appengine.complete your appengine.complete your appengine.complete

One catalogue, many views.

Tenants, locales, listeners, promotions and takedowns are small indexes stacked on the shared catalogue, overriding it per document id, without a copy. Five layers over 200,000 titles answer in 0.2 ms at the median.

Layers

  1. catalogshared, built once
  2. catalog-delocal charts
  3. radioedits and removals
  4. user-…own plays
  5. takedowns
engine.complete("queen", stack)
Bohemian Rhapsody (Remastered 2011) – Queen  radio
Dancing Queen – ABBA                         catalog
Dancing Queen (Live Session) – ABBA          radio

A few lines, in either language.

Python
import completype

db = completype.connect("s3://my-bucket/completions")
txn = db.begin()
txn.append("songs", docs)
txn.commit()

engine = db.engine()   # follows new versions
engine.complete("danc", ["songs"])
Rust
let database = Database::open("./data", Vec::<(String, String)>::new()).await?;
let mut txn = database.begin().await?;
txn.append_documents("songs", docs, [])?;
txn.commit().await?;

let engine = Arc::new(Engine::new());
let replica = Arc::new(Replica::new(database, IndexOptions::default()));
replica.sync(&engine).await?;
let _follower = replica.follow(&engine, Duration::from_secs(5));
engine.complete(&["songs"], "danc", 10)?;

The full quick start

Questions

What does serverless mean here?

There is no completype server. The engine is a library in your process, and the database is a set of files in a bucket or directory. Your application is deployed however you like; completype adds no service to it.

How is it different from Elasticsearch, Typesense or Meilisearch?

Those are search servers for documents with many fields, filters and facets, and every query crosses the network. completype does autocompletion only, inside your process. Many applications use both: a search server for the results page, completype for the box.

How do several writers avoid conflicts without a server?

Through the store. Each commit creates the next manifest create-only, so exactly one writer wins each version and the others retry. For high write rates, a single ingestor elected by an expiring lease commits queued change sets in order.

How fresh are completions after an update?

Engines sync every sync_every seconds (5 by default), so a committed transaction appears within a few seconds; engine.sync() loads it at once.

All questions

Complete your first query.