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.7.0.tar.gz (621.9 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.7.0-cp314-cp314-macosx_11_0_arm64.whl (69.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

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

Uploaded CPython 3.13Windows ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

laurus-0.7.0-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.7.0.tar.gz.

File metadata

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

File hashes

Hashes for laurus-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7849cc06b7f189763ecde248dd6c06fdde5a86c554f84a541b743d81f8fc6de5
MD5 60441a47ac08e8fa5f8a415d0c33ca87
BLAKE2b-256 b662b14f78d29efab6ef306f6a22d12493b1e15a48f4223896eef799bfd9edfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.7.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40ca5d18344b0106acddbd48930e46d66d84ca16a581c400ccaf450303e0849c
MD5 40ac3f2f01de02a7a050db2a0a8b19fb
BLAKE2b-256 f4ee3394f9f5bd886c34e58e3b5878969ba622572948435e69395e20afa5ce9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.7.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2f22a9078546f4bc28ddc0363c2b7e575e3aaf36347d7b71bc8b437bea57b861
MD5 9fd5f5e389889c345caa39f1202bed34
BLAKE2b-256 4e045e0b32fb95373086014e526b92db6afb67aa6c0cd6687645683c37e05745

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.7.0-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.7.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 55161f94f17c9c8f6328563951e049b67b45f3ed5d828cd137fef2f444d1eb39
MD5 2048f2fed85fe4cf13945df3a52dcf40
BLAKE2b-256 128ca3d0784a5e623bb8b6b59e0f27ba651bd8c43ebc324515292eda02ca4a4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.7.0-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.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 98f5c2b4f101f8b4ec085a5ec59206e50a888d456e459bc892ec2178ca733991
MD5 984a3767b8ae4607d4b34ebd19c9153b
BLAKE2b-256 fac1efd9ee50c73030fea2722bcfa1dff403e906887f861302aa39eb15ffe138

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.7.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 55f569c72840662aaa3e1cacfc1b231ec2c10969b21640dd1a7f60746934ddf2
MD5 a220f7afcd8caa16604229fb612d2727
BLAKE2b-256 85c0c69070de3be10b4341b1d975e071e1abdfc0ea69a55838a7d02906e33851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.7.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 ae5cd3f6aa152e09ca8a096be3ff59155264ee9a5b634b441aeeab4b0634d20d
MD5 b0b980a0c7413f885ed99790db7dd4cd
BLAKE2b-256 bedb0f9bf3c51275df9d157dab822d4b3b4bea43b3f0b3c2219f687d0de4e798

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