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 a database with one collection per user
Each user’s context lives in their own collection, named by their user ID. Nothing one user saves can appear in another user’s query.assistant.py
2. Remember each session
When a session ends, save its turns as a memory. Send the dialogue asuser_assistant_pairs with infer: true: HydraDB extracts the preferences and facts, including ones that are implied, and reconciles them with what it already holds. Saving session by session is how the LongMemEval run ingested its conversations.
assistant.py
3. Add the person’s email and photos
Email and media are knowledge, saved in the same collection. Send an email as anemail app source. Send a photo or video as a custom app source: put the caption and any text read from the image in fields.body, and the date and place in fields.data. This mirrors the ATM-Bench setup, where every item is text plus its timestamp, location, and tags.
assistant.py
4. Answer from memories and items together
type: "all" searches the user’s memories and knowledge in one call.
assistant.py
Run it
Use real data
Connect Gmail and Google Drive with connectors to keep email and files in sync, with each user’s connector pointing at that user’s collection. For photos and video, caption them with a vision model in your application, then ingest them as in step 3.Common mistakes
- Saving a transcript with
infer: false: that stores the dialogue word for word, and the preference inside it is harder to find. Useinfer: truefor raw conversation. - Forgetting
collectionon the query: a query without it reads the default collection, which holds nothing for this user. - Ingesting images without text: queries match text. Put a caption, any text in the image, and the date and place into the app source.
Next steps
- Context:
infer,custom_instructions, and deleting a memory. - Build your own AI Chief of Staff: the same memory, applied to meetings and commitments.
