Skip to main content

Python bindings for the Laurus search library

Project description

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)

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.

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

laurus-0.9.0.tar.gz (700.8 kB view details)

Uploaded Source

Built Distributions

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

laurus-0.9.0-cp314-cp314-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

laurus-0.9.0-cp314-cp314-macosx_10_12_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

laurus-0.9.0-cp313-cp313-win_arm64.whl (7.4 MB view details)

Uploaded CPython 3.13Windows ARM64

laurus-0.9.0-cp312-cp312-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.12Windows x86-64

laurus-0.9.0-cp312-cp312-manylinux_2_39_x86_64.whl (10.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

laurus-0.9.0-cp312-cp312-manylinux_2_39_aarch64.whl (10.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ ARM64

File details

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

File metadata

  • Download URL: laurus-0.9.0.tar.gz
  • Upload date:
  • Size: 700.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for laurus-0.9.0.tar.gz
Algorithm Hash digest
SHA256 a2016e17173797ff086ac9bb42bbe8f1087037539fa42a7d310806899b909624
MD5 0b03980672f177715af068ab72e50bd5
BLAKE2b-256 18707bb449360c4d40dbdc6621d37a5eaee222ed0c9d847b57def00b12ef280c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.9.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2a816b103901e4f1b4d20dc9ddb10e71e2d74300285a075c14ccdec9ad99be1
MD5 31146cdfe3f51a0ea340483b2a1a5665
BLAKE2b-256 edc09813c8b4764f52a18413900cf7ca20b74241f32c591aec76b8104bc627e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.9.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a6a468e9e92e41956165f5c3f7fd1dcad3384d26bb19f05cba2c6d49c69f52f5
MD5 b11a649438f89ca55c1e7b1c25a5bf22
BLAKE2b-256 5c69c712bd9606b096b1c30e44ee8cfbf62690a4cd988663e76c089389a306b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.9.0-cp313-cp313-win_arm64.whl
  • Upload date:
  • Size: 7.4 MB
  • Tags: CPython 3.13, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for laurus-0.9.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 3568ffc3e801673806fab43c736f677647cac69d1a6ad531ef8aaa419d62ba2a
MD5 84dc19576ddb569872548d267d5d2864
BLAKE2b-256 6a20eb01866b942f54a0af967b2f32ff9c6ccc19220dd9141f7c5b69743c1741

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for laurus-0.9.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b000ad804b544e289801b62ea8f0ad0bd4a35f3c2ce9f0da95d086e7a397ba26
MD5 0ce9d11e17ed2485ccc511beae666df1
BLAKE2b-256 098f6a19459c42694748b528eb1b3fe622177c112baec9f62e8aa82b4ad47b25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.9.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2aa0e94e4aee8cef12503c941a1bf1bcdf85aa1b435e258d5530e5b26e7d3acc
MD5 dabea71e57a74c45cfa9de0b8c4b345f
BLAKE2b-256 b052768b930bd7532a3aed094a14931e0438b659498d8f3ca68cf197c37dc4d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.9.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 d72b99e6548e7ef864bc117513dde7b3b2ae8ad7cf98ca45a4633021a428cccd
MD5 fe6d18c669236f17bcc9a272c7022497
BLAKE2b-256 eca766353064c39897aeb5c21c08b9f29a33e5bf242513d61f7a331a352fb16f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page