Prerequisites
- A HydraDB API key from dashboard.hydradb.com, set as
HYDRADB_API_KEY. - An OpenAI API key, set as
OPENAI_API_KEY. HydraDB returns context, not answers, so any model works; swap theanswerfunction below for your own. - Python 3.10 or later, with the SDKs:
pip install "hydradb-sdk>=2.1.7,<3" openai.
hydra.py. Every cookbook imports it. It holds what every HydraDB application does around its own logic: wait for the database, check what an ingest accepted, wait for indexing, and pass query results to a model.
hydra.py
1. Create one database and one collection
Put everything in one collection so a single query searches all of it. Separate collections are for context that must never meet in one query; permissions are handled by ACLs, not by splitting collections. See Databases and Collections.glean.py
2. Ingest sources from each app
Send records your code already holds as app sources.kind tells HydraDB what the record is, fields carries its content, and acl lists who may see it. The samples include an outdated wiki page and the Slack message that replaced it, and a ticket only the finance lead can see.
glean.py
3. Query as the person asking
Send the signed-in user’s identity asacl. Take it from your session on the server, never from the client: a query without acl returns everything in scope. The other settings are the ones the EnterpriseRAG-Bench run used: hybrid matching, thinking mode, and 12 results.
glean.py
4. Answer with citations
Each chunk in the query result carries the ID and title of the source it came from. Print each source once under the answer.glean.py
Run it
Use real data
Replace step 2 with connectors: HydraDB then syncs each app on a schedule and copies its permissions into each source’s ACL. Create one connector per app, all pointing at the same collection.connect.py
acl on every query, and leave enforce_acl off for this application. With enforce_acl on, HydraDB ignores the request’s acl and uses the identity of whoever created the API key, so every user of your application would see what the key’s creator can see. Enforcement fits a caller who authenticates as themselves, such as a user signed in through MCP OAuth.
Common mistakes
- Turning on
enforce_aclbehind one API key: every query then runs with the key creator’s permissions, not the asker’s. - Querying without
acl: the query returns restricted sources to everyone. Send the user’s identity on every query. - One collection per app or team: a query that names one collection does not read the others. Keep one collection and narrow with metadata filters.
- Group permissions: an email matches its
domain:principal automatically, but not groups. Sendgroup:principals yourself. See Query.
Next steps
- Query: tune
mode,alpha, andrecency_bias. - Build your own customer support agent: add per-user memory to shared knowledge.
