ProfileMemory
is the central brain behind your user profiles. It’s a smart, self-contained component that listens to a user’s conversation history and builds a detailed, searchable profile from it. Think of it as a helpful assistant that remembers all the important details about a user for you.
At its core, ProfileMemory
uses advanced language models to intelligently extract and organize profile information. It stores this data, along with searchable vector embeddings, in a database. This allows for super-fast, high-quality searches that go beyond simple keywords.
How It Works
The magic ofProfileMemory
lies in its ability to:
- Ingest messages: It takes in new messages and learns from them, continuously updating a user’s profile.
- Consolidate and simplify: To keep profiles accurate and easy to manage, it intelligently combines similar information and removes redundant entries.
- Search efficiently: It allows you to perform semantic searches, which find relevant information even if the exact words aren’t used.
- Cache for speed: It keeps frequently used profiles handy in a cache so you get faster results when you need them.
ProfileMemory
Methods
Here’s a breakdown of the key methods you’ll use to interact with ProfileMemory
.
startup()
What it does: This is the first method you’ll call. It gets ProfileMemory
up and running by initializing all the necessary resources, like the database connection.
cleanup()
What it does: This method gracefully shuts down the ProfileMemory
instance by closing resources, like the database connection pool, when you’re finished.
get_user_profile()
What it does: This method retrieves a user’s entire profile. For better performance, it first checks a cache before looking up the data in the database.
user_id
: The ID of the user whose profile you want to retrieve.isolations
: (Optional) A dictionary for data isolation, allowing you to get a specific subset of the profile.
add_new_profile()
What it does: Use this method to manually add a new piece of information (a “feature”) to a user’s profile. This is useful for adding foundational information that isn’t learned from a conversation.
user_id
: The ID of the user.feature
: The name of the profile feature (e.g., “hobbies”).value
: The value for the feature (e.g., “hiking”).tag
: A category for the feature (e.g., “leisure”).
semantic_search()
What it does: This powerful method allows you to search a user’s profile for specific information. It’s a “semantic” search, which means it understands the meaning of your query, not just the exact words.
user_id
: The ID of the user you are searching.query
: The search query (e.g., “Where does the user live?”).
add_persona_message()
What it does: This is the core ingestion method. You send it a message, and ProfileMemory
adds it to the user’s conversation history. Periodically, it will use these new messages to automatically update and consolidate the user’s profile.
user_id
: The ID of the user.content
: The message content.metadata
: (Optional) Metadata for the message (e.g., who said it).
delete_user_profile()
What it does: Deletes an entire user profile.
user_id
: The ID of the user whose profile will be deleted.
delete_user_profile_feature()
What it does: Deletes a specific feature from a user’s profile.
user_id
: The ID of the user.feature
: The feature to delete (e.g., “hobbies”).tag
: The tag of the feature to delete (e.g., “leisure”).value
: (Optional) The specific value to delete. If this is not provided, all values for that feature and tag are deleted.