Skip to main content
A personal assistant has two jobs: remember what a person tells it, across sessions, and find the one item they mean among years of their email and photos. This cookbook builds both in one collection per user.

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 the answer function below for your own.
  • Python 3.10 or later, with the SDKs: pip install "hydradb-sdk>=2.1.7,<3" openai.
Save this as 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 as user_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 an email 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

The first answer should suggest vegetarian options near King’s Cross, not Shoreditch. The second should give 312 GBP from the booking email. The third should give “Wheelers” from the photo.

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. Use infer: true for raw conversation.
  • Forgetting collection on 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