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.2

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.2
File Size Uploaded Provenance
adhara-0.1.2.tar.gz 222.7 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for adhara 0.1.2
File
adhara-0.1.2-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
adhara-0.1.2-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
adhara-0.1.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
adhara-0.1.2-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.2.tar.gz

Download URL adhara-0.1.2.tar.gz
Size 222.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b40acf7ecb7a783afd7c8991160ebf3e538e3a559c898f2722c19d7f12b8f9c
BLAKE2b-256 checksum
How to use checksums
978a5b93e4034c5b32d7ccdb3143b4dca6835ffe0bd2e57415384690c3d7bc0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL adhara-0.1.2-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
aafa0e21934d226b644cf6eaeeaf6872b0ceb5d56c826881d435749ef259ea08
BLAKE2b-256 checksum
How to use checksums
4cdb5e55becd157d959a5db7bf0238665e924d21cb636d47128214a4a086e7a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL adhara-0.1.2-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
801dd8b874f49b8a66be699236e1a4a63c1e5728715545061d6a6bce4e8abebd
BLAKE2b-256 checksum
How to use checksums
c39baad4193bbc6ada19cd8a2294c59d420d7c01d13306621803146a1f1b3a73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL adhara-0.1.2-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
9b290e1ca0b2079c92cd869f6c010c052abde090439065ec0ab7cdeb3c483dbc
BLAKE2b-256 checksum
How to use checksums
c410d94b9f82e81e6651d1f637b484be9696f97b176344fbb7e0a9d308438f71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL adhara-0.1.2-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
924f7ae5d1a9170fadd4c1d419a7d7bf87ae36e7bc4761dd163fb69b6978b9cc
BLAKE2b-256 checksum
How to use checksums
4a303f06a3e51c7504e4fb067775095d6d247f466f3a9d95b8ecce160522c4ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Security for adhara 0.1.2

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