Local autocomplete from text, PDFs, and DOCX without Elasticsearch, Meilisearch, Algolia, or Typesense.
Project description
query-autocomplete
Local, typo-tolerant autocomplete for Python apps.
query-autocomplete turns text, PDFs, and DOCX files into fast local suggestions with a compact prefix index, fuzzy prefix recovery, and a local scorer. It is useful when you want autocomplete without running Elasticsearch, Meilisearch, Algolia, Typesense, or another search service.
Full documentation: https://query-autocomplete.readthedocs.io/en/latest/
Install
pip install query-autocomplete
Optional sentence chunking support:
pip install "query-autocomplete[chunking]"
Quick Start
from query_autocomplete import Autocomplete, Document
index = Autocomplete.create([
Document(text="how to build a deck"),
Document(text="how to build a desk"),
Document(text="how to build with python"),
])
print(index.suggest("how to bui", topk=5))
print(index.suggest("how to biuld", topk=5))
That is the core model: build an index from text, then ask for suggestions.
You can also pass file paths directly. .txt, .pdf, and .docx inputs are supported in the base package:
from pathlib import Path
from query_autocomplete import Autocomplete
index = Autocomplete.create([
Path("docs/handbook.pdf"),
Path("docs/release-notes.docx"),
Path("docs/faq.txt"),
])
print(index.suggest("install", topk=5))
Use It In An App
Build or load the autocomplete once when your app starts. Do not rebuild it inside every request handler.
from fastapi import FastAPI
from query_autocomplete import Autocomplete
app = FastAPI()
index = Autocomplete.load("my-index")
# Warm before serving traffic so the first user query is not the loader.
index.warm()
@app.get("/autocomplete")
def autocomplete(q: str):
return {"suggestions": index.suggest(q, topk=5)}
Cold starts are normal for local indexes: a new process has to load the compiled index into memory once. After that, suggestions are served from the in-process engine.
Save A Serving Index
If your source text changes rarely, build the index ahead of time and save it as a compiled artifact.
from query_autocomplete import Autocomplete, Document
index = Autocomplete.create([
Document(text="wireless mechanical keyboard"),
Document(text="wireless mouse for laptop"),
Document(text="usb c docking station"),
Document(text="noise cancelling headphones"),
])
index.save("products-v1")
Then load it in your app:
from query_autocomplete import Autocomplete
index = Autocomplete.load("products-v1")
print(index.suggest("wireless m", topk=5))
Use this path when you want the simplest serving setup: compile once, load many times.
Use SQLite When Documents Change
If your document collection needs to be updated over time, use AdaptiveStore. It stores source documents and the current compiled serving index in SQLite.
from query_autocomplete import AdaptiveStore, Document
store = AdaptiveStore.open("sqlite:///autocomplete.sqlite3")
store.add_documents([
Document(text="how to build a deck", doc_id="deck"),
Document(text="how to build with python", doc_id="python"),
])
# Warm before serving traffic so the first user query is not the builder.
store.warm()
print(store.suggest("how to bui", topk=5))
AdaptiveStore rebuilds the serving index when documents change. For production-style apps, call store.warm() during startup or after ingestion so the first real user request does not pay that cost.
Supported SQLite paths:
sqlite:///autocomplete.sqlite3sqlite:////absolute/path/autocomplete.sqlite3- a plain path like
"./autocomplete.sqlite3"
Serving a SQLite-backed autocomplete from FastAPI:
from fastapi import FastAPI
from query_autocomplete import AdaptiveStore
app = FastAPI()
store = AdaptiveStore.open("sqlite:///autocomplete.sqlite3")
@app.on_event("startup")
def startup():
store.warm()
@app.get("/autocomplete")
def autocomplete(q: str):
return {"suggestions": store.suggest(q, topk=5)}
Which API Should I Use?
Use Autocomplete.create(...) when your documents are already in memory and you want the fastest way to start.
Use Autocomplete.save(...) and Autocomplete.load(...) when you want a compiled serving artifact that can be loaded at app startup.
Use AdaptiveStore when you want a SQLite-backed document collection that can add or remove documents and rebuild its serving index.
What It Is Good For
- search box suggestions
- command palettes
- docs and help-center autocomplete
- local autocomplete inside Python apps
- prototypes that should not need a search server
It is probably not the right tool when you need distributed search, complex faceting, hosted multi-tenant search infrastructure, or semantic/vector search as the primary retrieval model.
Learn More
The full guide covers configuration, quality profiles, diagnostics, file readers, adaptive stores, and persistence:
https://query-autocomplete.readthedocs.io/en/latest/
Repository Note
- The published package is built from
python-package/ - The importable library source lives in
core/src/query_autocomplete/
Third-Party Licensing
- This package is MIT-licensed.
- It depends on
marisa-trie, whose current published licensing isMIT AND (BSD-2-Clause OR LGPL-2.1-or-later). - See THIRD_PARTY_LICENSES.md for a short note and links to upstream metadata.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file query_autocomplete-0.1.2.tar.gz.
File metadata
- Download URL: query_autocomplete-0.1.2.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be795fbaf5045527c642afb023fbe528dfc12425a1773a4e1dbb56cd4584c70
|
|
| MD5 |
e160cda42222cbd4ff199d23d9ec2683
|
|
| BLAKE2b-256 |
92f4518fb03bdaa62df487fe7e556f1dbdeb4cf9558d4c707fde219b9368d3e3
|
Provenance
The following attestation bundles were made for query_autocomplete-0.1.2.tar.gz:
Publisher:
release.yml on MarcellM01/query-autocomplete
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
query_autocomplete-0.1.2.tar.gz -
Subject digest:
7be795fbaf5045527c642afb023fbe528dfc12425a1773a4e1dbb56cd4584c70 - Sigstore transparency entry: 1396358653
- Sigstore integration time:
-
Permalink:
MarcellM01/query-autocomplete@a8c92598014cdee94b0bcd2fa3fc5d0fa4249fa7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/MarcellM01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8c92598014cdee94b0bcd2fa3fc5d0fa4249fa7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file query_autocomplete-0.1.2-py3-none-any.whl.
File metadata
- Download URL: query_autocomplete-0.1.2-py3-none-any.whl
- Upload date:
- Size: 52.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cf32ed4f916bcce0c2030afc4a26cfe4f2e490568de2dbe6d94d65850d7cd38
|
|
| MD5 |
2f4c86e993d52ad074b2c0df4bdc684b
|
|
| BLAKE2b-256 |
04d47b032460460d6b249e19ea15b317f5557561d7711b6483ad5fad738107c9
|
Provenance
The following attestation bundles were made for query_autocomplete-0.1.2-py3-none-any.whl:
Publisher:
release.yml on MarcellM01/query-autocomplete
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
query_autocomplete-0.1.2-py3-none-any.whl -
Subject digest:
3cf32ed4f916bcce0c2030afc4a26cfe4f2e490568de2dbe6d94d65850d7cd38 - Sigstore transparency entry: 1396358656
- Sigstore integration time:
-
Permalink:
MarcellM01/query-autocomplete@a8c92598014cdee94b0bcd2fa3fc5d0fa4249fa7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/MarcellM01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8c92598014cdee94b0bcd2fa3fc5d0fa4249fa7 -
Trigger Event:
push
-
Statement type: