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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

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

Uploaded CPython 3.13Windows ARM64

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

Uploaded CPython 3.12Windows x86-64

laurus-0.8.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.8.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.8.0.tar.gz.

File metadata

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

File hashes

Hashes for laurus-0.8.0.tar.gz
Algorithm Hash digest
SHA256 23cdce54168174d87b83ef4f47d847e30f6646bb3ce3b29f525f809d84a7dee2
MD5 97c1bdee971537f8ff1f9945c9916ecb
BLAKE2b-256 e32940a423348e47c51e898468033c7744cfa602ff117161c0685da0a3156d35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.8.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb42656a9ae669d4a38bbf7027c29543e0b21bd188c8f4744909f054618a30d1
MD5 84f8d0f9e7948aed1d6c6cd4b91e1727
BLAKE2b-256 dba23067519217bf7c92000e9d0e440aecdbef6e1d031dbda0341756a33925ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.8.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 67fe334bbc17d34df55c7cf40f158ed095ab91bad52608f6a75dba4b61a25bfe
MD5 f2bb041e0548a685033160145584e8d6
BLAKE2b-256 d5eefe9afeff2fae4af541b55a05dd8890674029765d89f627009a5b07ed271c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.8.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.8.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 3d769473fdc9c80e8a5cdfcb4d623753051aba328fe6363ffdd2c1c2e0912590
MD5 747d681966530ecc8c6782f9941d355e
BLAKE2b-256 39c3a7998376222a8a8b654b31c8c1d7519bddf1c158b61f984898fb68bb36fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laurus-0.8.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.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ba9791b3a8fb5adfda5e159687c1aa7f3675889defcf936a527619878a143705
MD5 24c285d1ae41ade287e440e734308ecb
BLAKE2b-256 cda4fe3ceb69b26221af5d5ace5ed054485f6c245b8d87db510f6a83b0711feb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.8.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b4d35dfb759c58680aa2e9a138212cb31d9c7cbf3053fa627fca4ff69e32ea59
MD5 50de1d5c2891fd305509b56177d37823
BLAKE2b-256 de58793a094ffd1eb33e7659413ef6eda58b30be545c8df3ebe2a2150615b630

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for laurus-0.8.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 1ee72c66e54f20e67e287d6c0692fa93af1e5db00876f7b6de1a983dfc4fa01e
MD5 f0fbf7611bcf8619b6a0bb9f0f74dd87
BLAKE2b-256 045d4c59a46e57212f2c0ecee221cc52cdcd329685b64e0968e47153863f6a67

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