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)
GeoQuery(field, lat, lon, radius_km) Geo-distance radius search
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.4.2.tar.gz (616.2 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.4.2-cp314-cp314-macosx_11_0_arm64.whl (69.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

laurus-0.4.2-cp314-cp314-macosx_10_12_x86_64.whl (69.5 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

laurus-0.4.2-cp313-cp313-win_arm64.whl (68.8 MB view details)

Uploaded CPython 3.13Windows ARM64

laurus-0.4.2-cp312-cp312-win_amd64.whl (69.1 MB view details)

Uploaded CPython 3.12Windows x86-64

laurus-0.4.2-cp312-cp312-manylinux_2_39_x86_64.whl (72.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

laurus-0.4.2-cp312-cp312-manylinux_2_39_aarch64.whl (71.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ ARM64

File details

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

File metadata

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

File hashes

Hashes for laurus-0.4.2.tar.gz
Algorithm Hash digest
SHA256 ad5dab6cb5a8a30e6924b36d69227a14fa32dd13fe83207317857374aad94e57
MD5 2b4bf8da483d8f23cdfdc7f91630e4ab
BLAKE2b-256 a6402516af8e940e3fb3aa3279289e6a8468329dbfd114fd5d6228f78ca60e73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.4.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df39d9a3ea5e8852da840f41599d8edf9864da9477ba5e3f3d1133caeccf5dce
MD5 e1d0589e2c79870f29e9b987e3ec836f
BLAKE2b-256 2ece00cef8331325a0e51f9906d7e6f6c0c6c929dc54697e39b9765b00014bec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.4.2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8123c636f120a3177091238172762e874e6933ea560bb9dc701924f247a59e63
MD5 deee381507ec284069edd5827fd1a668
BLAKE2b-256 da49ca11fbb2232577786609d450bf53ae068c1c2d063112628f4f6338d340d6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for laurus-0.4.2-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 34c37373c12b13d9ead349781a05bb3a0fad3e111a9f55c936dc1d98c77c5fa0
MD5 a78756144c1df0dd387037c46df59001
BLAKE2b-256 091812153efa4e0d7b2b00d961aba9f1c0a3d369b87241b4ba7852147696b2a8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for laurus-0.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 96b2f2c7546052a8cfb4121274cc3e0f542da45947bba0f145875e0bdb345f01
MD5 80d3491de9a850ae492e7ba38222931b
BLAKE2b-256 d74c9a7087619b720d3b711fcac625b828e16499cec64bda84a406d1d906ded4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.4.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 a31a8269e0c4b046a994ba07f172acb166a589f7c2da8a2ad9bd42d6c8a204da
MD5 f2003fe48907c271d7998710297291a1
BLAKE2b-256 3247ae5988dfa98af0ad2dbcc544b3e2d6ed307dfe51d544afe3c241c2deb8ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.4.2-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 85865aea3209d3bfec91e1645dab59f00ac7169848328e1b93e01f0147e56076
MD5 b0c84b8818faea322889f228ec636b8d
BLAKE2b-256 72889fafab2dffb68047516121e3571eea5b7563d17bfbbe660cab07278f08c5

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