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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

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

Uploaded CPython 3.13Windows ARM64

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

Uploaded CPython 3.12Windows x86-64

laurus-0.6.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.6.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.6.0.tar.gz.

File metadata

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

File hashes

Hashes for laurus-0.6.0.tar.gz
Algorithm Hash digest
SHA256 47167612204d3235a82aa07bb052327505ba8deb1ad97dc014f93a065bbd0647
MD5 94d3a1d69e30b1b71207790434d56ed1
BLAKE2b-256 ed80f3c14c03744b4eb1b0e04ef5793a2e7c8adabe2ec102bf494acc6942ec63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.6.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0001c872280202102f00f3081b16704d912ccb12e8d1e6961b6bdd8d321dc18d
MD5 fce43b96805d4284dafb4bc54be0f0df
BLAKE2b-256 54b363c72067bfe42ba8f142ef7da9ac44ba8c6dede47e277aa8f7b705798a6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.6.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6c50bf97a57b29258a9511d98891e1b3f0676b524f047a17726fcb6e07c285ff
MD5 ef59ad59707f290d1985b976dbd1591d
BLAKE2b-256 72ec3320fb763b65cb8d2a48796ff4342b2ec65f0ebec9afd93d5e525bc4acc6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.6.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.6.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 03214e13cd8a9437279729b61c89d23e7bce21b18da3cc296076a0ea45a6f39f
MD5 ed094a08df8cd7b278034dc30afaa14c
BLAKE2b-256 c876dcad9ca87a7ca8f1a9514ac80af5292d225bf528fadb877fc3d6da199e39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.6.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.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3fa6ecc70eb2ea6e76838838fd61faffa3949e6d2f4cff97fa16c16935e89639
MD5 8e40129a23de5a6ead1f3975302253da
BLAKE2b-256 fc5712487ee25dc2cd7dc8e5f4b9a11342e30b3fad3137cc6948f1d67d0ae0f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.6.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1160b0bc4eb4150c77b711d36e8658197343ff24e83fc7a991f43fa0c3a2ab66
MD5 ec23aa65d9e946c60d5986ede6847159
BLAKE2b-256 c6a133e9e718c1193f1ab728cb8ed021f66413a48410cef143d79a0b896a0f2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.6.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 c5158c819ddd0269ba72182a2ef9a8d0aed6ae044379cda96d5d282013d75e49
MD5 5f4a9cf98c24880191a9b4d549695eac
BLAKE2b-256 17df77c607781b175cf6264dcbe6474cf8acd7b3b67ff5418d55b6ad8ef61b5a

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