The stable, public surface of densekit. Import the common types straight from
the package root (import densekit).
Deterministic feature-hashing encoder. analyzer is "word" or "char".
encode(texts) -> np.ndarrayof shape(len(texts), dim).
Projects another encoder's output to out_dim with a fixed Gaussian matrix.
All indexes share:
add(vectors)— add(n, dim)rows.search(queries, k=10) -> SearchResultsize,dim,metricproperties.
Exact brute-force search.
Coarse-quantized approximate search. Call train(vectors) before add.
Signed-random-projection LSH with multi-probe.
Product-quantized search (ADC). Call train(vectors) before add.
The quantizer itself: fit, encode, decode, asymmetric_distances.
Frozen dataclass returned by every search.
indices,scores—(n_queries, k)arrays.n_queries,kfor_query(i) -> list[tuple[int, float]]
Relevance judgements. add(query_id, doc_id, grade=1.0), relevant(query_id),
graded(query_id), query_ids.
evaluate(run) -> dict[str, float]whererunmaps query id to ranked doc ids. Returnsrecall@k,precision@k,ndcg@kfor eachk, plusmrrandmap.
recall_at_k, precision_at_k, ndcg_at_k, reciprocal_rank,
average_precision, hit_rate_at_k, mrr, mean_average_precision.
save_index(index, path)— write a.npzarchive.load_index(path) -> BaseIndex— reconstruct it.
info_nce_loss(queries, positives, *, temperature=0.05, extra_negatives=None, normalize=True) -> float
BiEncoder(vocab_size=2**16, dim=128, *, pooling="mean", max_length=64)BiEncoderTrainer(model, config=None)withTrainConfig(epochs, lr, batch_size, temperature, seed)HashingTokenizer,mean_pool,cls_pool