Skip to the content
hinny

Reference

Python API

Look up namespaces, queries, writes, and storage operations.

Namespace operations

See the parameters, return value, and examples for query(), upsert(), and snapshot().

Database(path), db.namespace(name, text=…, ints=…, floats=…, strings=…, tags=…, vector=dims, metric="cosine"), db.open(name)
Opens or creates a namespace. Attributes support integers, floats, strings, and tags (multi-string lists). Schemas can grow over time. metric selects "cosine" (default), "euclidean", or "dot" and is fixed once set. language="english" (or any of 18 Snowball languages) enables stemming and drops stopwords by default for English and German (stopwords=False keeps them); analyzers are fixed once the namespace holds data. db.open(name) opens an existing namespace with its stored schema; db.delete(name) removes a closed namespace and all its files.
ns.upsert(key, text=…, attrs=…, vector=…), ns.upsert_many(docs)
Writes are immediately searchable and survive a process crash on return. The WAL is OS-buffered; call ns.sync() for an explicit storage durability boundary. NumPy float32 arrays are read in place. upsert_many commits an iterable as one atomic batch.
ns.query(text=…, vector=…, sparse=…, filter=…, limit=10, order_by=…)
Runs text, vector, sparse, or any combination together. With only a filter, lists matching documents in order_by order. Hits include stored text and a highlighted snippet by default.
ns.query(text="tax ret", typing=32)
Search-as-you-type: treats the final word as an incomplete prefix and expands it to the top 32 matching terms, so "tax ret" matches "tax return".
text_weight=0.5, fusion="rrf"
By default, each retriever's scores are min-max scaled to 0–1 and blended 50/50. Lower text_weight when your embedding model is strong on the domain; raise it when exact names and codes matter more. Pass fusion="rrf" for Reciprocal Rank Fusion.
text_candidates=200, vector_candidates=100, sparse_candidates=200, ns.explain(…)
Controls how many candidates each retriever gathers before fusion (fixed regardless of limit, raised automatically if limit is larger). explain() returns the hits alongside fusion diagnostics: each retriever's depth, match count, score range, and overlap.
attr("kind") == "pdf", >=, .between(), .one_of(), .prefix(), .contains(), .glob(), .iglob(), .has(), .has_any(), .has_all(), & | ~
Filters evaluated inside the search so filtered results stay exact. Numeric filters accept ints or floats. .glob() and .iglob() match full strings with * and ?. On tags, use .has("tax"), .has_any([…]), and .has_all([…]); string predicates match when any tag on the document matches.
ns.count(filter), ns.count_by("kind", filter, limit)
Counts documents matching a filter directly from attribute columns, or groups counts by attribute value. Documents with tags are counted once per tag.
ns.apply(upsert=…, delete=…), ns.delete_many(keys), ns.snapshot()
Atomic mixed write/delete batches, and point-in-time snapshots that remain isolated from later writes and merges.
ns.delete_where(filter)
Deletes every document matching a filter in one atomic batch and returns the count deleted.
ns.patch(key, attrs=…, remove=…), ns.patch_where(filter, attrs=…)
Updates specific fields of a document while keeping the rest, removing any names listed in remove. patch_where applies a patch across all documents matching a filter and returns the count updated. Because segments are immutable, patching reads and rewrites the document (requiring stored text).
ns.upsert_if(key, condition, …), ns.delete_if(key, condition), ns.patch(key, …, condition=…)
Conditional writes checked atomically under the writer lock for optimistic concurrency (for example, writing only when a revision attribute is below the new one). upsert_if also inserts when the key is missing; patch and delete_if do not. Each returns whether it wrote.
ns.fork("sandbox")
Creates an independent namespace initialized from the current state for sandboxes, experiments, or migrations. Files are hard-linked rather than copied, so forking takes milliseconds and uses zero extra disk until writes diverge (3.9 ms on 1M docs; 8.9 ms with 10,000 unflushed docs in memory).
timeout=, ns.set_limits(max_batch_bytes=…, flush_bytes=…)
Queries past timeout raise TimeoutError instead of returning partial hits. Batches over max_batch_bytes (1 GiB default) raise ValueError before writing. Memtables flush at flush_bytes (256 MiB) or 20,000 passages. ns.stats() exposes memory use, active background work, and pinned segments.
ns.sync()
Flushes prior WAL writes to storage without building segments. Writes after the last successful sync can be lost on OS crash or power loss. Check I/O errors explicitly; cleanup on drop is best-effort. Durability depends on the filesystem and device honoring sync calls (non-Unix directory entries are not synced).
ns.optimize(), ns.flush(), ns.stats(), ns.verify(), hinny.key("any string")
Compact into one segment after a bulk load, sync and flush memory to disk, inspect stats, verify every file against its checksums, and hash string IDs into stable 64-bit integer keys.

HTTP service

Need a shared service? hinny-server exposes the same namespaces, queries, and filters over HTTP as JSON, with optional read replicas. See crates/hinny-server/README.md.