Why Personalized Search
Most assistants treat every query like they’ve never seen you before. That means repeating yourself about your location, diet, or preferences, and getting results that feel generic.- With Mem0, your assistant builds a memory of the user’s world.
- With Tavily, it fetches fresh and accurate results in real time.
Prerequisites
Before you begin, make sure you have:- Installed the dependencies:
- Set up your API keys in a .env file:
Code Walkthrough
Let’s break down the main components.1: Initialize Mem0 with Custom Instructions
We configure Mem0 with custom instructions that guide it to infer user memories tailored specifically for our usecase.2. Simulating User History
To test personalization, we preload some sample conversation history for a user:3. Retrieving User Context from Memory
When a user makes a new search query, we retrieve relevant memories to enhance the search query:4. Creating the Personalized Search Agent
The agent uses Tavily search, but always augments search queries with user context:5. Run a Personalized Search
The workflow ties everything together:6. Store New Interactions
Every new query/response pair is stored for future personalization:Full Example Run
How It Works in Practice
Here’s how personalization plays out:- Context Gathering: User previously mentioned living in Los Angeles, being vegan, and having a 7-year-old daughter allergic to peanuts.
- Enhanced Search Query: Query -> “good coffee shops nearby for working” Enhanced Query -> “good coffee shops in Los Angeles with strong wifi, remote-work-friendly”
- Personalized Results: The assistant only returns wifi-friendly, work-friendly cafes near Los Angeles.
- Memory Update: Interaction is saved for better future recommendations.