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 adharais 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īṣmaandभीष्मall match.adhara_hybridis 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'ssearchin 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 ownload_extensioncall.fold_token,roman_fold,skeleton,formsandtokensgive 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| adhara-0.1.1.tar.gz | 222.4 kB | Without provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| adhara-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| adhara-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| adhara-0.1.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| adhara-0.1.1-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.1.tar.gz
| Download URL | adhara-0.1.1.tar.gz |
|---|---|
| Size | 222.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2797ff3bd072efa425019a65b51c5e89897ba503139dcfcbadd5f0319dcb2d5c
|
|
BLAKE2b-256 checksum How to use checksums |
5e2f84e19b15cb8d5f91c9f915d865d379f0ffe617b6d72050799d6e79580d30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / adhara-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | adhara-0.1.1-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 |
f4333496863cc04a092b7c2b076e69ea54d8a42ac1431d08152f2d2e4c4076d0
|
|
BLAKE2b-256 checksum How to use checksums |
a6740fda86545dbd6809f5171ee730016dc9e08eb0f417a3e2e0fc8d0d91674f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / adhara-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | adhara-0.1.1-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 |
42a3425fd743e32b80c6eb602ba34c172a77ec0e37981d6224e6e24249ee62fc
|
|
BLAKE2b-256 checksum How to use checksums |
def840003f7339f1002e77b7294e5cc8db4ffd513ec80989eb8697c4de1099c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / adhara-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | adhara-0.1.1-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 |
79517dab5b1dbe98f156471b1a0abaf87c8655ed0b6ae8f2e9928ac2f737025c
|
|
BLAKE2b-256 checksum How to use checksums |
01b77bd8b3e67421444ce3d388b3e9d817eef01ad1f4b8c28f8fc5726440daa4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / adhara-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | adhara-0.1.1-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 |
5678214071c55888c11d3906cdb370818e20de60da7bca034b342f86815f9edf
|
|
BLAKE2b-256 checksum How to use checksums |
cf824cfb85c8d829165d507a3b03ab1dbac8384f9ba12dd2298b569a213f9ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Security for adhara 0.1.1
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.