Skip to main content

laurus-python

PyPI License: MIT

Python bindings for the Laurus search engine. Provides lexical search, vector search, and hybrid search from Python via a native Rust extension built with PyO3 and Maturin.

Features

  • Lexical Search -- Full-text search powered by an inverted index with BM25 scoring
  • Vector Search -- Approximate nearest neighbor (ANN) search using Flat, HNSW, or IVF indexes
  • Hybrid Search -- Combine lexical and vector results with fusion algorithms (RRF, WeightedSum)
  • Rich Query DSL -- Term, Phrase, Fuzzy, Wildcard, NumericRange, Geo, Boolean, Span queries
  • Text Analysis -- Tokenizers, filters, stemmers, and synonym expansion
  • Flexible Storage -- In-memory (ephemeral) or file-based (persistent) indexes
  • Pythonic API -- Clean, intuitive Python classes with full type information

Installation

pip install laurus

To build from source (requires Rust toolchain):

pip install maturin
maturin develop

Quick Start

import laurus

# Create an in-memory index
index = laurus.Index()

# Index documents
index.put_document("doc1", {"title": "Introduction to Rust", "body": "Systems programming language."})
index.put_document("doc2", {"title": "Python for Data Science", "body": "Data analysis with Python."})
index.commit()

# Search with a DSL string
results = index.search("title:rust", limit=5)
for r in results:
    print(f"[{r.id}] score={r.score:.4f}  {r.document['title']}")

# Search with a query object
results = index.search(laurus.TermQuery("body", "python"), limit=5)

Index Types

In-memory (ephemeral)

index = laurus.Index()

File-based (persistent)

schema = laurus.Schema()
schema.add_text_field("title")
schema.add_text_field("body")
schema.add_hnsw_field("embedding", dimension=384)

index = laurus.Index(path="./myindex", schema=schema)

This writes ./myindex/schema.toml and ./myindex/store/ -- the same layout laurus-cli create index --schema uses, so the directory can be opened by either. Reopening it later only needs the path (schema must be omitted, since it's loaded from the persisted schema.toml):

index = laurus.Index(path="./myindex")

Durability / WAL

A persistent index writes every change to a write-ahead log (WAL). By default the WAL is fsync-ed on every record, so each write is fully durable. Opt into group commit to batch fsync for higher write throughput (a crash can lose up to the last unsynced batch, like SQLite's synchronous = NORMAL):

import laurus

policy = laurus.WalSyncPolicy.group(max_records=4096, max_interval_ms=1000)
index = laurus.Index(path="./myindex", schema=schema, wal_sync_policy=policy)

index.put_document("doc1", {"title": "Hello"})
index.flush_wal()  # force a durable barrier on demand
index.commit()     # also flushes the WAL

Omit wal_sync_policy (or pass laurus.WalSyncPolicy.per_record()) to keep the default per-record durability.

Query Types

Query class Description
TermQuery(field, term) Exact term match
PhraseQuery(field, [terms]) Ordered phrase match
FuzzyQuery(field, term, max_edits) Approximate term match
WildcardQuery(field, pattern) Wildcard pattern match (*, ?)
NumericRangeQuery(field, min, max) Numeric range (int or float)
GeoDistanceQuery.within_radius(field, lat, lon, distance_m) Geo-distance radius search
GeoBoundingBoxQuery.within_bounding_box(field, min_lat, min_lon, max_lat, max_lon) Geo bounding-box search
Geo3dDistanceQuery.within_sphere(field, x, y, z, distance_m) 3D ECEF sphere search
Geo3dBoundingBoxQuery.within_box(field, min_x, min_y, min_z, max_x, max_y, max_z) 3D ECEF AABB search
Geo3dNearestQuery.k_nearest(field, x, y, z, k) 3D ECEF k-nearest neighbours
BooleanQuery(must, should, must_not) Compound boolean logic
SpanNearQuery(field, [terms], slop) Proximity / ordered span match
VectorQuery(field, vector) Pre-computed vector similarity
VectorTextQuery(field, text) Text-to-vector similarity (requires embedder)

Hybrid Search

request = laurus.SearchRequest(
    lexical_query=laurus.TermQuery("body", "rust"),
    vector_query=laurus.VectorQuery("embedding", query_vec),
    fusion=laurus.RRF(k=60.0),
    limit=10,
)
results = index.search(request)

Fusion algorithms

Class Description
RRF(k=60.0) Reciprocal Rank Fusion (rank-based, default for hybrid)
WeightedSum(lexical_weight=0.5, vector_weight=0.5) Score-normalised weighted sum

Text Analysis

syn_dict = laurus.SynonymDictionary()
syn_dict.add_synonym_group(["ml", "machine learning"])

tokenizer = laurus.WhitespaceTokenizer()
filt = laurus.SynonymGraphFilter(syn_dict, keep_original=True, boost=0.8)

tokens = tokenizer.tokenize("ml tutorial")
tokens = filt.apply(tokens)
for tok in tokens:
    print(tok.text, tok.position, tok.boost)

Examples

Usage examples are in the examples/ directory:

Example Description
quickstart.py Basic indexing and full-text search
lexical_search.py All query types (Term, Phrase, Boolean, Fuzzy, Wildcard, Range, Geo, Span)
vector_search.py Semantic similarity search with embeddings
hybrid_search.py Combining lexical and vector search with fusion
synonym_graph_filter.py Synonym expansion in the analysis pipeline
search_with_openai.py Cloud-based embeddings via OpenAI
multimodal_search.py Text-to-image and image-to-image search

Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

laurus-0.13.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

laurus-0.13.0-cp314-cp314-macosx_11_0_arm64.whl (9.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

laurus-0.13.0-cp314-cp314-macosx_10_12_x86_64.whl (9.9 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

laurus-0.13.0-cp313-cp313-win_arm64.whl (9.2 MB view details)

Uploaded CPython 3.13Windows ARM64

laurus-0.13.0-cp312-cp312-win_amd64.whl (9.6 MB view details)

Uploaded CPython 3.12Windows x86-64

laurus-0.13.0-cp312-cp312-manylinux_2_39_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

laurus-0.13.0-cp312-cp312-manylinux_2_39_aarch64.whl (9.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ ARM64

File details

Details for the file laurus-0.13.0.tar.gz.

File metadata

  • Download URL: laurus-0.13.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.15.0

File hashes

Hashes for laurus-0.13.0.tar.gz
Algorithm Hash digest
SHA256 e97651492ede1142441f4b29b166c57e81b358cc7db0cef5abc4408d223be5e4
MD5 772d5d3e9990e3244df55c417066efb5
BLAKE2b-256 09efb825950308b6ea4b3d7771b50a4bc201d683262ea4141f3dd840465e2b1e

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for laurus-0.13.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29d9040a6027ad64f991534d2f2f1aced41c463605c755e8e6099cedcc1081c6
MD5 bb85723a08d208c71c6c6da89b59fc98
BLAKE2b-256 82177cd358b8d56a3e8903e2789da32f6ab16df0e476db8b497b4b16bc0f76fe

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for laurus-0.13.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 61e8494a77fa847bd06fbc5d7f93d25dd3175ebe678c58cf6534803b264cc8d9
MD5 ff5b9679d22582e156f9bad0272dcd3f
BLAKE2b-256 0bf0bacd533208a90ff96b25b2b00895ca0fc7019fea9aada425c746446afdac

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp313-cp313-win_arm64.whl.

File metadata

File hashes

Hashes for laurus-0.13.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 51d96ee4d2dc62ae755516ced490b651e1c5d8463cdf45a90d1985791ee30390
MD5 82c90d3d0562d0ed1c8e40eeb06f78ac
BLAKE2b-256 2e3db088159f1e9a98a8169bac31f5d08b58562fff7c3a92e1b0544223973326

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: laurus-0.13.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 9.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.15.0

File hashes

Hashes for laurus-0.13.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b639676806a2ed9c11160904aa0f581858a6946ffb5361c675b9c686e9187dba
MD5 afaf4577e3e8f4f61043da28934caa89
BLAKE2b-256 79a5ddb17c39c8b45836a70c59836711854861fdff015ff9e063a584b4b255ad

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for laurus-0.13.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4e22be03e9471b9d064b142fa7bde12255ae0bd2a0b2be58450ff5b7e800bd9a
MD5 5ed4491622c183c198e4494064777327
BLAKE2b-256 a2d2cda77b828f696dcd0955e35a5d7fbf4fa32deb178410aeac5be0fc0e5e7f

See more details on using hashes here.

File details

Details for the file laurus-0.13.0-cp312-cp312-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for laurus-0.13.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 7eee515cfd9dfa813bff7211332eeebeb7aaa4224193f733d53ce4492189fa55
MD5 887e30097a6cfa39305ed4fe260759be
BLAKE2b-256 2d62d209975f25259c86520707c63dcf6b81c718b98a02a5f257738053f0c69b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.13.1

7 files

This release

0.13.0 This release

7 files

0.12.1

7 files

0.12.0

7 files

0.11.0

7 files

0.10.0

7 files

0.9.0

7 files

0.8.0

7 files

0.7.0

7 files

0.6.0

7 files

0.5.0

7 files

0.4.2

7 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page