Skip to main content

An embeddable, in-process search engine written in Rust

Project description

lucisearch

The SQLite of Search — an embeddable, in-process search engine.

No cluster to manage. No HTTP layer. No JVM. pip install and search.

pip install lucisearch

Quick Start

import luci

# Create an index with field mappings
index = luci.Index.create("products.luci", {
    "properties": {
        "title": {"type": "text"},
        "description": {"type": "text"},
        "category": {"type": "keyword"},
        "price": {"type": "float"},
        "in_stock": {"type": "boolean"},
    }
})

# Index documents
index.bulk([
    {"title": "Wireless Headphones", "description": "Noise-cancelling bluetooth headphones", "category": "electronics", "price": 79.99, "in_stock": True},
    {"title": "Running Shoes", "description": "Lightweight trail running shoes", "category": "sports", "price": 129.99, "in_stock": True},
    {"title": "Coffee Maker", "description": "Programmable drip coffee maker", "category": "kitchen", "price": 49.99, "in_stock": False},
])

# Search
results = index.search({"match": {"title": "headphones"}}, 10)
for hit in results["hits"]:
    print(f'{hit["_score"]:.2f}  {hit["_source"]["title"]}')

Queries

Luci supports the Elasticsearch query DSL. Pass any query as a Python dict.

Full-text search

# Single field
index.search({"match": {"title": "running shoes"}}, 10)

# Multiple fields
index.search({"multi_match": {"query": "wireless", "fields": ["title", "description"]}}, 10)

# Exact phrase
index.search({"match_phrase": {"description": "trail running"}}, 10)

Filtering and boolean logic

# Term query (exact match on keyword fields)
index.search({"term": {"category": "electronics"}}, 10)

# Bool query — combine must, should, must_not, filter
index.search({
    "bool": {
        "must": [{"match": {"title": "shoes"}}],
        "filter": [
            {"term": {"in_stock": True}},
            {"range": {"price": {"lte": 100}}},
        ]
    }
}, 10)

# Prefix, wildcard, regexp, fuzzy
index.search({"prefix": {"category": "elec"}}, 10)
index.search({"fuzzy": {"title": {"value": "headphoens", "fuzziness": 1}}}, 10)

Sorting and pagination

# Sort by field
results = index.search({
    "query": {"match_all": {}},
    "sort": [{"price": "asc"}],
    "size": 10
})

# Pagination with from/size
results = index.search({
    "query": {"match_all": {}},
    "sort": ["price"],
    "from": 20,
    "size": 10
})

# Cursor-based pagination with search_after
results = index.search({
    "query": {"match_all": {}},
    "sort": ["price"],
    "size": 10,
    "search_after": [49.99]
})

Aggregations

# Terms aggregation
results = index.search({
    "query": {"match_all": {}},
    "aggs": {"categories": {"terms": {"field": "category"}}},
    "size": 0
})
for bucket in results["aggregations"]["categories"]["buckets"]:
    print(f'{bucket["key"]}: {bucket["doc_count"]}')

# Metric aggregations
results = index.search({
    "query": {"match_all": {}},
    "aggs": {
        "avg_price": {"avg": {"field": "price"}},
        "price_stats": {"stats": {"field": "price"}},
        "price_ranges": {"range": {
            "field": "price",
            "ranges": [{"to": 50}, {"from": 50, "to": 100}, {"from": 100}]
        }},
    },
    "size": 0
})

# Nested aggregations
results = index.search({
    "query": {"match_all": {}},
    "aggs": {"by_category": {
        "terms": {"field": "category"},
        "aggs": {"avg_price": {"avg": {"field": "price"}}},
    }},
    "size": 0
})

Highlighting

results = index.search({
    "query": {"match": {"description": "coffee"}},
    "highlight": {
        "fields": {"description": {}},
        "pre_tags": ["<b>"],
        "post_tags": ["</b>"],
    }
})
for hit in results["hits"]:
    print(hit.get("highlight", {}))

Vector search (kNN)

# Create index with vector field
index = luci.Index.create("vectors.luci", {
    "properties": {
        "title": {"type": "text"},
        "embedding": {"type": "dense_vector", "dims": 384},
    }
})

# kNN search
results = index.search({
    "knn": {
        "field": "embedding",
        "query_vector": [0.1, 0.2, ...],  # 384-dim vector
        "k": 10,
        "num_candidates": 50,
    }
}, 10)

# Hybrid search — text + vector combined via RRF
results = index.search({
    "query": {"match": {"title": "headphones"}},
    "knn": {
        "field": "embedding",
        "query_vector": query_vector,
        "k": 10,
        "num_candidates": 50,
    }
}, 10)

Geospatial queries

# Create index with geo fields
index = luci.Index.create("places.luci", {
    "properties": {
        "name": {"type": "text"},
        "location": {"type": "geo_point"},
    }
})

# Geo distance
index.search({
    "geo_distance": {
        "distance": "10km",
        "location": {"lat": 40.7128, "lon": -74.0060}
    }
}, 10)

# Geo bounding box
index.search({
    "geo_bounding_box": {
        "location": {
            "top_left": {"lat": 41.0, "lon": -74.5},
            "bottom_right": {"lat": 40.5, "lon": -73.5}
        }
    }
}, 10)

Document CRUD

# Add with explicit ID
index.add({"_id": "prod-1", "title": "Widget", "price": 9.99})

# Get by ID
doc = index.get("prod-1")

# Update (partial merge)
index.update("prod-1", {"price": 7.99})

# Delete by ID
index.delete("prod-1")

# Delete by query
index.delete_by_query({"term": {"category": "discontinued"}})

# Count
count = index.count({"term": {"in_stock": True}})

Field Types

Type Description
text Full-text search with BM25 scoring and analysis
keyword Exact match, sorting, aggregations
integer, long Signed integers
float, double Floating point numbers
boolean true / false
date Date/time values
dense_vector Fixed-dimension float vectors (cosine, L2, dot product; int8 quantization)
geo_point Latitude/longitude pairs
geo_shape Polygons, multipolygons with spatial relations
nested Arrays of objects with independent field scoping

Features

  • Full-text search with BM25 scoring, analyzers, phrase queries, fuzzy matching
  • Vector search with HNSW, int8 quantization, pre-filtering
  • Hybrid search with Reciprocal Rank Fusion (RRF)
  • 20+ aggregation types — terms, avg, sum, min, max, stats, range, histogram, cardinality, percentiles, date_histogram, geo_bounds, filters, nested, and more
  • Geospatial — geo_distance, geo_bounding_box, geo_shape with all spatial relations
  • Nested documents with block-join queries and inner_hits
  • Highlighting with custom tags, per-field configuration
  • Sort by field — keyword, numeric, score, with multi-level sort
  • Paginationfrom/size and cursor-based search_after
  • Collapse — deduplicate results by a keyword field
  • Explain — BM25 score breakdowns
  • Rescore — two-phase scoring with custom query weights
  • Single-file storage — one .luci file, no directory sprawl
  • Auto-commit — documents are searchable immediately after add() or bulk()
  • ES-compatible JSON query DSL — same queries, same field types

License

MIT

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

lucisearch-0.4.1.tar.gz (351.2 kB view details)

Uploaded Source

Built Distribution

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

lucisearch-0.4.1-cp39-cp39-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file lucisearch-0.4.1.tar.gz.

File metadata

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

File hashes

Hashes for lucisearch-0.4.1.tar.gz
Algorithm Hash digest
SHA256 bfa5bd367f07828bd25c7de7ffad60b0f42701f984faa84ba4a211c59c2a1a6a
MD5 d476c09b9b8b5ac03982577ad5aa8b58
BLAKE2b-256 597f0db8ea4b0d3b3689b8d8166dbaee98449024e783573c3a75195126a28c39

See more details on using hashes here.

File details

Details for the file lucisearch-0.4.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lucisearch-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d421e1f3be964dbce859dcf5a1d2b7690edb4385ba06b92237b66e1299cc450
MD5 6d67c8f8e9c36c9252c03dd37ee2b105
BLAKE2b-256 94c7209693fab70abe9932bf236473143a6c77bad93a6a66f02ce2e8f481bc46

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