Skip to the content
hinny

Guides

Combine text and vectors

Find exact terms and paraphrases in the same query.

Explore the rankings

BM25 matches exact names, IDs, and error codes. Vectors catch paraphrases when the wording differs. Adjust the blend to see which documents move up when the words or the meaning carry more weight.

ns.query()
textlease for the apartment, 2025
filteryear >= 2025
  1. 1Lease agreement, Elm Streetpdf0.90
  2. 2Re: the rental contractmail0.67
  3. 3Apartment handover checklistmd0.64
  4. 4Deposit receipt, Marchpdf0.42
words (BM25)meaning (vectors)Words and meaning agree on the lease; meaning alone finds the contract that never says "lease".

Run a hybrid query

Generate the document embedding and query embedding with the same 384-dimensional model. In the examples, emb represents the document and q represents the query.

import hinny
from hinny import attr

docs = hinny.Database("data").namespace("docs", text="body", ints=["year"], vector=384)
docs.upsert(1, text="The lease for the flat on Elm Street", attrs={"year": 2025}, vector=emb)

hits = docs.query(text="apartment lease", vector=q, filter=attr("year") >= 2025)  # one ranking

Add learned sparse terms

Store term weights from SPLADE or OpenSearch inference-free encoders, scored by dot product with the same block-max pruning as BM25. Weights are stored to hundredths.

Python
ns = db.namespace("docs", text="body", sparse=["terms"], vector=256, language="english")
ns.upsert(1, text="...", sparse={"terms": {"lease": 1.4, "rent": 0.6}}, vector=v)   # weights from a sparse model

hits = ns.query(sparse={"terms": query_weights}, vector=query_vector)    # sparse + vectors