Guides
Build a retrieval pipeline
Store chunks and memories with the metadata you need to retrieve them later.
Retrieve context for RAG
Store chunks as documents with source metadata as attributes. Query with the question as both text and vector.
Python
chunks = db.namespace("chunks", text="text", ints=["page"], strings=["source"], vector=768) chunks.upsert_many( {"key": hinny.key(f"{path}#{i}"), "text": chunk, "attrs": {"source": path, "page": page}, "vector": vec} for i, (chunk, page, vec) in enumerate(split_and_embed(path)) ) hits = chunks.query(text=question, vector=embed(question), filter=attr("source").prefix("handbook/"), limit=8) context = "\n\n".join(h.text["text"] for h in hits)
Recall agent memories
Writes are live on return, so an agent can recall on its next turn what it just stored. Keep each memory as a document, scope it with attributes (user, kind, timestamp), and query with both text and vector under a filter. Reusing a key overwrites in place; delete_where drops matching memories in one atomic batch.
Python
memory = db.namespace("memory", text="note", strings=["user", "kind"], ints=["at"], vector=768) def remember(user, note, kind="fact"): key = hinny.key(f"{user}:{note}") memory.upsert(key, text=note, attrs={"user": user, "kind": kind, "at": int(time.time())}, vector=embed(note)) def recall(user, question, since=0): scope = (attr("user") == user) & (attr("at") >= since) return memory.query(text=question, vector=embed(question), filter=scope, limit=8)