Skip to main content

adhara

adhara is the SQLite core of litesearch. The name is Sanskrit for "foundation". adhara is one Rust library. It loads into SQLite and adds an FTS5 tokenizer and a hybrid search function. FTS5 is the full-text search module of SQLite.

  • porter adhara is the tokenizer. It gives the same tokens as the tokenizer chain of litesearch, porter simplify casefold 1 sanskrit unicodewords. It inserts text 4.6 times faster. A query in Devanagari, IAST or plain English spelling finds the same word. Bheeshma, Bhīṣma and भीष्म all match.
  • adhara_hybrid is the hybrid search function. One SQL call runs a full-text search, a vector search and Reciprocal Rank Fusion (RRF) on a litesearch store. RRF merges the two result lists by rank. The function returns the rows of litesearch's search in the same order. It is 1.2 to 9.5 times faster.

Python loads adhara as an SQLite extension. Swift links adhara as a static library with SQLite built in. A Swift app can search a store that Python wrote.

RESULTS.md has the measurements and the method. DEV.md has the build and release steps.

Python

pip install adhara
import apsw, adhara
db = adhara.load(apsw.Connection('vault.db'))
db.execute(f"create virtual table notes using fts5(body, tokenize='{adhara.TOKENIZE}')")
rows = db.execute("select id, score from adhara_hybrid('store', :q, :vec, 10)", dict(q='"krishna"*', vec=qvec)).fetchall()
  • adhara.load(conn) loads the extension into an apsw or sqlite3 connection and returns the connection. Use one SQLite library in each process.
  • adhara.path() returns the path of the extension file, for your own load_extension call.
  • fold_token, roman_fold, skeleton, forms and tokens give the folds and the tokens without SQLite.

SQL

select id, score, fts_rank, vec_rank, dist
from adhara_hybrid(store, q, qvec, k, filter, dtype, metric, ann)
argument meaning
store a litesearch store: the table store, its FTS5 table store_fts, and an embedding column
q an FTS5 query, or NULL for the vector search only
qvec the query vector as bytes, or NULL for the full-text search only
k the number of rows from each search, and the number of rows returned
filter an SQL condition on the rows of the store, or NULL
dtype f16 (default), f32 or i8
metric cosine (default), inner or sqeuclidean
ann 1 (default) to use the HNSW index of litesearch, 0 to compare the query with every vector

HNSW is an approximate nearest-neighbour index. litesearch keeps it in a file beside the database. The vector search uses the HNSW index when ann is 1, filter is NULL and the index file is current. Otherwise the vector search compares the query with every vector. An HNSW search can miss a row that the exact search finds. litesearch's search uses the exact search by default (ann=False). Pass ann as 0 to get the same rows.

Join on id to get the row:

select s.content, h.score from adhara_hybrid('store', :q, :vec, 10) h cross join store s on s.rowid = h.id order by h.score desc

Swift

Add adhara to the dependencies of your package:

.package(url: "https://github.com/vedicreader/adhara", from: "0.1.0")
import Adhara
let db = try Database(path: vaultPath, readonly: true)
let hits = try db.search(fts: anyOf(["krishna"]), vector: queryVector, k: 10)

The package downloads the compiled library from the GitHub release. It runs on macOS 13 and later, on Apple silicon and Intel.

The Swift library also registers the tokenizer name simplify. litesearch stores declare porter simplify casefold 1 sanskrit unicodewords. With this name, Swift reads those stores with the adhara tokenizer. The adhara tokens are the same as the tokens of that chain, except after a ZWJ emoji sequence (RESULTS.md). Open those stores read-only in Swift. A Swift write to such a store can leave a stale index entry for a row with that sequence. simplify with other arguments gives an error.

Build and test

cargo test --release
maturin develop --release
pytest
scripts/xcframework.sh && swift test
python bench/bench_tok.py; python bench/bench_hybrid.py

pytest compares adhara with litesearch and apsw on the corpus of laghu. scripts/xcframework.sh builds swift/AdharaCore.xcframework. When that folder exists, the Swift package links it instead of the release download.

Licence

MIT.

Metadata

Release files for adhara 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adhara 0.1.0
File Size Uploaded Provenance
adhara-0.1.0.tar.gz 221.0 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for adhara 0.1.0
File
adhara-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
adhara-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
adhara-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
adhara-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 6.6 MB

Release files / adhara-0.1.0.tar.gz

Download URL adhara-0.1.0.tar.gz
Size 221.0 kB
Tags Source
SHA-256 checksum
How to use checksums
50c1edeb97c58ab9c3c5284ce58904f0974dabeffcb6564cf1ace4f0aed64df2
BLAKE2b-256 checksum
How to use checksums
e314f27367dfee8fd6e0dc7caada6107da517a839346910ca6e48d8e41ff91e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / adhara-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL adhara-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
f812b85b0b16b678275b5b5d01a83ee5eb9e049dde079019459fc9a0e4b71ec9
BLAKE2b-256 checksum
How to use checksums
5fe3fc372c19fdcbe8000d33e6e5050c36b5e0f4895538909078da603d9e5206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / adhara-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL adhara-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
b50be333acee4e3f01530d2aeeb0a541362eff32485298fa94f8ec4a067dd8d9
BLAKE2b-256 checksum
How to use checksums
75295d6ae6a7dbced3702d86e4c2c05e17522cf13f07b3ef137fb2820b186fdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / adhara-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL adhara-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c18cdde659165c0b991e8fb45bdb3e7b66e6a62455f0bd84a8846733b22c0969
BLAKE2b-256 checksum
How to use checksums
ed51c9d90412a7ad3be535e2793c5213a3fbb0ac85b35fa3ccc156d4ce494231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / adhara-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL adhara-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
311582790ee77fc712ff4d9b50e2c556c10ba5b2455a3f5c8bc39ff6852af6bd
BLAKE2b-256 checksum
How to use checksums
47d3711c720198db05a1d7803872c95cfb73f7c06eef95d13dac5a177f14bfc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Security for adhara 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page